001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.exception.SystemException;
031    import com.liferay.portal.kernel.log.Log;
032    import com.liferay.portal.kernel.log.LogFactoryUtil;
033    import com.liferay.portal.kernel.sanitizer.Sanitizer;
034    import com.liferay.portal.kernel.sanitizer.SanitizerException;
035    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
036    import com.liferay.portal.kernel.util.ArrayUtil;
037    import com.liferay.portal.kernel.util.ContentTypes;
038    import com.liferay.portal.kernel.util.GetterUtil;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
046    import com.liferay.portal.model.CacheModel;
047    import com.liferay.portal.security.auth.PrincipalThreadLocal;
048    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
049    import com.liferay.portal.service.ServiceContext;
050    import com.liferay.portal.service.ServiceContextThreadLocal;
051    import com.liferay.portal.service.persistence.CompanyProvider;
052    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
053    
054    import com.liferay.portlet.messageboards.NoSuchMessageException;
055    import com.liferay.portlet.messageboards.model.MBMessage;
056    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
057    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
058    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
059    
060    import java.io.Serializable;
061    
062    import java.util.Arrays;
063    import java.util.Collections;
064    import java.util.Date;
065    import java.util.HashMap;
066    import java.util.HashSet;
067    import java.util.Iterator;
068    import java.util.List;
069    import java.util.Map;
070    import java.util.Set;
071    
072    /**
073     * The persistence implementation for the message-boards message service.
074     *
075     * <p>
076     * Caching information and settings can be found in <code>portal.properties</code>
077     * </p>
078     *
079     * @author Brian Wing Shun Chan
080     * @see MBMessagePersistence
081     * @see com.liferay.portlet.messageboards.service.persistence.MBMessageUtil
082     * @generated
083     */
084    @ProviderType
085    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
086            implements MBMessagePersistence {
087            /*
088             * NOTE FOR DEVELOPERS:
089             *
090             * 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.
091             */
092            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
093            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
094                    ".List1";
095            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
096                    ".List2";
097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
098                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
101                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
103            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
106            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
107                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
108                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
109                            new String[] {
110                                    String.class.getName(),
111                                    
112                            Integer.class.getName(), Integer.class.getName(),
113                                    OrderByComparator.class.getName()
114                            });
115            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
116                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
118                            new String[] { String.class.getName() },
119                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
120                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
121            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
122                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
123                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
124                            new String[] { String.class.getName() });
125    
126            /**
127             * Returns all the message-boards messages where uuid = &#63;.
128             *
129             * @param uuid the uuid
130             * @return the matching message-boards messages
131             */
132            @Override
133            public List<MBMessage> findByUuid(String uuid) {
134                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
135            }
136    
137            /**
138             * Returns a range of all the message-boards messages where uuid = &#63;.
139             *
140             * <p>
141             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
142             * </p>
143             *
144             * @param uuid the uuid
145             * @param start the lower bound of the range of message-boards messages
146             * @param end the upper bound of the range of message-boards messages (not inclusive)
147             * @return the range of matching message-boards messages
148             */
149            @Override
150            public List<MBMessage> findByUuid(String uuid, int start, int end) {
151                    return findByUuid(uuid, start, end, null);
152            }
153    
154            /**
155             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
156             *
157             * <p>
158             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
159             * </p>
160             *
161             * @param uuid the uuid
162             * @param start the lower bound of the range of message-boards messages
163             * @param end the upper bound of the range of message-boards messages (not inclusive)
164             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
165             * @return the ordered range of matching message-boards messages
166             */
167            @Override
168            public List<MBMessage> findByUuid(String uuid, int start, int end,
169                    OrderByComparator<MBMessage> orderByComparator) {
170                    return findByUuid(uuid, start, end, orderByComparator, true);
171            }
172    
173            /**
174             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
175             *
176             * <p>
177             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
178             * </p>
179             *
180             * @param uuid the uuid
181             * @param start the lower bound of the range of message-boards messages
182             * @param end the upper bound of the range of message-boards messages (not inclusive)
183             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
184             * @param retrieveFromCache whether to retrieve from the finder cache
185             * @return the ordered range of matching message-boards messages
186             */
187            @Override
188            public List<MBMessage> findByUuid(String uuid, int start, int end,
189                    OrderByComparator<MBMessage> orderByComparator,
190                    boolean retrieveFromCache) {
191                    boolean pagination = true;
192                    FinderPath finderPath = null;
193                    Object[] finderArgs = null;
194    
195                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
196                                    (orderByComparator == null)) {
197                            pagination = false;
198                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
199                            finderArgs = new Object[] { uuid };
200                    }
201                    else {
202                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
203                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
204                    }
205    
206                    List<MBMessage> list = null;
207    
208                    if (retrieveFromCache) {
209                            list = (List<MBMessage>)finderCache.getResult(finderPath,
210                                            finderArgs, this);
211    
212                            if ((list != null) && !list.isEmpty()) {
213                                    for (MBMessage mbMessage : list) {
214                                            if (!Validator.equals(uuid, mbMessage.getUuid())) {
215                                                    list = null;
216    
217                                                    break;
218                                            }
219                                    }
220                            }
221                    }
222    
223                    if (list == null) {
224                            StringBundler query = null;
225    
226                            if (orderByComparator != null) {
227                                    query = new StringBundler(3 +
228                                                    (orderByComparator.getOrderByFields().length * 3));
229                            }
230                            else {
231                                    query = new StringBundler(3);
232                            }
233    
234                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
235    
236                            boolean bindUuid = false;
237    
238                            if (uuid == null) {
239                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
240                            }
241                            else if (uuid.equals(StringPool.BLANK)) {
242                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
243                            }
244                            else {
245                                    bindUuid = true;
246    
247                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
248                            }
249    
250                            if (orderByComparator != null) {
251                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
252                                            orderByComparator);
253                            }
254                            else
255                             if (pagination) {
256                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
257                            }
258    
259                            String sql = query.toString();
260    
261                            Session session = null;
262    
263                            try {
264                                    session = openSession();
265    
266                                    Query q = session.createQuery(sql);
267    
268                                    QueryPos qPos = QueryPos.getInstance(q);
269    
270                                    if (bindUuid) {
271                                            qPos.add(uuid);
272                                    }
273    
274                                    if (!pagination) {
275                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
276                                                            start, end, false);
277    
278                                            Collections.sort(list);
279    
280                                            list = Collections.unmodifiableList(list);
281                                    }
282                                    else {
283                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
284                                                            start, end);
285                                    }
286    
287                                    cacheResult(list);
288    
289                                    finderCache.putResult(finderPath, finderArgs, list);
290                            }
291                            catch (Exception e) {
292                                    finderCache.removeResult(finderPath, finderArgs);
293    
294                                    throw processException(e);
295                            }
296                            finally {
297                                    closeSession(session);
298                            }
299                    }
300    
301                    return list;
302            }
303    
304            /**
305             * Returns the first message-boards message in the ordered set where uuid = &#63;.
306             *
307             * @param uuid the uuid
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the first matching message-boards message
310             * @throws NoSuchMessageException if a matching message-boards message could not be found
311             */
312            @Override
313            public MBMessage findByUuid_First(String uuid,
314                    OrderByComparator<MBMessage> orderByComparator)
315                    throws NoSuchMessageException {
316                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
317    
318                    if (mbMessage != null) {
319                            return mbMessage;
320                    }
321    
322                    StringBundler msg = new StringBundler(4);
323    
324                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
325    
326                    msg.append("uuid=");
327                    msg.append(uuid);
328    
329                    msg.append(StringPool.CLOSE_CURLY_BRACE);
330    
331                    throw new NoSuchMessageException(msg.toString());
332            }
333    
334            /**
335             * Returns the first message-boards message in the ordered set where uuid = &#63;.
336             *
337             * @param uuid the uuid
338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
339             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
340             */
341            @Override
342            public MBMessage fetchByUuid_First(String uuid,
343                    OrderByComparator<MBMessage> orderByComparator) {
344                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
345    
346                    if (!list.isEmpty()) {
347                            return list.get(0);
348                    }
349    
350                    return null;
351            }
352    
353            /**
354             * Returns the last message-boards message in the ordered set where uuid = &#63;.
355             *
356             * @param uuid the uuid
357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
358             * @return the last matching message-boards message
359             * @throws NoSuchMessageException if a matching message-boards message could not be found
360             */
361            @Override
362            public MBMessage findByUuid_Last(String uuid,
363                    OrderByComparator<MBMessage> orderByComparator)
364                    throws NoSuchMessageException {
365                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
366    
367                    if (mbMessage != null) {
368                            return mbMessage;
369                    }
370    
371                    StringBundler msg = new StringBundler(4);
372    
373                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
374    
375                    msg.append("uuid=");
376                    msg.append(uuid);
377    
378                    msg.append(StringPool.CLOSE_CURLY_BRACE);
379    
380                    throw new NoSuchMessageException(msg.toString());
381            }
382    
383            /**
384             * Returns the last message-boards message in the ordered set where uuid = &#63;.
385             *
386             * @param uuid the uuid
387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
388             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
389             */
390            @Override
391            public MBMessage fetchByUuid_Last(String uuid,
392                    OrderByComparator<MBMessage> orderByComparator) {
393                    int count = countByUuid(uuid);
394    
395                    if (count == 0) {
396                            return null;
397                    }
398    
399                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
400                                    orderByComparator);
401    
402                    if (!list.isEmpty()) {
403                            return list.get(0);
404                    }
405    
406                    return null;
407            }
408    
409            /**
410             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
411             *
412             * @param messageId the primary key of the current message-boards message
413             * @param uuid the uuid
414             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
415             * @return the previous, current, and next message-boards message
416             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
417             */
418            @Override
419            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
420                    OrderByComparator<MBMessage> orderByComparator)
421                    throws NoSuchMessageException {
422                    MBMessage mbMessage = findByPrimaryKey(messageId);
423    
424                    Session session = null;
425    
426                    try {
427                            session = openSession();
428    
429                            MBMessage[] array = new MBMessageImpl[3];
430    
431                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
432                                            orderByComparator, true);
433    
434                            array[1] = mbMessage;
435    
436                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
437                                            orderByComparator, false);
438    
439                            return array;
440                    }
441                    catch (Exception e) {
442                            throw processException(e);
443                    }
444                    finally {
445                            closeSession(session);
446                    }
447            }
448    
449            protected MBMessage getByUuid_PrevAndNext(Session session,
450                    MBMessage mbMessage, String uuid,
451                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
452                    StringBundler query = null;
453    
454                    if (orderByComparator != null) {
455                            query = new StringBundler(6 +
456                                            (orderByComparator.getOrderByFields().length * 6));
457                    }
458                    else {
459                            query = new StringBundler(3);
460                    }
461    
462                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
463    
464                    boolean bindUuid = false;
465    
466                    if (uuid == null) {
467                            query.append(_FINDER_COLUMN_UUID_UUID_1);
468                    }
469                    else if (uuid.equals(StringPool.BLANK)) {
470                            query.append(_FINDER_COLUMN_UUID_UUID_3);
471                    }
472                    else {
473                            bindUuid = true;
474    
475                            query.append(_FINDER_COLUMN_UUID_UUID_2);
476                    }
477    
478                    if (orderByComparator != null) {
479                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
480    
481                            if (orderByConditionFields.length > 0) {
482                                    query.append(WHERE_AND);
483                            }
484    
485                            for (int i = 0; i < orderByConditionFields.length; i++) {
486                                    query.append(_ORDER_BY_ENTITY_ALIAS);
487                                    query.append(orderByConditionFields[i]);
488    
489                                    if ((i + 1) < orderByConditionFields.length) {
490                                            if (orderByComparator.isAscending() ^ previous) {
491                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
492                                            }
493                                            else {
494                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
495                                            }
496                                    }
497                                    else {
498                                            if (orderByComparator.isAscending() ^ previous) {
499                                                    query.append(WHERE_GREATER_THAN);
500                                            }
501                                            else {
502                                                    query.append(WHERE_LESSER_THAN);
503                                            }
504                                    }
505                            }
506    
507                            query.append(ORDER_BY_CLAUSE);
508    
509                            String[] orderByFields = orderByComparator.getOrderByFields();
510    
511                            for (int i = 0; i < orderByFields.length; i++) {
512                                    query.append(_ORDER_BY_ENTITY_ALIAS);
513                                    query.append(orderByFields[i]);
514    
515                                    if ((i + 1) < orderByFields.length) {
516                                            if (orderByComparator.isAscending() ^ previous) {
517                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
518                                            }
519                                            else {
520                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
521                                            }
522                                    }
523                                    else {
524                                            if (orderByComparator.isAscending() ^ previous) {
525                                                    query.append(ORDER_BY_ASC);
526                                            }
527                                            else {
528                                                    query.append(ORDER_BY_DESC);
529                                            }
530                                    }
531                            }
532                    }
533                    else {
534                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
535                    }
536    
537                    String sql = query.toString();
538    
539                    Query q = session.createQuery(sql);
540    
541                    q.setFirstResult(0);
542                    q.setMaxResults(2);
543    
544                    QueryPos qPos = QueryPos.getInstance(q);
545    
546                    if (bindUuid) {
547                            qPos.add(uuid);
548                    }
549    
550                    if (orderByComparator != null) {
551                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
552    
553                            for (Object value : values) {
554                                    qPos.add(value);
555                            }
556                    }
557    
558                    List<MBMessage> list = q.list();
559    
560                    if (list.size() == 2) {
561                            return list.get(1);
562                    }
563                    else {
564                            return null;
565                    }
566            }
567    
568            /**
569             * Removes all the message-boards messages where uuid = &#63; from the database.
570             *
571             * @param uuid the uuid
572             */
573            @Override
574            public void removeByUuid(String uuid) {
575                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
576                                    QueryUtil.ALL_POS, null)) {
577                            remove(mbMessage);
578                    }
579            }
580    
581            /**
582             * Returns the number of message-boards messages where uuid = &#63;.
583             *
584             * @param uuid the uuid
585             * @return the number of matching message-boards messages
586             */
587            @Override
588            public int countByUuid(String uuid) {
589                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
590    
591                    Object[] finderArgs = new Object[] { uuid };
592    
593                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
594    
595                    if (count == null) {
596                            StringBundler query = new StringBundler(2);
597    
598                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
599    
600                            boolean bindUuid = false;
601    
602                            if (uuid == null) {
603                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
604                            }
605                            else if (uuid.equals(StringPool.BLANK)) {
606                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
607                            }
608                            else {
609                                    bindUuid = true;
610    
611                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
612                            }
613    
614                            String sql = query.toString();
615    
616                            Session session = null;
617    
618                            try {
619                                    session = openSession();
620    
621                                    Query q = session.createQuery(sql);
622    
623                                    QueryPos qPos = QueryPos.getInstance(q);
624    
625                                    if (bindUuid) {
626                                            qPos.add(uuid);
627                                    }
628    
629                                    count = (Long)q.uniqueResult();
630    
631                                    finderCache.putResult(finderPath, finderArgs, count);
632                            }
633                            catch (Exception e) {
634                                    finderCache.removeResult(finderPath, finderArgs);
635    
636                                    throw processException(e);
637                            }
638                            finally {
639                                    closeSession(session);
640                            }
641                    }
642    
643                    return count.intValue();
644            }
645    
646            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
647            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
648            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
649            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
650                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
651                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
652                            new String[] { String.class.getName(), Long.class.getName() },
653                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
654                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
655            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
656                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
657                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
658                            new String[] { String.class.getName(), Long.class.getName() });
659    
660            /**
661             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
662             *
663             * @param uuid the uuid
664             * @param groupId the group ID
665             * @return the matching message-boards message
666             * @throws NoSuchMessageException if a matching message-boards message could not be found
667             */
668            @Override
669            public MBMessage findByUUID_G(String uuid, long groupId)
670                    throws NoSuchMessageException {
671                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
672    
673                    if (mbMessage == null) {
674                            StringBundler msg = new StringBundler(6);
675    
676                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
677    
678                            msg.append("uuid=");
679                            msg.append(uuid);
680    
681                            msg.append(", groupId=");
682                            msg.append(groupId);
683    
684                            msg.append(StringPool.CLOSE_CURLY_BRACE);
685    
686                            if (_log.isWarnEnabled()) {
687                                    _log.warn(msg.toString());
688                            }
689    
690                            throw new NoSuchMessageException(msg.toString());
691                    }
692    
693                    return mbMessage;
694            }
695    
696            /**
697             * 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.
698             *
699             * @param uuid the uuid
700             * @param groupId the group ID
701             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
702             */
703            @Override
704            public MBMessage fetchByUUID_G(String uuid, long groupId) {
705                    return fetchByUUID_G(uuid, groupId, true);
706            }
707    
708            /**
709             * 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.
710             *
711             * @param uuid the uuid
712             * @param groupId the group ID
713             * @param retrieveFromCache whether to retrieve from the finder cache
714             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
715             */
716            @Override
717            public MBMessage fetchByUUID_G(String uuid, long groupId,
718                    boolean retrieveFromCache) {
719                    Object[] finderArgs = new Object[] { uuid, groupId };
720    
721                    Object result = null;
722    
723                    if (retrieveFromCache) {
724                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
725                                            finderArgs, this);
726                    }
727    
728                    if (result instanceof MBMessage) {
729                            MBMessage mbMessage = (MBMessage)result;
730    
731                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
732                                            (groupId != mbMessage.getGroupId())) {
733                                    result = null;
734                            }
735                    }
736    
737                    if (result == null) {
738                            StringBundler query = new StringBundler(4);
739    
740                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
741    
742                            boolean bindUuid = false;
743    
744                            if (uuid == null) {
745                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
746                            }
747                            else if (uuid.equals(StringPool.BLANK)) {
748                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
749                            }
750                            else {
751                                    bindUuid = true;
752    
753                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
754                            }
755    
756                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
757    
758                            String sql = query.toString();
759    
760                            Session session = null;
761    
762                            try {
763                                    session = openSession();
764    
765                                    Query q = session.createQuery(sql);
766    
767                                    QueryPos qPos = QueryPos.getInstance(q);
768    
769                                    if (bindUuid) {
770                                            qPos.add(uuid);
771                                    }
772    
773                                    qPos.add(groupId);
774    
775                                    List<MBMessage> list = q.list();
776    
777                                    if (list.isEmpty()) {
778                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
779                                                    finderArgs, list);
780                                    }
781                                    else {
782                                            MBMessage mbMessage = list.get(0);
783    
784                                            result = mbMessage;
785    
786                                            cacheResult(mbMessage);
787    
788                                            if ((mbMessage.getUuid() == null) ||
789                                                            !mbMessage.getUuid().equals(uuid) ||
790                                                            (mbMessage.getGroupId() != groupId)) {
791                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
792                                                            finderArgs, mbMessage);
793                                            }
794                                    }
795                            }
796                            catch (Exception e) {
797                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
798    
799                                    throw processException(e);
800                            }
801                            finally {
802                                    closeSession(session);
803                            }
804                    }
805    
806                    if (result instanceof List<?>) {
807                            return null;
808                    }
809                    else {
810                            return (MBMessage)result;
811                    }
812            }
813    
814            /**
815             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
816             *
817             * @param uuid the uuid
818             * @param groupId the group ID
819             * @return the message-boards message that was removed
820             */
821            @Override
822            public MBMessage removeByUUID_G(String uuid, long groupId)
823                    throws NoSuchMessageException {
824                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
825    
826                    return remove(mbMessage);
827            }
828    
829            /**
830             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
831             *
832             * @param uuid the uuid
833             * @param groupId the group ID
834             * @return the number of matching message-boards messages
835             */
836            @Override
837            public int countByUUID_G(String uuid, long groupId) {
838                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
839    
840                    Object[] finderArgs = new Object[] { uuid, groupId };
841    
842                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
843    
844                    if (count == null) {
845                            StringBundler query = new StringBundler(3);
846    
847                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
848    
849                            boolean bindUuid = false;
850    
851                            if (uuid == null) {
852                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
853                            }
854                            else if (uuid.equals(StringPool.BLANK)) {
855                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
856                            }
857                            else {
858                                    bindUuid = true;
859    
860                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
861                            }
862    
863                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
864    
865                            String sql = query.toString();
866    
867                            Session session = null;
868    
869                            try {
870                                    session = openSession();
871    
872                                    Query q = session.createQuery(sql);
873    
874                                    QueryPos qPos = QueryPos.getInstance(q);
875    
876                                    if (bindUuid) {
877                                            qPos.add(uuid);
878                                    }
879    
880                                    qPos.add(groupId);
881    
882                                    count = (Long)q.uniqueResult();
883    
884                                    finderCache.putResult(finderPath, finderArgs, count);
885                            }
886                            catch (Exception e) {
887                                    finderCache.removeResult(finderPath, finderArgs);
888    
889                                    throw processException(e);
890                            }
891                            finally {
892                                    closeSession(session);
893                            }
894                    }
895    
896                    return count.intValue();
897            }
898    
899            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
900            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
901            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
902            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
903            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
904                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
905                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
906                            new String[] {
907                                    String.class.getName(), Long.class.getName(),
908                                    
909                            Integer.class.getName(), Integer.class.getName(),
910                                    OrderByComparator.class.getName()
911                            });
912            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
913                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
914                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
915                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
916                            new String[] { String.class.getName(), Long.class.getName() },
917                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
918                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
919                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
920            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
921                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
922                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
923                            new String[] { String.class.getName(), Long.class.getName() });
924    
925            /**
926             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
927             *
928             * @param uuid the uuid
929             * @param companyId the company ID
930             * @return the matching message-boards messages
931             */
932            @Override
933            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
934                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
935                            QueryUtil.ALL_POS, null);
936            }
937    
938            /**
939             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
940             *
941             * <p>
942             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
943             * </p>
944             *
945             * @param uuid the uuid
946             * @param companyId the company ID
947             * @param start the lower bound of the range of message-boards messages
948             * @param end the upper bound of the range of message-boards messages (not inclusive)
949             * @return the range of matching message-boards messages
950             */
951            @Override
952            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
953                    int end) {
954                    return findByUuid_C(uuid, companyId, start, end, null);
955            }
956    
957            /**
958             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
959             *
960             * <p>
961             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
962             * </p>
963             *
964             * @param uuid the uuid
965             * @param companyId the company ID
966             * @param start the lower bound of the range of message-boards messages
967             * @param end the upper bound of the range of message-boards messages (not inclusive)
968             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
969             * @return the ordered range of matching message-boards messages
970             */
971            @Override
972            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
973                    int end, OrderByComparator<MBMessage> orderByComparator) {
974                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
975            }
976    
977            /**
978             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
979             *
980             * <p>
981             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
982             * </p>
983             *
984             * @param uuid the uuid
985             * @param companyId the company ID
986             * @param start the lower bound of the range of message-boards messages
987             * @param end the upper bound of the range of message-boards messages (not inclusive)
988             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
989             * @param retrieveFromCache whether to retrieve from the finder cache
990             * @return the ordered range of matching message-boards messages
991             */
992            @Override
993            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
994                    int end, OrderByComparator<MBMessage> orderByComparator,
995                    boolean retrieveFromCache) {
996                    boolean pagination = true;
997                    FinderPath finderPath = null;
998                    Object[] finderArgs = null;
999    
1000                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1001                                    (orderByComparator == null)) {
1002                            pagination = false;
1003                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1004                            finderArgs = new Object[] { uuid, companyId };
1005                    }
1006                    else {
1007                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1008                            finderArgs = new Object[] {
1009                                            uuid, companyId,
1010                                            
1011                                            start, end, orderByComparator
1012                                    };
1013                    }
1014    
1015                    List<MBMessage> list = null;
1016    
1017                    if (retrieveFromCache) {
1018                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1019                                            finderArgs, this);
1020    
1021                            if ((list != null) && !list.isEmpty()) {
1022                                    for (MBMessage mbMessage : list) {
1023                                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
1024                                                            (companyId != mbMessage.getCompanyId())) {
1025                                                    list = null;
1026    
1027                                                    break;
1028                                            }
1029                                    }
1030                            }
1031                    }
1032    
1033                    if (list == null) {
1034                            StringBundler query = null;
1035    
1036                            if (orderByComparator != null) {
1037                                    query = new StringBundler(4 +
1038                                                    (orderByComparator.getOrderByFields().length * 3));
1039                            }
1040                            else {
1041                                    query = new StringBundler(4);
1042                            }
1043    
1044                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1045    
1046                            boolean bindUuid = false;
1047    
1048                            if (uuid == null) {
1049                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1050                            }
1051                            else if (uuid.equals(StringPool.BLANK)) {
1052                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1053                            }
1054                            else {
1055                                    bindUuid = true;
1056    
1057                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1058                            }
1059    
1060                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1061    
1062                            if (orderByComparator != null) {
1063                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1064                                            orderByComparator);
1065                            }
1066                            else
1067                             if (pagination) {
1068                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1069                            }
1070    
1071                            String sql = query.toString();
1072    
1073                            Session session = null;
1074    
1075                            try {
1076                                    session = openSession();
1077    
1078                                    Query q = session.createQuery(sql);
1079    
1080                                    QueryPos qPos = QueryPos.getInstance(q);
1081    
1082                                    if (bindUuid) {
1083                                            qPos.add(uuid);
1084                                    }
1085    
1086                                    qPos.add(companyId);
1087    
1088                                    if (!pagination) {
1089                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1090                                                            start, end, false);
1091    
1092                                            Collections.sort(list);
1093    
1094                                            list = Collections.unmodifiableList(list);
1095                                    }
1096                                    else {
1097                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1098                                                            start, end);
1099                                    }
1100    
1101                                    cacheResult(list);
1102    
1103                                    finderCache.putResult(finderPath, finderArgs, list);
1104                            }
1105                            catch (Exception e) {
1106                                    finderCache.removeResult(finderPath, finderArgs);
1107    
1108                                    throw processException(e);
1109                            }
1110                            finally {
1111                                    closeSession(session);
1112                            }
1113                    }
1114    
1115                    return list;
1116            }
1117    
1118            /**
1119             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1120             *
1121             * @param uuid the uuid
1122             * @param companyId the company ID
1123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1124             * @return the first matching message-boards message
1125             * @throws NoSuchMessageException if a matching message-boards message could not be found
1126             */
1127            @Override
1128            public MBMessage findByUuid_C_First(String uuid, long companyId,
1129                    OrderByComparator<MBMessage> orderByComparator)
1130                    throws NoSuchMessageException {
1131                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1132                                    orderByComparator);
1133    
1134                    if (mbMessage != null) {
1135                            return mbMessage;
1136                    }
1137    
1138                    StringBundler msg = new StringBundler(6);
1139    
1140                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1141    
1142                    msg.append("uuid=");
1143                    msg.append(uuid);
1144    
1145                    msg.append(", companyId=");
1146                    msg.append(companyId);
1147    
1148                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1149    
1150                    throw new NoSuchMessageException(msg.toString());
1151            }
1152    
1153            /**
1154             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1155             *
1156             * @param uuid the uuid
1157             * @param companyId the company ID
1158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1159             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1160             */
1161            @Override
1162            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1163                    OrderByComparator<MBMessage> orderByComparator) {
1164                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1165                                    orderByComparator);
1166    
1167                    if (!list.isEmpty()) {
1168                            return list.get(0);
1169                    }
1170    
1171                    return null;
1172            }
1173    
1174            /**
1175             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1176             *
1177             * @param uuid the uuid
1178             * @param companyId the company ID
1179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1180             * @return the last matching message-boards message
1181             * @throws NoSuchMessageException if a matching message-boards message could not be found
1182             */
1183            @Override
1184            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1185                    OrderByComparator<MBMessage> orderByComparator)
1186                    throws NoSuchMessageException {
1187                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1188                                    orderByComparator);
1189    
1190                    if (mbMessage != null) {
1191                            return mbMessage;
1192                    }
1193    
1194                    StringBundler msg = new StringBundler(6);
1195    
1196                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1197    
1198                    msg.append("uuid=");
1199                    msg.append(uuid);
1200    
1201                    msg.append(", companyId=");
1202                    msg.append(companyId);
1203    
1204                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1205    
1206                    throw new NoSuchMessageException(msg.toString());
1207            }
1208    
1209            /**
1210             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1211             *
1212             * @param uuid the uuid
1213             * @param companyId the company ID
1214             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1215             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1216             */
1217            @Override
1218            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1219                    OrderByComparator<MBMessage> orderByComparator) {
1220                    int count = countByUuid_C(uuid, companyId);
1221    
1222                    if (count == 0) {
1223                            return null;
1224                    }
1225    
1226                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1227                                    orderByComparator);
1228    
1229                    if (!list.isEmpty()) {
1230                            return list.get(0);
1231                    }
1232    
1233                    return null;
1234            }
1235    
1236            /**
1237             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1238             *
1239             * @param messageId the primary key of the current message-boards message
1240             * @param uuid the uuid
1241             * @param companyId the company ID
1242             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1243             * @return the previous, current, and next message-boards message
1244             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1245             */
1246            @Override
1247            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1248                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1249                    throws NoSuchMessageException {
1250                    MBMessage mbMessage = findByPrimaryKey(messageId);
1251    
1252                    Session session = null;
1253    
1254                    try {
1255                            session = openSession();
1256    
1257                            MBMessage[] array = new MBMessageImpl[3];
1258    
1259                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1260                                            companyId, orderByComparator, true);
1261    
1262                            array[1] = mbMessage;
1263    
1264                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1265                                            companyId, orderByComparator, false);
1266    
1267                            return array;
1268                    }
1269                    catch (Exception e) {
1270                            throw processException(e);
1271                    }
1272                    finally {
1273                            closeSession(session);
1274                    }
1275            }
1276    
1277            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1278                    MBMessage mbMessage, String uuid, long companyId,
1279                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1280                    StringBundler query = null;
1281    
1282                    if (orderByComparator != null) {
1283                            query = new StringBundler(6 +
1284                                            (orderByComparator.getOrderByFields().length * 6));
1285                    }
1286                    else {
1287                            query = new StringBundler(3);
1288                    }
1289    
1290                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1291    
1292                    boolean bindUuid = false;
1293    
1294                    if (uuid == null) {
1295                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1296                    }
1297                    else if (uuid.equals(StringPool.BLANK)) {
1298                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1299                    }
1300                    else {
1301                            bindUuid = true;
1302    
1303                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1304                    }
1305    
1306                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1307    
1308                    if (orderByComparator != null) {
1309                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1310    
1311                            if (orderByConditionFields.length > 0) {
1312                                    query.append(WHERE_AND);
1313                            }
1314    
1315                            for (int i = 0; i < orderByConditionFields.length; i++) {
1316                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1317                                    query.append(orderByConditionFields[i]);
1318    
1319                                    if ((i + 1) < orderByConditionFields.length) {
1320                                            if (orderByComparator.isAscending() ^ previous) {
1321                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1322                                            }
1323                                            else {
1324                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1325                                            }
1326                                    }
1327                                    else {
1328                                            if (orderByComparator.isAscending() ^ previous) {
1329                                                    query.append(WHERE_GREATER_THAN);
1330                                            }
1331                                            else {
1332                                                    query.append(WHERE_LESSER_THAN);
1333                                            }
1334                                    }
1335                            }
1336    
1337                            query.append(ORDER_BY_CLAUSE);
1338    
1339                            String[] orderByFields = orderByComparator.getOrderByFields();
1340    
1341                            for (int i = 0; i < orderByFields.length; i++) {
1342                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1343                                    query.append(orderByFields[i]);
1344    
1345                                    if ((i + 1) < orderByFields.length) {
1346                                            if (orderByComparator.isAscending() ^ previous) {
1347                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1348                                            }
1349                                            else {
1350                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1351                                            }
1352                                    }
1353                                    else {
1354                                            if (orderByComparator.isAscending() ^ previous) {
1355                                                    query.append(ORDER_BY_ASC);
1356                                            }
1357                                            else {
1358                                                    query.append(ORDER_BY_DESC);
1359                                            }
1360                                    }
1361                            }
1362                    }
1363                    else {
1364                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1365                    }
1366    
1367                    String sql = query.toString();
1368    
1369                    Query q = session.createQuery(sql);
1370    
1371                    q.setFirstResult(0);
1372                    q.setMaxResults(2);
1373    
1374                    QueryPos qPos = QueryPos.getInstance(q);
1375    
1376                    if (bindUuid) {
1377                            qPos.add(uuid);
1378                    }
1379    
1380                    qPos.add(companyId);
1381    
1382                    if (orderByComparator != null) {
1383                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1384    
1385                            for (Object value : values) {
1386                                    qPos.add(value);
1387                            }
1388                    }
1389    
1390                    List<MBMessage> list = q.list();
1391    
1392                    if (list.size() == 2) {
1393                            return list.get(1);
1394                    }
1395                    else {
1396                            return null;
1397                    }
1398            }
1399    
1400            /**
1401             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1402             *
1403             * @param uuid the uuid
1404             * @param companyId the company ID
1405             */
1406            @Override
1407            public void removeByUuid_C(String uuid, long companyId) {
1408                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1409                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1410                            remove(mbMessage);
1411                    }
1412            }
1413    
1414            /**
1415             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1416             *
1417             * @param uuid the uuid
1418             * @param companyId the company ID
1419             * @return the number of matching message-boards messages
1420             */
1421            @Override
1422            public int countByUuid_C(String uuid, long companyId) {
1423                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1424    
1425                    Object[] finderArgs = new Object[] { uuid, companyId };
1426    
1427                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1428    
1429                    if (count == null) {
1430                            StringBundler query = new StringBundler(3);
1431    
1432                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1433    
1434                            boolean bindUuid = false;
1435    
1436                            if (uuid == null) {
1437                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1438                            }
1439                            else if (uuid.equals(StringPool.BLANK)) {
1440                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1441                            }
1442                            else {
1443                                    bindUuid = true;
1444    
1445                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1446                            }
1447    
1448                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1449    
1450                            String sql = query.toString();
1451    
1452                            Session session = null;
1453    
1454                            try {
1455                                    session = openSession();
1456    
1457                                    Query q = session.createQuery(sql);
1458    
1459                                    QueryPos qPos = QueryPos.getInstance(q);
1460    
1461                                    if (bindUuid) {
1462                                            qPos.add(uuid);
1463                                    }
1464    
1465                                    qPos.add(companyId);
1466    
1467                                    count = (Long)q.uniqueResult();
1468    
1469                                    finderCache.putResult(finderPath, finderArgs, count);
1470                            }
1471                            catch (Exception e) {
1472                                    finderCache.removeResult(finderPath, finderArgs);
1473    
1474                                    throw processException(e);
1475                            }
1476                            finally {
1477                                    closeSession(session);
1478                            }
1479                    }
1480    
1481                    return count.intValue();
1482            }
1483    
1484            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1485            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1486            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1487            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1488            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1489                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1490                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1491                            new String[] {
1492                                    Long.class.getName(),
1493                                    
1494                            Integer.class.getName(), Integer.class.getName(),
1495                                    OrderByComparator.class.getName()
1496                            });
1497            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1498                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1499                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1500                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1501                            new String[] { Long.class.getName() },
1502                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1503                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1504            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1505                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1506                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1507                            new String[] { Long.class.getName() });
1508    
1509            /**
1510             * Returns all the message-boards messages where groupId = &#63;.
1511             *
1512             * @param groupId the group ID
1513             * @return the matching message-boards messages
1514             */
1515            @Override
1516            public List<MBMessage> findByGroupId(long groupId) {
1517                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1518            }
1519    
1520            /**
1521             * Returns a range of all the message-boards messages where groupId = &#63;.
1522             *
1523             * <p>
1524             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1525             * </p>
1526             *
1527             * @param groupId the group ID
1528             * @param start the lower bound of the range of message-boards messages
1529             * @param end the upper bound of the range of message-boards messages (not inclusive)
1530             * @return the range of matching message-boards messages
1531             */
1532            @Override
1533            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1534                    return findByGroupId(groupId, start, end, null);
1535            }
1536    
1537            /**
1538             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1539             *
1540             * <p>
1541             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1542             * </p>
1543             *
1544             * @param groupId the group ID
1545             * @param start the lower bound of the range of message-boards messages
1546             * @param end the upper bound of the range of message-boards messages (not inclusive)
1547             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1548             * @return the ordered range of matching message-boards messages
1549             */
1550            @Override
1551            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1552                    OrderByComparator<MBMessage> orderByComparator) {
1553                    return findByGroupId(groupId, start, end, orderByComparator, true);
1554            }
1555    
1556            /**
1557             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1558             *
1559             * <p>
1560             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1561             * </p>
1562             *
1563             * @param groupId the group ID
1564             * @param start the lower bound of the range of message-boards messages
1565             * @param end the upper bound of the range of message-boards messages (not inclusive)
1566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1567             * @param retrieveFromCache whether to retrieve from the finder cache
1568             * @return the ordered range of matching message-boards messages
1569             */
1570            @Override
1571            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1572                    OrderByComparator<MBMessage> orderByComparator,
1573                    boolean retrieveFromCache) {
1574                    boolean pagination = true;
1575                    FinderPath finderPath = null;
1576                    Object[] finderArgs = null;
1577    
1578                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1579                                    (orderByComparator == null)) {
1580                            pagination = false;
1581                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1582                            finderArgs = new Object[] { groupId };
1583                    }
1584                    else {
1585                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1586                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1587                    }
1588    
1589                    List<MBMessage> list = null;
1590    
1591                    if (retrieveFromCache) {
1592                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1593                                            finderArgs, this);
1594    
1595                            if ((list != null) && !list.isEmpty()) {
1596                                    for (MBMessage mbMessage : list) {
1597                                            if ((groupId != mbMessage.getGroupId())) {
1598                                                    list = null;
1599    
1600                                                    break;
1601                                            }
1602                                    }
1603                            }
1604                    }
1605    
1606                    if (list == null) {
1607                            StringBundler query = null;
1608    
1609                            if (orderByComparator != null) {
1610                                    query = new StringBundler(3 +
1611                                                    (orderByComparator.getOrderByFields().length * 3));
1612                            }
1613                            else {
1614                                    query = new StringBundler(3);
1615                            }
1616    
1617                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1618    
1619                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1620    
1621                            if (orderByComparator != null) {
1622                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1623                                            orderByComparator);
1624                            }
1625                            else
1626                             if (pagination) {
1627                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1628                            }
1629    
1630                            String sql = query.toString();
1631    
1632                            Session session = null;
1633    
1634                            try {
1635                                    session = openSession();
1636    
1637                                    Query q = session.createQuery(sql);
1638    
1639                                    QueryPos qPos = QueryPos.getInstance(q);
1640    
1641                                    qPos.add(groupId);
1642    
1643                                    if (!pagination) {
1644                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1645                                                            start, end, false);
1646    
1647                                            Collections.sort(list);
1648    
1649                                            list = Collections.unmodifiableList(list);
1650                                    }
1651                                    else {
1652                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1653                                                            start, end);
1654                                    }
1655    
1656                                    cacheResult(list);
1657    
1658                                    finderCache.putResult(finderPath, finderArgs, list);
1659                            }
1660                            catch (Exception e) {
1661                                    finderCache.removeResult(finderPath, finderArgs);
1662    
1663                                    throw processException(e);
1664                            }
1665                            finally {
1666                                    closeSession(session);
1667                            }
1668                    }
1669    
1670                    return list;
1671            }
1672    
1673            /**
1674             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1675             *
1676             * @param groupId the group ID
1677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1678             * @return the first matching message-boards message
1679             * @throws NoSuchMessageException if a matching message-boards message could not be found
1680             */
1681            @Override
1682            public MBMessage findByGroupId_First(long groupId,
1683                    OrderByComparator<MBMessage> orderByComparator)
1684                    throws NoSuchMessageException {
1685                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1686    
1687                    if (mbMessage != null) {
1688                            return mbMessage;
1689                    }
1690    
1691                    StringBundler msg = new StringBundler(4);
1692    
1693                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1694    
1695                    msg.append("groupId=");
1696                    msg.append(groupId);
1697    
1698                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1699    
1700                    throw new NoSuchMessageException(msg.toString());
1701            }
1702    
1703            /**
1704             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1705             *
1706             * @param groupId the group ID
1707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1708             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1709             */
1710            @Override
1711            public MBMessage fetchByGroupId_First(long groupId,
1712                    OrderByComparator<MBMessage> orderByComparator) {
1713                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1714    
1715                    if (!list.isEmpty()) {
1716                            return list.get(0);
1717                    }
1718    
1719                    return null;
1720            }
1721    
1722            /**
1723             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1724             *
1725             * @param groupId the group ID
1726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1727             * @return the last matching message-boards message
1728             * @throws NoSuchMessageException if a matching message-boards message could not be found
1729             */
1730            @Override
1731            public MBMessage findByGroupId_Last(long groupId,
1732                    OrderByComparator<MBMessage> orderByComparator)
1733                    throws NoSuchMessageException {
1734                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1735    
1736                    if (mbMessage != null) {
1737                            return mbMessage;
1738                    }
1739    
1740                    StringBundler msg = new StringBundler(4);
1741    
1742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                    msg.append("groupId=");
1745                    msg.append(groupId);
1746    
1747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1748    
1749                    throw new NoSuchMessageException(msg.toString());
1750            }
1751    
1752            /**
1753             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1754             *
1755             * @param groupId the group ID
1756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1757             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1758             */
1759            @Override
1760            public MBMessage fetchByGroupId_Last(long groupId,
1761                    OrderByComparator<MBMessage> orderByComparator) {
1762                    int count = countByGroupId(groupId);
1763    
1764                    if (count == 0) {
1765                            return null;
1766                    }
1767    
1768                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1769                                    orderByComparator);
1770    
1771                    if (!list.isEmpty()) {
1772                            return list.get(0);
1773                    }
1774    
1775                    return null;
1776            }
1777    
1778            /**
1779             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1780             *
1781             * @param messageId the primary key of the current message-boards message
1782             * @param groupId the group ID
1783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1784             * @return the previous, current, and next message-boards message
1785             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1786             */
1787            @Override
1788            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1789                    OrderByComparator<MBMessage> orderByComparator)
1790                    throws NoSuchMessageException {
1791                    MBMessage mbMessage = findByPrimaryKey(messageId);
1792    
1793                    Session session = null;
1794    
1795                    try {
1796                            session = openSession();
1797    
1798                            MBMessage[] array = new MBMessageImpl[3];
1799    
1800                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1801                                            orderByComparator, true);
1802    
1803                            array[1] = mbMessage;
1804    
1805                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1806                                            orderByComparator, false);
1807    
1808                            return array;
1809                    }
1810                    catch (Exception e) {
1811                            throw processException(e);
1812                    }
1813                    finally {
1814                            closeSession(session);
1815                    }
1816            }
1817    
1818            protected MBMessage getByGroupId_PrevAndNext(Session session,
1819                    MBMessage mbMessage, long groupId,
1820                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1821                    StringBundler query = null;
1822    
1823                    if (orderByComparator != null) {
1824                            query = new StringBundler(6 +
1825                                            (orderByComparator.getOrderByFields().length * 6));
1826                    }
1827                    else {
1828                            query = new StringBundler(3);
1829                    }
1830    
1831                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1832    
1833                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1834    
1835                    if (orderByComparator != null) {
1836                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1837    
1838                            if (orderByConditionFields.length > 0) {
1839                                    query.append(WHERE_AND);
1840                            }
1841    
1842                            for (int i = 0; i < orderByConditionFields.length; i++) {
1843                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1844                                    query.append(orderByConditionFields[i]);
1845    
1846                                    if ((i + 1) < orderByConditionFields.length) {
1847                                            if (orderByComparator.isAscending() ^ previous) {
1848                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1849                                            }
1850                                            else {
1851                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1852                                            }
1853                                    }
1854                                    else {
1855                                            if (orderByComparator.isAscending() ^ previous) {
1856                                                    query.append(WHERE_GREATER_THAN);
1857                                            }
1858                                            else {
1859                                                    query.append(WHERE_LESSER_THAN);
1860                                            }
1861                                    }
1862                            }
1863    
1864                            query.append(ORDER_BY_CLAUSE);
1865    
1866                            String[] orderByFields = orderByComparator.getOrderByFields();
1867    
1868                            for (int i = 0; i < orderByFields.length; i++) {
1869                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1870                                    query.append(orderByFields[i]);
1871    
1872                                    if ((i + 1) < orderByFields.length) {
1873                                            if (orderByComparator.isAscending() ^ previous) {
1874                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1875                                            }
1876                                            else {
1877                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1878                                            }
1879                                    }
1880                                    else {
1881                                            if (orderByComparator.isAscending() ^ previous) {
1882                                                    query.append(ORDER_BY_ASC);
1883                                            }
1884                                            else {
1885                                                    query.append(ORDER_BY_DESC);
1886                                            }
1887                                    }
1888                            }
1889                    }
1890                    else {
1891                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1892                    }
1893    
1894                    String sql = query.toString();
1895    
1896                    Query q = session.createQuery(sql);
1897    
1898                    q.setFirstResult(0);
1899                    q.setMaxResults(2);
1900    
1901                    QueryPos qPos = QueryPos.getInstance(q);
1902    
1903                    qPos.add(groupId);
1904    
1905                    if (orderByComparator != null) {
1906                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1907    
1908                            for (Object value : values) {
1909                                    qPos.add(value);
1910                            }
1911                    }
1912    
1913                    List<MBMessage> list = q.list();
1914    
1915                    if (list.size() == 2) {
1916                            return list.get(1);
1917                    }
1918                    else {
1919                            return null;
1920                    }
1921            }
1922    
1923            /**
1924             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1925             *
1926             * @param groupId the group ID
1927             * @return the matching message-boards messages that the user has permission to view
1928             */
1929            @Override
1930            public List<MBMessage> filterFindByGroupId(long groupId) {
1931                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1932                            QueryUtil.ALL_POS, null);
1933            }
1934    
1935            /**
1936             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1937             *
1938             * <p>
1939             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1940             * </p>
1941             *
1942             * @param groupId the group ID
1943             * @param start the lower bound of the range of message-boards messages
1944             * @param end the upper bound of the range of message-boards messages (not inclusive)
1945             * @return the range of matching message-boards messages that the user has permission to view
1946             */
1947            @Override
1948            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1949                    return filterFindByGroupId(groupId, start, end, null);
1950            }
1951    
1952            /**
1953             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1954             *
1955             * <p>
1956             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1957             * </p>
1958             *
1959             * @param groupId the group ID
1960             * @param start the lower bound of the range of message-boards messages
1961             * @param end the upper bound of the range of message-boards messages (not inclusive)
1962             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1963             * @return the ordered range of matching message-boards messages that the user has permission to view
1964             */
1965            @Override
1966            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1967                    int end, OrderByComparator<MBMessage> orderByComparator) {
1968                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1969                            return findByGroupId(groupId, start, end, orderByComparator);
1970                    }
1971    
1972                    StringBundler query = null;
1973    
1974                    if (orderByComparator != null) {
1975                            query = new StringBundler(3 +
1976                                            (orderByComparator.getOrderByFields().length * 3));
1977                    }
1978                    else {
1979                            query = new StringBundler(3);
1980                    }
1981    
1982                    if (getDB().isSupportsInlineDistinct()) {
1983                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1984                    }
1985                    else {
1986                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1987                    }
1988    
1989                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1990    
1991                    if (!getDB().isSupportsInlineDistinct()) {
1992                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1993                    }
1994    
1995                    if (orderByComparator != null) {
1996                            if (getDB().isSupportsInlineDistinct()) {
1997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1998                                            orderByComparator, true);
1999                            }
2000                            else {
2001                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2002                                            orderByComparator, true);
2003                            }
2004                    }
2005                    else {
2006                            if (getDB().isSupportsInlineDistinct()) {
2007                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2008                            }
2009                            else {
2010                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2011                            }
2012                    }
2013    
2014                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2015                                    MBMessage.class.getName(),
2016                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2017    
2018                    Session session = null;
2019    
2020                    try {
2021                            session = openSession();
2022    
2023                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2024    
2025                            if (getDB().isSupportsInlineDistinct()) {
2026                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2027                            }
2028                            else {
2029                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2030                            }
2031    
2032                            QueryPos qPos = QueryPos.getInstance(q);
2033    
2034                            qPos.add(groupId);
2035    
2036                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2037                    }
2038                    catch (Exception e) {
2039                            throw processException(e);
2040                    }
2041                    finally {
2042                            closeSession(session);
2043                    }
2044            }
2045    
2046            /**
2047             * 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;.
2048             *
2049             * @param messageId the primary key of the current message-boards message
2050             * @param groupId the group ID
2051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2052             * @return the previous, current, and next message-boards message
2053             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2054             */
2055            @Override
2056            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2057                    long groupId, OrderByComparator<MBMessage> orderByComparator)
2058                    throws NoSuchMessageException {
2059                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2060                            return findByGroupId_PrevAndNext(messageId, groupId,
2061                                    orderByComparator);
2062                    }
2063    
2064                    MBMessage mbMessage = findByPrimaryKey(messageId);
2065    
2066                    Session session = null;
2067    
2068                    try {
2069                            session = openSession();
2070    
2071                            MBMessage[] array = new MBMessageImpl[3];
2072    
2073                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2074                                            groupId, orderByComparator, true);
2075    
2076                            array[1] = mbMessage;
2077    
2078                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2079                                            groupId, orderByComparator, false);
2080    
2081                            return array;
2082                    }
2083                    catch (Exception e) {
2084                            throw processException(e);
2085                    }
2086                    finally {
2087                            closeSession(session);
2088                    }
2089            }
2090    
2091            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2092                    MBMessage mbMessage, long groupId,
2093                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2094                    StringBundler query = null;
2095    
2096                    if (orderByComparator != null) {
2097                            query = new StringBundler(6 +
2098                                            (orderByComparator.getOrderByFields().length * 6));
2099                    }
2100                    else {
2101                            query = new StringBundler(3);
2102                    }
2103    
2104                    if (getDB().isSupportsInlineDistinct()) {
2105                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2106                    }
2107                    else {
2108                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2109                    }
2110    
2111                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2112    
2113                    if (!getDB().isSupportsInlineDistinct()) {
2114                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2115                    }
2116    
2117                    if (orderByComparator != null) {
2118                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2119    
2120                            if (orderByConditionFields.length > 0) {
2121                                    query.append(WHERE_AND);
2122                            }
2123    
2124                            for (int i = 0; i < orderByConditionFields.length; i++) {
2125                                    if (getDB().isSupportsInlineDistinct()) {
2126                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2127                                    }
2128                                    else {
2129                                            query.append(_ORDER_BY_ENTITY_TABLE);
2130                                    }
2131    
2132                                    query.append(orderByConditionFields[i]);
2133    
2134                                    if ((i + 1) < orderByConditionFields.length) {
2135                                            if (orderByComparator.isAscending() ^ previous) {
2136                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2137                                            }
2138                                            else {
2139                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2140                                            }
2141                                    }
2142                                    else {
2143                                            if (orderByComparator.isAscending() ^ previous) {
2144                                                    query.append(WHERE_GREATER_THAN);
2145                                            }
2146                                            else {
2147                                                    query.append(WHERE_LESSER_THAN);
2148                                            }
2149                                    }
2150                            }
2151    
2152                            query.append(ORDER_BY_CLAUSE);
2153    
2154                            String[] orderByFields = orderByComparator.getOrderByFields();
2155    
2156                            for (int i = 0; i < orderByFields.length; i++) {
2157                                    if (getDB().isSupportsInlineDistinct()) {
2158                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2159                                    }
2160                                    else {
2161                                            query.append(_ORDER_BY_ENTITY_TABLE);
2162                                    }
2163    
2164                                    query.append(orderByFields[i]);
2165    
2166                                    if ((i + 1) < orderByFields.length) {
2167                                            if (orderByComparator.isAscending() ^ previous) {
2168                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2169                                            }
2170                                            else {
2171                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2172                                            }
2173                                    }
2174                                    else {
2175                                            if (orderByComparator.isAscending() ^ previous) {
2176                                                    query.append(ORDER_BY_ASC);
2177                                            }
2178                                            else {
2179                                                    query.append(ORDER_BY_DESC);
2180                                            }
2181                                    }
2182                            }
2183                    }
2184                    else {
2185                            if (getDB().isSupportsInlineDistinct()) {
2186                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2187                            }
2188                            else {
2189                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2190                            }
2191                    }
2192    
2193                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2194                                    MBMessage.class.getName(),
2195                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2196    
2197                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2198    
2199                    q.setFirstResult(0);
2200                    q.setMaxResults(2);
2201    
2202                    if (getDB().isSupportsInlineDistinct()) {
2203                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2204                    }
2205                    else {
2206                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2207                    }
2208    
2209                    QueryPos qPos = QueryPos.getInstance(q);
2210    
2211                    qPos.add(groupId);
2212    
2213                    if (orderByComparator != null) {
2214                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2215    
2216                            for (Object value : values) {
2217                                    qPos.add(value);
2218                            }
2219                    }
2220    
2221                    List<MBMessage> list = q.list();
2222    
2223                    if (list.size() == 2) {
2224                            return list.get(1);
2225                    }
2226                    else {
2227                            return null;
2228                    }
2229            }
2230    
2231            /**
2232             * Removes all the message-boards messages where groupId = &#63; from the database.
2233             *
2234             * @param groupId the group ID
2235             */
2236            @Override
2237            public void removeByGroupId(long groupId) {
2238                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2239                                    QueryUtil.ALL_POS, null)) {
2240                            remove(mbMessage);
2241                    }
2242            }
2243    
2244            /**
2245             * Returns the number of message-boards messages where groupId = &#63;.
2246             *
2247             * @param groupId the group ID
2248             * @return the number of matching message-boards messages
2249             */
2250            @Override
2251            public int countByGroupId(long groupId) {
2252                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2253    
2254                    Object[] finderArgs = new Object[] { groupId };
2255    
2256                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2257    
2258                    if (count == null) {
2259                            StringBundler query = new StringBundler(2);
2260    
2261                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2262    
2263                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2264    
2265                            String sql = query.toString();
2266    
2267                            Session session = null;
2268    
2269                            try {
2270                                    session = openSession();
2271    
2272                                    Query q = session.createQuery(sql);
2273    
2274                                    QueryPos qPos = QueryPos.getInstance(q);
2275    
2276                                    qPos.add(groupId);
2277    
2278                                    count = (Long)q.uniqueResult();
2279    
2280                                    finderCache.putResult(finderPath, finderArgs, count);
2281                            }
2282                            catch (Exception e) {
2283                                    finderCache.removeResult(finderPath, finderArgs);
2284    
2285                                    throw processException(e);
2286                            }
2287                            finally {
2288                                    closeSession(session);
2289                            }
2290                    }
2291    
2292                    return count.intValue();
2293            }
2294    
2295            /**
2296             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2297             *
2298             * @param groupId the group ID
2299             * @return the number of matching message-boards messages that the user has permission to view
2300             */
2301            @Override
2302            public int filterCountByGroupId(long groupId) {
2303                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2304                            return countByGroupId(groupId);
2305                    }
2306    
2307                    StringBundler query = new StringBundler(2);
2308    
2309                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2310    
2311                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2312    
2313                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2314                                    MBMessage.class.getName(),
2315                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2316    
2317                    Session session = null;
2318    
2319                    try {
2320                            session = openSession();
2321    
2322                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2323    
2324                            q.addScalar(COUNT_COLUMN_NAME,
2325                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2326    
2327                            QueryPos qPos = QueryPos.getInstance(q);
2328    
2329                            qPos.add(groupId);
2330    
2331                            Long count = (Long)q.uniqueResult();
2332    
2333                            return count.intValue();
2334                    }
2335                    catch (Exception e) {
2336                            throw processException(e);
2337                    }
2338                    finally {
2339                            closeSession(session);
2340                    }
2341            }
2342    
2343            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2344            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2345                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2346                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2347                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2348                            new String[] {
2349                                    Long.class.getName(),
2350                                    
2351                            Integer.class.getName(), Integer.class.getName(),
2352                                    OrderByComparator.class.getName()
2353                            });
2354            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2355                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2356                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2357                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2358                            new String[] { Long.class.getName() },
2359                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2360                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2361            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2362                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2363                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2364                            new String[] { Long.class.getName() });
2365    
2366            /**
2367             * Returns all the message-boards messages where companyId = &#63;.
2368             *
2369             * @param companyId the company ID
2370             * @return the matching message-boards messages
2371             */
2372            @Override
2373            public List<MBMessage> findByCompanyId(long companyId) {
2374                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2375                            null);
2376            }
2377    
2378            /**
2379             * Returns a range of all the message-boards messages where companyId = &#63;.
2380             *
2381             * <p>
2382             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2383             * </p>
2384             *
2385             * @param companyId the company ID
2386             * @param start the lower bound of the range of message-boards messages
2387             * @param end the upper bound of the range of message-boards messages (not inclusive)
2388             * @return the range of matching message-boards messages
2389             */
2390            @Override
2391            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2392                    return findByCompanyId(companyId, start, end, null);
2393            }
2394    
2395            /**
2396             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2397             *
2398             * <p>
2399             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2400             * </p>
2401             *
2402             * @param companyId the company ID
2403             * @param start the lower bound of the range of message-boards messages
2404             * @param end the upper bound of the range of message-boards messages (not inclusive)
2405             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2406             * @return the ordered range of matching message-boards messages
2407             */
2408            @Override
2409            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2410                    OrderByComparator<MBMessage> orderByComparator) {
2411                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2412            }
2413    
2414            /**
2415             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2416             *
2417             * <p>
2418             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2419             * </p>
2420             *
2421             * @param companyId the company ID
2422             * @param start the lower bound of the range of message-boards messages
2423             * @param end the upper bound of the range of message-boards messages (not inclusive)
2424             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2425             * @param retrieveFromCache whether to retrieve from the finder cache
2426             * @return the ordered range of matching message-boards messages
2427             */
2428            @Override
2429            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2430                    OrderByComparator<MBMessage> orderByComparator,
2431                    boolean retrieveFromCache) {
2432                    boolean pagination = true;
2433                    FinderPath finderPath = null;
2434                    Object[] finderArgs = null;
2435    
2436                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2437                                    (orderByComparator == null)) {
2438                            pagination = false;
2439                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2440                            finderArgs = new Object[] { companyId };
2441                    }
2442                    else {
2443                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2444                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2445                    }
2446    
2447                    List<MBMessage> list = null;
2448    
2449                    if (retrieveFromCache) {
2450                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2451                                            finderArgs, this);
2452    
2453                            if ((list != null) && !list.isEmpty()) {
2454                                    for (MBMessage mbMessage : list) {
2455                                            if ((companyId != mbMessage.getCompanyId())) {
2456                                                    list = null;
2457    
2458                                                    break;
2459                                            }
2460                                    }
2461                            }
2462                    }
2463    
2464                    if (list == null) {
2465                            StringBundler query = null;
2466    
2467                            if (orderByComparator != null) {
2468                                    query = new StringBundler(3 +
2469                                                    (orderByComparator.getOrderByFields().length * 3));
2470                            }
2471                            else {
2472                                    query = new StringBundler(3);
2473                            }
2474    
2475                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2476    
2477                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2478    
2479                            if (orderByComparator != null) {
2480                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2481                                            orderByComparator);
2482                            }
2483                            else
2484                             if (pagination) {
2485                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2486                            }
2487    
2488                            String sql = query.toString();
2489    
2490                            Session session = null;
2491    
2492                            try {
2493                                    session = openSession();
2494    
2495                                    Query q = session.createQuery(sql);
2496    
2497                                    QueryPos qPos = QueryPos.getInstance(q);
2498    
2499                                    qPos.add(companyId);
2500    
2501                                    if (!pagination) {
2502                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2503                                                            start, end, false);
2504    
2505                                            Collections.sort(list);
2506    
2507                                            list = Collections.unmodifiableList(list);
2508                                    }
2509                                    else {
2510                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2511                                                            start, end);
2512                                    }
2513    
2514                                    cacheResult(list);
2515    
2516                                    finderCache.putResult(finderPath, finderArgs, list);
2517                            }
2518                            catch (Exception e) {
2519                                    finderCache.removeResult(finderPath, finderArgs);
2520    
2521                                    throw processException(e);
2522                            }
2523                            finally {
2524                                    closeSession(session);
2525                            }
2526                    }
2527    
2528                    return list;
2529            }
2530    
2531            /**
2532             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2533             *
2534             * @param companyId the company ID
2535             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2536             * @return the first matching message-boards message
2537             * @throws NoSuchMessageException if a matching message-boards message could not be found
2538             */
2539            @Override
2540            public MBMessage findByCompanyId_First(long companyId,
2541                    OrderByComparator<MBMessage> orderByComparator)
2542                    throws NoSuchMessageException {
2543                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2544                                    orderByComparator);
2545    
2546                    if (mbMessage != null) {
2547                            return mbMessage;
2548                    }
2549    
2550                    StringBundler msg = new StringBundler(4);
2551    
2552                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2553    
2554                    msg.append("companyId=");
2555                    msg.append(companyId);
2556    
2557                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2558    
2559                    throw new NoSuchMessageException(msg.toString());
2560            }
2561    
2562            /**
2563             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2564             *
2565             * @param companyId the company ID
2566             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2567             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2568             */
2569            @Override
2570            public MBMessage fetchByCompanyId_First(long companyId,
2571                    OrderByComparator<MBMessage> orderByComparator) {
2572                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2573                                    orderByComparator);
2574    
2575                    if (!list.isEmpty()) {
2576                            return list.get(0);
2577                    }
2578    
2579                    return null;
2580            }
2581    
2582            /**
2583             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2584             *
2585             * @param companyId the company ID
2586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2587             * @return the last matching message-boards message
2588             * @throws NoSuchMessageException if a matching message-boards message could not be found
2589             */
2590            @Override
2591            public MBMessage findByCompanyId_Last(long companyId,
2592                    OrderByComparator<MBMessage> orderByComparator)
2593                    throws NoSuchMessageException {
2594                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2595    
2596                    if (mbMessage != null) {
2597                            return mbMessage;
2598                    }
2599    
2600                    StringBundler msg = new StringBundler(4);
2601    
2602                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2603    
2604                    msg.append("companyId=");
2605                    msg.append(companyId);
2606    
2607                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2608    
2609                    throw new NoSuchMessageException(msg.toString());
2610            }
2611    
2612            /**
2613             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2614             *
2615             * @param companyId the company ID
2616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2617             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2618             */
2619            @Override
2620            public MBMessage fetchByCompanyId_Last(long companyId,
2621                    OrderByComparator<MBMessage> orderByComparator) {
2622                    int count = countByCompanyId(companyId);
2623    
2624                    if (count == 0) {
2625                            return null;
2626                    }
2627    
2628                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2629                                    orderByComparator);
2630    
2631                    if (!list.isEmpty()) {
2632                            return list.get(0);
2633                    }
2634    
2635                    return null;
2636            }
2637    
2638            /**
2639             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2640             *
2641             * @param messageId the primary key of the current message-boards message
2642             * @param companyId the company ID
2643             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2644             * @return the previous, current, and next message-boards message
2645             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2646             */
2647            @Override
2648            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2649                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2650                    throws NoSuchMessageException {
2651                    MBMessage mbMessage = findByPrimaryKey(messageId);
2652    
2653                    Session session = null;
2654    
2655                    try {
2656                            session = openSession();
2657    
2658                            MBMessage[] array = new MBMessageImpl[3];
2659    
2660                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2661                                            companyId, orderByComparator, true);
2662    
2663                            array[1] = mbMessage;
2664    
2665                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2666                                            companyId, orderByComparator, false);
2667    
2668                            return array;
2669                    }
2670                    catch (Exception e) {
2671                            throw processException(e);
2672                    }
2673                    finally {
2674                            closeSession(session);
2675                    }
2676            }
2677    
2678            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2679                    MBMessage mbMessage, long companyId,
2680                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2681                    StringBundler query = null;
2682    
2683                    if (orderByComparator != null) {
2684                            query = new StringBundler(6 +
2685                                            (orderByComparator.getOrderByFields().length * 6));
2686                    }
2687                    else {
2688                            query = new StringBundler(3);
2689                    }
2690    
2691                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2692    
2693                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2694    
2695                    if (orderByComparator != null) {
2696                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2697    
2698                            if (orderByConditionFields.length > 0) {
2699                                    query.append(WHERE_AND);
2700                            }
2701    
2702                            for (int i = 0; i < orderByConditionFields.length; i++) {
2703                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2704                                    query.append(orderByConditionFields[i]);
2705    
2706                                    if ((i + 1) < orderByConditionFields.length) {
2707                                            if (orderByComparator.isAscending() ^ previous) {
2708                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2709                                            }
2710                                            else {
2711                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2712                                            }
2713                                    }
2714                                    else {
2715                                            if (orderByComparator.isAscending() ^ previous) {
2716                                                    query.append(WHERE_GREATER_THAN);
2717                                            }
2718                                            else {
2719                                                    query.append(WHERE_LESSER_THAN);
2720                                            }
2721                                    }
2722                            }
2723    
2724                            query.append(ORDER_BY_CLAUSE);
2725    
2726                            String[] orderByFields = orderByComparator.getOrderByFields();
2727    
2728                            for (int i = 0; i < orderByFields.length; i++) {
2729                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2730                                    query.append(orderByFields[i]);
2731    
2732                                    if ((i + 1) < orderByFields.length) {
2733                                            if (orderByComparator.isAscending() ^ previous) {
2734                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2735                                            }
2736                                            else {
2737                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2738                                            }
2739                                    }
2740                                    else {
2741                                            if (orderByComparator.isAscending() ^ previous) {
2742                                                    query.append(ORDER_BY_ASC);
2743                                            }
2744                                            else {
2745                                                    query.append(ORDER_BY_DESC);
2746                                            }
2747                                    }
2748                            }
2749                    }
2750                    else {
2751                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2752                    }
2753    
2754                    String sql = query.toString();
2755    
2756                    Query q = session.createQuery(sql);
2757    
2758                    q.setFirstResult(0);
2759                    q.setMaxResults(2);
2760    
2761                    QueryPos qPos = QueryPos.getInstance(q);
2762    
2763                    qPos.add(companyId);
2764    
2765                    if (orderByComparator != null) {
2766                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2767    
2768                            for (Object value : values) {
2769                                    qPos.add(value);
2770                            }
2771                    }
2772    
2773                    List<MBMessage> list = q.list();
2774    
2775                    if (list.size() == 2) {
2776                            return list.get(1);
2777                    }
2778                    else {
2779                            return null;
2780                    }
2781            }
2782    
2783            /**
2784             * Removes all the message-boards messages where companyId = &#63; from the database.
2785             *
2786             * @param companyId the company ID
2787             */
2788            @Override
2789            public void removeByCompanyId(long companyId) {
2790                    for (MBMessage mbMessage : findByCompanyId(companyId,
2791                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2792                            remove(mbMessage);
2793                    }
2794            }
2795    
2796            /**
2797             * Returns the number of message-boards messages where companyId = &#63;.
2798             *
2799             * @param companyId the company ID
2800             * @return the number of matching message-boards messages
2801             */
2802            @Override
2803            public int countByCompanyId(long companyId) {
2804                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2805    
2806                    Object[] finderArgs = new Object[] { companyId };
2807    
2808                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2809    
2810                    if (count == null) {
2811                            StringBundler query = new StringBundler(2);
2812    
2813                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2814    
2815                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2816    
2817                            String sql = query.toString();
2818    
2819                            Session session = null;
2820    
2821                            try {
2822                                    session = openSession();
2823    
2824                                    Query q = session.createQuery(sql);
2825    
2826                                    QueryPos qPos = QueryPos.getInstance(q);
2827    
2828                                    qPos.add(companyId);
2829    
2830                                    count = (Long)q.uniqueResult();
2831    
2832                                    finderCache.putResult(finderPath, finderArgs, count);
2833                            }
2834                            catch (Exception e) {
2835                                    finderCache.removeResult(finderPath, finderArgs);
2836    
2837                                    throw processException(e);
2838                            }
2839                            finally {
2840                                    closeSession(session);
2841                            }
2842                    }
2843    
2844                    return count.intValue();
2845            }
2846    
2847            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2848            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2849                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2850                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2851                            new String[] {
2852                                    Long.class.getName(),
2853                                    
2854                            Integer.class.getName(), Integer.class.getName(),
2855                                    OrderByComparator.class.getName()
2856                            });
2857            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2858                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2859                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2860                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2861                            new String[] { Long.class.getName() },
2862                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2863                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2864            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2865                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2866                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2867                            new String[] { Long.class.getName() });
2868    
2869            /**
2870             * Returns all the message-boards messages where userId = &#63;.
2871             *
2872             * @param userId the user ID
2873             * @return the matching message-boards messages
2874             */
2875            @Override
2876            public List<MBMessage> findByUserId(long userId) {
2877                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2878            }
2879    
2880            /**
2881             * Returns a range of all the message-boards messages where userId = &#63;.
2882             *
2883             * <p>
2884             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2885             * </p>
2886             *
2887             * @param userId the user ID
2888             * @param start the lower bound of the range of message-boards messages
2889             * @param end the upper bound of the range of message-boards messages (not inclusive)
2890             * @return the range of matching message-boards messages
2891             */
2892            @Override
2893            public List<MBMessage> findByUserId(long userId, int start, int end) {
2894                    return findByUserId(userId, start, end, null);
2895            }
2896    
2897            /**
2898             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2899             *
2900             * <p>
2901             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2902             * </p>
2903             *
2904             * @param userId the user ID
2905             * @param start the lower bound of the range of message-boards messages
2906             * @param end the upper bound of the range of message-boards messages (not inclusive)
2907             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2908             * @return the ordered range of matching message-boards messages
2909             */
2910            @Override
2911            public List<MBMessage> findByUserId(long userId, int start, int end,
2912                    OrderByComparator<MBMessage> orderByComparator) {
2913                    return findByUserId(userId, start, end, orderByComparator, true);
2914            }
2915    
2916            /**
2917             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2918             *
2919             * <p>
2920             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2921             * </p>
2922             *
2923             * @param userId the user ID
2924             * @param start the lower bound of the range of message-boards messages
2925             * @param end the upper bound of the range of message-boards messages (not inclusive)
2926             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2927             * @param retrieveFromCache whether to retrieve from the finder cache
2928             * @return the ordered range of matching message-boards messages
2929             */
2930            @Override
2931            public List<MBMessage> findByUserId(long userId, int start, int end,
2932                    OrderByComparator<MBMessage> orderByComparator,
2933                    boolean retrieveFromCache) {
2934                    boolean pagination = true;
2935                    FinderPath finderPath = null;
2936                    Object[] finderArgs = null;
2937    
2938                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2939                                    (orderByComparator == null)) {
2940                            pagination = false;
2941                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2942                            finderArgs = new Object[] { userId };
2943                    }
2944                    else {
2945                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2946                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2947                    }
2948    
2949                    List<MBMessage> list = null;
2950    
2951                    if (retrieveFromCache) {
2952                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2953                                            finderArgs, this);
2954    
2955                            if ((list != null) && !list.isEmpty()) {
2956                                    for (MBMessage mbMessage : list) {
2957                                            if ((userId != mbMessage.getUserId())) {
2958                                                    list = null;
2959    
2960                                                    break;
2961                                            }
2962                                    }
2963                            }
2964                    }
2965    
2966                    if (list == null) {
2967                            StringBundler query = null;
2968    
2969                            if (orderByComparator != null) {
2970                                    query = new StringBundler(3 +
2971                                                    (orderByComparator.getOrderByFields().length * 3));
2972                            }
2973                            else {
2974                                    query = new StringBundler(3);
2975                            }
2976    
2977                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2978    
2979                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2980    
2981                            if (orderByComparator != null) {
2982                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2983                                            orderByComparator);
2984                            }
2985                            else
2986                             if (pagination) {
2987                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2988                            }
2989    
2990                            String sql = query.toString();
2991    
2992                            Session session = null;
2993    
2994                            try {
2995                                    session = openSession();
2996    
2997                                    Query q = session.createQuery(sql);
2998    
2999                                    QueryPos qPos = QueryPos.getInstance(q);
3000    
3001                                    qPos.add(userId);
3002    
3003                                    if (!pagination) {
3004                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3005                                                            start, end, false);
3006    
3007                                            Collections.sort(list);
3008    
3009                                            list = Collections.unmodifiableList(list);
3010                                    }
3011                                    else {
3012                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3013                                                            start, end);
3014                                    }
3015    
3016                                    cacheResult(list);
3017    
3018                                    finderCache.putResult(finderPath, finderArgs, list);
3019                            }
3020                            catch (Exception e) {
3021                                    finderCache.removeResult(finderPath, finderArgs);
3022    
3023                                    throw processException(e);
3024                            }
3025                            finally {
3026                                    closeSession(session);
3027                            }
3028                    }
3029    
3030                    return list;
3031            }
3032    
3033            /**
3034             * Returns the first message-boards message in the ordered set where userId = &#63;.
3035             *
3036             * @param userId the user ID
3037             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3038             * @return the first matching message-boards message
3039             * @throws NoSuchMessageException if a matching message-boards message could not be found
3040             */
3041            @Override
3042            public MBMessage findByUserId_First(long userId,
3043                    OrderByComparator<MBMessage> orderByComparator)
3044                    throws NoSuchMessageException {
3045                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3046    
3047                    if (mbMessage != null) {
3048                            return mbMessage;
3049                    }
3050    
3051                    StringBundler msg = new StringBundler(4);
3052    
3053                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3054    
3055                    msg.append("userId=");
3056                    msg.append(userId);
3057    
3058                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3059    
3060                    throw new NoSuchMessageException(msg.toString());
3061            }
3062    
3063            /**
3064             * Returns the first message-boards message in the ordered set where userId = &#63;.
3065             *
3066             * @param userId the user ID
3067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3068             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3069             */
3070            @Override
3071            public MBMessage fetchByUserId_First(long userId,
3072                    OrderByComparator<MBMessage> orderByComparator) {
3073                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3074    
3075                    if (!list.isEmpty()) {
3076                            return list.get(0);
3077                    }
3078    
3079                    return null;
3080            }
3081    
3082            /**
3083             * Returns the last message-boards message in the ordered set where userId = &#63;.
3084             *
3085             * @param userId the user ID
3086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3087             * @return the last matching message-boards message
3088             * @throws NoSuchMessageException if a matching message-boards message could not be found
3089             */
3090            @Override
3091            public MBMessage findByUserId_Last(long userId,
3092                    OrderByComparator<MBMessage> orderByComparator)
3093                    throws NoSuchMessageException {
3094                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3095    
3096                    if (mbMessage != null) {
3097                            return mbMessage;
3098                    }
3099    
3100                    StringBundler msg = new StringBundler(4);
3101    
3102                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3103    
3104                    msg.append("userId=");
3105                    msg.append(userId);
3106    
3107                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3108    
3109                    throw new NoSuchMessageException(msg.toString());
3110            }
3111    
3112            /**
3113             * Returns the last message-boards message in the ordered set where userId = &#63;.
3114             *
3115             * @param userId the user ID
3116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3117             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3118             */
3119            @Override
3120            public MBMessage fetchByUserId_Last(long userId,
3121                    OrderByComparator<MBMessage> orderByComparator) {
3122                    int count = countByUserId(userId);
3123    
3124                    if (count == 0) {
3125                            return null;
3126                    }
3127    
3128                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3129                                    orderByComparator);
3130    
3131                    if (!list.isEmpty()) {
3132                            return list.get(0);
3133                    }
3134    
3135                    return null;
3136            }
3137    
3138            /**
3139             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3140             *
3141             * @param messageId the primary key of the current message-boards message
3142             * @param userId the user ID
3143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3144             * @return the previous, current, and next message-boards message
3145             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3146             */
3147            @Override
3148            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3149                    OrderByComparator<MBMessage> orderByComparator)
3150                    throws NoSuchMessageException {
3151                    MBMessage mbMessage = findByPrimaryKey(messageId);
3152    
3153                    Session session = null;
3154    
3155                    try {
3156                            session = openSession();
3157    
3158                            MBMessage[] array = new MBMessageImpl[3];
3159    
3160                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3161                                            orderByComparator, true);
3162    
3163                            array[1] = mbMessage;
3164    
3165                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3166                                            orderByComparator, false);
3167    
3168                            return array;
3169                    }
3170                    catch (Exception e) {
3171                            throw processException(e);
3172                    }
3173                    finally {
3174                            closeSession(session);
3175                    }
3176            }
3177    
3178            protected MBMessage getByUserId_PrevAndNext(Session session,
3179                    MBMessage mbMessage, long userId,
3180                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3181                    StringBundler query = null;
3182    
3183                    if (orderByComparator != null) {
3184                            query = new StringBundler(6 +
3185                                            (orderByComparator.getOrderByFields().length * 6));
3186                    }
3187                    else {
3188                            query = new StringBundler(3);
3189                    }
3190    
3191                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3192    
3193                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3194    
3195                    if (orderByComparator != null) {
3196                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3197    
3198                            if (orderByConditionFields.length > 0) {
3199                                    query.append(WHERE_AND);
3200                            }
3201    
3202                            for (int i = 0; i < orderByConditionFields.length; i++) {
3203                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3204                                    query.append(orderByConditionFields[i]);
3205    
3206                                    if ((i + 1) < orderByConditionFields.length) {
3207                                            if (orderByComparator.isAscending() ^ previous) {
3208                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3209                                            }
3210                                            else {
3211                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3212                                            }
3213                                    }
3214                                    else {
3215                                            if (orderByComparator.isAscending() ^ previous) {
3216                                                    query.append(WHERE_GREATER_THAN);
3217                                            }
3218                                            else {
3219                                                    query.append(WHERE_LESSER_THAN);
3220                                            }
3221                                    }
3222                            }
3223    
3224                            query.append(ORDER_BY_CLAUSE);
3225    
3226                            String[] orderByFields = orderByComparator.getOrderByFields();
3227    
3228                            for (int i = 0; i < orderByFields.length; i++) {
3229                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3230                                    query.append(orderByFields[i]);
3231    
3232                                    if ((i + 1) < orderByFields.length) {
3233                                            if (orderByComparator.isAscending() ^ previous) {
3234                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3235                                            }
3236                                            else {
3237                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3238                                            }
3239                                    }
3240                                    else {
3241                                            if (orderByComparator.isAscending() ^ previous) {
3242                                                    query.append(ORDER_BY_ASC);
3243                                            }
3244                                            else {
3245                                                    query.append(ORDER_BY_DESC);
3246                                            }
3247                                    }
3248                            }
3249                    }
3250                    else {
3251                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3252                    }
3253    
3254                    String sql = query.toString();
3255    
3256                    Query q = session.createQuery(sql);
3257    
3258                    q.setFirstResult(0);
3259                    q.setMaxResults(2);
3260    
3261                    QueryPos qPos = QueryPos.getInstance(q);
3262    
3263                    qPos.add(userId);
3264    
3265                    if (orderByComparator != null) {
3266                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3267    
3268                            for (Object value : values) {
3269                                    qPos.add(value);
3270                            }
3271                    }
3272    
3273                    List<MBMessage> list = q.list();
3274    
3275                    if (list.size() == 2) {
3276                            return list.get(1);
3277                    }
3278                    else {
3279                            return null;
3280                    }
3281            }
3282    
3283            /**
3284             * Removes all the message-boards messages where userId = &#63; from the database.
3285             *
3286             * @param userId the user ID
3287             */
3288            @Override
3289            public void removeByUserId(long userId) {
3290                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3291                                    QueryUtil.ALL_POS, null)) {
3292                            remove(mbMessage);
3293                    }
3294            }
3295    
3296            /**
3297             * Returns the number of message-boards messages where userId = &#63;.
3298             *
3299             * @param userId the user ID
3300             * @return the number of matching message-boards messages
3301             */
3302            @Override
3303            public int countByUserId(long userId) {
3304                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3305    
3306                    Object[] finderArgs = new Object[] { userId };
3307    
3308                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3309    
3310                    if (count == null) {
3311                            StringBundler query = new StringBundler(2);
3312    
3313                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3314    
3315                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3316    
3317                            String sql = query.toString();
3318    
3319                            Session session = null;
3320    
3321                            try {
3322                                    session = openSession();
3323    
3324                                    Query q = session.createQuery(sql);
3325    
3326                                    QueryPos qPos = QueryPos.getInstance(q);
3327    
3328                                    qPos.add(userId);
3329    
3330                                    count = (Long)q.uniqueResult();
3331    
3332                                    finderCache.putResult(finderPath, finderArgs, count);
3333                            }
3334                            catch (Exception e) {
3335                                    finderCache.removeResult(finderPath, finderArgs);
3336    
3337                                    throw processException(e);
3338                            }
3339                            finally {
3340                                    closeSession(session);
3341                            }
3342                    }
3343    
3344                    return count.intValue();
3345            }
3346    
3347            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3348            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3349                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3350                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3351                            new String[] {
3352                                    Long.class.getName(),
3353                                    
3354                            Integer.class.getName(), Integer.class.getName(),
3355                                    OrderByComparator.class.getName()
3356                            });
3357            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3358                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3359                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3360                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3361                            new String[] { Long.class.getName() },
3362                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3363                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3364            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3365                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3366                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3367                            new String[] { Long.class.getName() });
3368    
3369            /**
3370             * Returns all the message-boards messages where threadId = &#63;.
3371             *
3372             * @param threadId the thread ID
3373             * @return the matching message-boards messages
3374             */
3375            @Override
3376            public List<MBMessage> findByThreadId(long threadId) {
3377                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3378                            null);
3379            }
3380    
3381            /**
3382             * Returns a range of all the message-boards messages where threadId = &#63;.
3383             *
3384             * <p>
3385             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3386             * </p>
3387             *
3388             * @param threadId the thread ID
3389             * @param start the lower bound of the range of message-boards messages
3390             * @param end the upper bound of the range of message-boards messages (not inclusive)
3391             * @return the range of matching message-boards messages
3392             */
3393            @Override
3394            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3395                    return findByThreadId(threadId, start, end, null);
3396            }
3397    
3398            /**
3399             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3400             *
3401             * <p>
3402             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3403             * </p>
3404             *
3405             * @param threadId the thread ID
3406             * @param start the lower bound of the range of message-boards messages
3407             * @param end the upper bound of the range of message-boards messages (not inclusive)
3408             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3409             * @return the ordered range of matching message-boards messages
3410             */
3411            @Override
3412            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3413                    OrderByComparator<MBMessage> orderByComparator) {
3414                    return findByThreadId(threadId, start, end, orderByComparator, true);
3415            }
3416    
3417            /**
3418             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3419             *
3420             * <p>
3421             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3422             * </p>
3423             *
3424             * @param threadId the thread ID
3425             * @param start the lower bound of the range of message-boards messages
3426             * @param end the upper bound of the range of message-boards messages (not inclusive)
3427             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3428             * @param retrieveFromCache whether to retrieve from the finder cache
3429             * @return the ordered range of matching message-boards messages
3430             */
3431            @Override
3432            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3433                    OrderByComparator<MBMessage> orderByComparator,
3434                    boolean retrieveFromCache) {
3435                    boolean pagination = true;
3436                    FinderPath finderPath = null;
3437                    Object[] finderArgs = null;
3438    
3439                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3440                                    (orderByComparator == null)) {
3441                            pagination = false;
3442                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3443                            finderArgs = new Object[] { threadId };
3444                    }
3445                    else {
3446                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3447                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3448                    }
3449    
3450                    List<MBMessage> list = null;
3451    
3452                    if (retrieveFromCache) {
3453                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3454                                            finderArgs, this);
3455    
3456                            if ((list != null) && !list.isEmpty()) {
3457                                    for (MBMessage mbMessage : list) {
3458                                            if ((threadId != mbMessage.getThreadId())) {
3459                                                    list = null;
3460    
3461                                                    break;
3462                                            }
3463                                    }
3464                            }
3465                    }
3466    
3467                    if (list == null) {
3468                            StringBundler query = null;
3469    
3470                            if (orderByComparator != null) {
3471                                    query = new StringBundler(3 +
3472                                                    (orderByComparator.getOrderByFields().length * 3));
3473                            }
3474                            else {
3475                                    query = new StringBundler(3);
3476                            }
3477    
3478                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3479    
3480                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3481    
3482                            if (orderByComparator != null) {
3483                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3484                                            orderByComparator);
3485                            }
3486                            else
3487                             if (pagination) {
3488                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3489                            }
3490    
3491                            String sql = query.toString();
3492    
3493                            Session session = null;
3494    
3495                            try {
3496                                    session = openSession();
3497    
3498                                    Query q = session.createQuery(sql);
3499    
3500                                    QueryPos qPos = QueryPos.getInstance(q);
3501    
3502                                    qPos.add(threadId);
3503    
3504                                    if (!pagination) {
3505                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3506                                                            start, end, false);
3507    
3508                                            Collections.sort(list);
3509    
3510                                            list = Collections.unmodifiableList(list);
3511                                    }
3512                                    else {
3513                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3514                                                            start, end);
3515                                    }
3516    
3517                                    cacheResult(list);
3518    
3519                                    finderCache.putResult(finderPath, finderArgs, list);
3520                            }
3521                            catch (Exception e) {
3522                                    finderCache.removeResult(finderPath, finderArgs);
3523    
3524                                    throw processException(e);
3525                            }
3526                            finally {
3527                                    closeSession(session);
3528                            }
3529                    }
3530    
3531                    return list;
3532            }
3533    
3534            /**
3535             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3536             *
3537             * @param threadId the thread ID
3538             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3539             * @return the first matching message-boards message
3540             * @throws NoSuchMessageException if a matching message-boards message could not be found
3541             */
3542            @Override
3543            public MBMessage findByThreadId_First(long threadId,
3544                    OrderByComparator<MBMessage> orderByComparator)
3545                    throws NoSuchMessageException {
3546                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3547    
3548                    if (mbMessage != null) {
3549                            return mbMessage;
3550                    }
3551    
3552                    StringBundler msg = new StringBundler(4);
3553    
3554                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3555    
3556                    msg.append("threadId=");
3557                    msg.append(threadId);
3558    
3559                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3560    
3561                    throw new NoSuchMessageException(msg.toString());
3562            }
3563    
3564            /**
3565             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3566             *
3567             * @param threadId the thread ID
3568             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3569             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3570             */
3571            @Override
3572            public MBMessage fetchByThreadId_First(long threadId,
3573                    OrderByComparator<MBMessage> orderByComparator) {
3574                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3575    
3576                    if (!list.isEmpty()) {
3577                            return list.get(0);
3578                    }
3579    
3580                    return null;
3581            }
3582    
3583            /**
3584             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3585             *
3586             * @param threadId the thread ID
3587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3588             * @return the last matching message-boards message
3589             * @throws NoSuchMessageException if a matching message-boards message could not be found
3590             */
3591            @Override
3592            public MBMessage findByThreadId_Last(long threadId,
3593                    OrderByComparator<MBMessage> orderByComparator)
3594                    throws NoSuchMessageException {
3595                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3596    
3597                    if (mbMessage != null) {
3598                            return mbMessage;
3599                    }
3600    
3601                    StringBundler msg = new StringBundler(4);
3602    
3603                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3604    
3605                    msg.append("threadId=");
3606                    msg.append(threadId);
3607    
3608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3609    
3610                    throw new NoSuchMessageException(msg.toString());
3611            }
3612    
3613            /**
3614             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3615             *
3616             * @param threadId the thread ID
3617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3618             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3619             */
3620            @Override
3621            public MBMessage fetchByThreadId_Last(long threadId,
3622                    OrderByComparator<MBMessage> orderByComparator) {
3623                    int count = countByThreadId(threadId);
3624    
3625                    if (count == 0) {
3626                            return null;
3627                    }
3628    
3629                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3630                                    orderByComparator);
3631    
3632                    if (!list.isEmpty()) {
3633                            return list.get(0);
3634                    }
3635    
3636                    return null;
3637            }
3638    
3639            /**
3640             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3641             *
3642             * @param messageId the primary key of the current message-boards message
3643             * @param threadId the thread ID
3644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3645             * @return the previous, current, and next message-boards message
3646             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3647             */
3648            @Override
3649            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3650                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3651                    throws NoSuchMessageException {
3652                    MBMessage mbMessage = findByPrimaryKey(messageId);
3653    
3654                    Session session = null;
3655    
3656                    try {
3657                            session = openSession();
3658    
3659                            MBMessage[] array = new MBMessageImpl[3];
3660    
3661                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3662                                            orderByComparator, true);
3663    
3664                            array[1] = mbMessage;
3665    
3666                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3667                                            orderByComparator, false);
3668    
3669                            return array;
3670                    }
3671                    catch (Exception e) {
3672                            throw processException(e);
3673                    }
3674                    finally {
3675                            closeSession(session);
3676                    }
3677            }
3678    
3679            protected MBMessage getByThreadId_PrevAndNext(Session session,
3680                    MBMessage mbMessage, long threadId,
3681                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3682                    StringBundler query = null;
3683    
3684                    if (orderByComparator != null) {
3685                            query = new StringBundler(6 +
3686                                            (orderByComparator.getOrderByFields().length * 6));
3687                    }
3688                    else {
3689                            query = new StringBundler(3);
3690                    }
3691    
3692                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3693    
3694                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3695    
3696                    if (orderByComparator != null) {
3697                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3698    
3699                            if (orderByConditionFields.length > 0) {
3700                                    query.append(WHERE_AND);
3701                            }
3702    
3703                            for (int i = 0; i < orderByConditionFields.length; i++) {
3704                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3705                                    query.append(orderByConditionFields[i]);
3706    
3707                                    if ((i + 1) < orderByConditionFields.length) {
3708                                            if (orderByComparator.isAscending() ^ previous) {
3709                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3710                                            }
3711                                            else {
3712                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3713                                            }
3714                                    }
3715                                    else {
3716                                            if (orderByComparator.isAscending() ^ previous) {
3717                                                    query.append(WHERE_GREATER_THAN);
3718                                            }
3719                                            else {
3720                                                    query.append(WHERE_LESSER_THAN);
3721                                            }
3722                                    }
3723                            }
3724    
3725                            query.append(ORDER_BY_CLAUSE);
3726    
3727                            String[] orderByFields = orderByComparator.getOrderByFields();
3728    
3729                            for (int i = 0; i < orderByFields.length; i++) {
3730                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3731                                    query.append(orderByFields[i]);
3732    
3733                                    if ((i + 1) < orderByFields.length) {
3734                                            if (orderByComparator.isAscending() ^ previous) {
3735                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3736                                            }
3737                                            else {
3738                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3739                                            }
3740                                    }
3741                                    else {
3742                                            if (orderByComparator.isAscending() ^ previous) {
3743                                                    query.append(ORDER_BY_ASC);
3744                                            }
3745                                            else {
3746                                                    query.append(ORDER_BY_DESC);
3747                                            }
3748                                    }
3749                            }
3750                    }
3751                    else {
3752                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3753                    }
3754    
3755                    String sql = query.toString();
3756    
3757                    Query q = session.createQuery(sql);
3758    
3759                    q.setFirstResult(0);
3760                    q.setMaxResults(2);
3761    
3762                    QueryPos qPos = QueryPos.getInstance(q);
3763    
3764                    qPos.add(threadId);
3765    
3766                    if (orderByComparator != null) {
3767                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3768    
3769                            for (Object value : values) {
3770                                    qPos.add(value);
3771                            }
3772                    }
3773    
3774                    List<MBMessage> list = q.list();
3775    
3776                    if (list.size() == 2) {
3777                            return list.get(1);
3778                    }
3779                    else {
3780                            return null;
3781                    }
3782            }
3783    
3784            /**
3785             * Removes all the message-boards messages where threadId = &#63; from the database.
3786             *
3787             * @param threadId the thread ID
3788             */
3789            @Override
3790            public void removeByThreadId(long threadId) {
3791                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3792                                    QueryUtil.ALL_POS, null)) {
3793                            remove(mbMessage);
3794                    }
3795            }
3796    
3797            /**
3798             * Returns the number of message-boards messages where threadId = &#63;.
3799             *
3800             * @param threadId the thread ID
3801             * @return the number of matching message-boards messages
3802             */
3803            @Override
3804            public int countByThreadId(long threadId) {
3805                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3806    
3807                    Object[] finderArgs = new Object[] { threadId };
3808    
3809                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3810    
3811                    if (count == null) {
3812                            StringBundler query = new StringBundler(2);
3813    
3814                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3815    
3816                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3817    
3818                            String sql = query.toString();
3819    
3820                            Session session = null;
3821    
3822                            try {
3823                                    session = openSession();
3824    
3825                                    Query q = session.createQuery(sql);
3826    
3827                                    QueryPos qPos = QueryPos.getInstance(q);
3828    
3829                                    qPos.add(threadId);
3830    
3831                                    count = (Long)q.uniqueResult();
3832    
3833                                    finderCache.putResult(finderPath, finderArgs, count);
3834                            }
3835                            catch (Exception e) {
3836                                    finderCache.removeResult(finderPath, finderArgs);
3837    
3838                                    throw processException(e);
3839                            }
3840                            finally {
3841                                    closeSession(session);
3842                            }
3843                    }
3844    
3845                    return count.intValue();
3846            }
3847    
3848            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3849            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3850                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3851                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3852                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3853                            new String[] {
3854                                    Long.class.getName(),
3855                                    
3856                            Integer.class.getName(), Integer.class.getName(),
3857                                    OrderByComparator.class.getName()
3858                            });
3859            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3860                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3861                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3862                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3863                            new String[] { Long.class.getName() },
3864                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3865                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3866            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3867                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3868                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3869                            new String[] { Long.class.getName() });
3870    
3871            /**
3872             * Returns all the message-boards messages where threadId = &#63;.
3873             *
3874             * @param threadId the thread ID
3875             * @return the matching message-boards messages
3876             */
3877            @Override
3878            public List<MBMessage> findByThreadReplies(long threadId) {
3879                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3880                            QueryUtil.ALL_POS, null);
3881            }
3882    
3883            /**
3884             * Returns a range of all the message-boards messages where threadId = &#63;.
3885             *
3886             * <p>
3887             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3888             * </p>
3889             *
3890             * @param threadId the thread ID
3891             * @param start the lower bound of the range of message-boards messages
3892             * @param end the upper bound of the range of message-boards messages (not inclusive)
3893             * @return the range of matching message-boards messages
3894             */
3895            @Override
3896            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3897                    return findByThreadReplies(threadId, start, end, null);
3898            }
3899    
3900            /**
3901             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3902             *
3903             * <p>
3904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3905             * </p>
3906             *
3907             * @param threadId the thread ID
3908             * @param start the lower bound of the range of message-boards messages
3909             * @param end the upper bound of the range of message-boards messages (not inclusive)
3910             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3911             * @return the ordered range of matching message-boards messages
3912             */
3913            @Override
3914            public List<MBMessage> findByThreadReplies(long threadId, int start,
3915                    int end, OrderByComparator<MBMessage> orderByComparator) {
3916                    return findByThreadReplies(threadId, start, end, orderByComparator, true);
3917            }
3918    
3919            /**
3920             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3921             *
3922             * <p>
3923             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3924             * </p>
3925             *
3926             * @param threadId the thread ID
3927             * @param start the lower bound of the range of message-boards messages
3928             * @param end the upper bound of the range of message-boards messages (not inclusive)
3929             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3930             * @param retrieveFromCache whether to retrieve from the finder cache
3931             * @return the ordered range of matching message-boards messages
3932             */
3933            @Override
3934            public List<MBMessage> findByThreadReplies(long threadId, int start,
3935                    int end, OrderByComparator<MBMessage> orderByComparator,
3936                    boolean retrieveFromCache) {
3937                    boolean pagination = true;
3938                    FinderPath finderPath = null;
3939                    Object[] finderArgs = null;
3940    
3941                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3942                                    (orderByComparator == null)) {
3943                            pagination = false;
3944                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3945                            finderArgs = new Object[] { threadId };
3946                    }
3947                    else {
3948                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3949                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3950                    }
3951    
3952                    List<MBMessage> list = null;
3953    
3954                    if (retrieveFromCache) {
3955                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3956                                            finderArgs, this);
3957    
3958                            if ((list != null) && !list.isEmpty()) {
3959                                    for (MBMessage mbMessage : list) {
3960                                            if ((threadId != mbMessage.getThreadId())) {
3961                                                    list = null;
3962    
3963                                                    break;
3964                                            }
3965                                    }
3966                            }
3967                    }
3968    
3969                    if (list == null) {
3970                            StringBundler query = null;
3971    
3972                            if (orderByComparator != null) {
3973                                    query = new StringBundler(3 +
3974                                                    (orderByComparator.getOrderByFields().length * 3));
3975                            }
3976                            else {
3977                                    query = new StringBundler(3);
3978                            }
3979    
3980                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3981    
3982                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3983    
3984                            if (orderByComparator != null) {
3985                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3986                                            orderByComparator);
3987                            }
3988                            else
3989                             if (pagination) {
3990                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3991                            }
3992    
3993                            String sql = query.toString();
3994    
3995                            Session session = null;
3996    
3997                            try {
3998                                    session = openSession();
3999    
4000                                    Query q = session.createQuery(sql);
4001    
4002                                    QueryPos qPos = QueryPos.getInstance(q);
4003    
4004                                    qPos.add(threadId);
4005    
4006                                    if (!pagination) {
4007                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4008                                                            start, end, false);
4009    
4010                                            Collections.sort(list);
4011    
4012                                            list = Collections.unmodifiableList(list);
4013                                    }
4014                                    else {
4015                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4016                                                            start, end);
4017                                    }
4018    
4019                                    cacheResult(list);
4020    
4021                                    finderCache.putResult(finderPath, finderArgs, list);
4022                            }
4023                            catch (Exception e) {
4024                                    finderCache.removeResult(finderPath, finderArgs);
4025    
4026                                    throw processException(e);
4027                            }
4028                            finally {
4029                                    closeSession(session);
4030                            }
4031                    }
4032    
4033                    return list;
4034            }
4035    
4036            /**
4037             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4038             *
4039             * @param threadId the thread ID
4040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4041             * @return the first matching message-boards message
4042             * @throws NoSuchMessageException if a matching message-boards message could not be found
4043             */
4044            @Override
4045            public MBMessage findByThreadReplies_First(long threadId,
4046                    OrderByComparator<MBMessage> orderByComparator)
4047                    throws NoSuchMessageException {
4048                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4049                                    orderByComparator);
4050    
4051                    if (mbMessage != null) {
4052                            return mbMessage;
4053                    }
4054    
4055                    StringBundler msg = new StringBundler(4);
4056    
4057                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4058    
4059                    msg.append("threadId=");
4060                    msg.append(threadId);
4061    
4062                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4063    
4064                    throw new NoSuchMessageException(msg.toString());
4065            }
4066    
4067            /**
4068             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4069             *
4070             * @param threadId the thread ID
4071             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4072             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4073             */
4074            @Override
4075            public MBMessage fetchByThreadReplies_First(long threadId,
4076                    OrderByComparator<MBMessage> orderByComparator) {
4077                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4078                                    orderByComparator);
4079    
4080                    if (!list.isEmpty()) {
4081                            return list.get(0);
4082                    }
4083    
4084                    return null;
4085            }
4086    
4087            /**
4088             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4089             *
4090             * @param threadId the thread ID
4091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4092             * @return the last matching message-boards message
4093             * @throws NoSuchMessageException if a matching message-boards message could not be found
4094             */
4095            @Override
4096            public MBMessage findByThreadReplies_Last(long threadId,
4097                    OrderByComparator<MBMessage> orderByComparator)
4098                    throws NoSuchMessageException {
4099                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4100                                    orderByComparator);
4101    
4102                    if (mbMessage != null) {
4103                            return mbMessage;
4104                    }
4105    
4106                    StringBundler msg = new StringBundler(4);
4107    
4108                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4109    
4110                    msg.append("threadId=");
4111                    msg.append(threadId);
4112    
4113                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4114    
4115                    throw new NoSuchMessageException(msg.toString());
4116            }
4117    
4118            /**
4119             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4120             *
4121             * @param threadId the thread ID
4122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4123             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4124             */
4125            @Override
4126            public MBMessage fetchByThreadReplies_Last(long threadId,
4127                    OrderByComparator<MBMessage> orderByComparator) {
4128                    int count = countByThreadReplies(threadId);
4129    
4130                    if (count == 0) {
4131                            return null;
4132                    }
4133    
4134                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4135                                    orderByComparator);
4136    
4137                    if (!list.isEmpty()) {
4138                            return list.get(0);
4139                    }
4140    
4141                    return null;
4142            }
4143    
4144            /**
4145             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4146             *
4147             * @param messageId the primary key of the current message-boards message
4148             * @param threadId the thread ID
4149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4150             * @return the previous, current, and next message-boards message
4151             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4152             */
4153            @Override
4154            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4155                    long threadId, OrderByComparator<MBMessage> orderByComparator)
4156                    throws NoSuchMessageException {
4157                    MBMessage mbMessage = findByPrimaryKey(messageId);
4158    
4159                    Session session = null;
4160    
4161                    try {
4162                            session = openSession();
4163    
4164                            MBMessage[] array = new MBMessageImpl[3];
4165    
4166                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4167                                            threadId, orderByComparator, true);
4168    
4169                            array[1] = mbMessage;
4170    
4171                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4172                                            threadId, orderByComparator, false);
4173    
4174                            return array;
4175                    }
4176                    catch (Exception e) {
4177                            throw processException(e);
4178                    }
4179                    finally {
4180                            closeSession(session);
4181                    }
4182            }
4183    
4184            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4185                    MBMessage mbMessage, long threadId,
4186                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4187                    StringBundler query = null;
4188    
4189                    if (orderByComparator != null) {
4190                            query = new StringBundler(6 +
4191                                            (orderByComparator.getOrderByFields().length * 6));
4192                    }
4193                    else {
4194                            query = new StringBundler(3);
4195                    }
4196    
4197                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4198    
4199                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4200    
4201                    if (orderByComparator != null) {
4202                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4203    
4204                            if (orderByConditionFields.length > 0) {
4205                                    query.append(WHERE_AND);
4206                            }
4207    
4208                            for (int i = 0; i < orderByConditionFields.length; i++) {
4209                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4210                                    query.append(orderByConditionFields[i]);
4211    
4212                                    if ((i + 1) < orderByConditionFields.length) {
4213                                            if (orderByComparator.isAscending() ^ previous) {
4214                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4215                                            }
4216                                            else {
4217                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4218                                            }
4219                                    }
4220                                    else {
4221                                            if (orderByComparator.isAscending() ^ previous) {
4222                                                    query.append(WHERE_GREATER_THAN);
4223                                            }
4224                                            else {
4225                                                    query.append(WHERE_LESSER_THAN);
4226                                            }
4227                                    }
4228                            }
4229    
4230                            query.append(ORDER_BY_CLAUSE);
4231    
4232                            String[] orderByFields = orderByComparator.getOrderByFields();
4233    
4234                            for (int i = 0; i < orderByFields.length; i++) {
4235                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4236                                    query.append(orderByFields[i]);
4237    
4238                                    if ((i + 1) < orderByFields.length) {
4239                                            if (orderByComparator.isAscending() ^ previous) {
4240                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4241                                            }
4242                                            else {
4243                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4244                                            }
4245                                    }
4246                                    else {
4247                                            if (orderByComparator.isAscending() ^ previous) {
4248                                                    query.append(ORDER_BY_ASC);
4249                                            }
4250                                            else {
4251                                                    query.append(ORDER_BY_DESC);
4252                                            }
4253                                    }
4254                            }
4255                    }
4256                    else {
4257                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4258                    }
4259    
4260                    String sql = query.toString();
4261    
4262                    Query q = session.createQuery(sql);
4263    
4264                    q.setFirstResult(0);
4265                    q.setMaxResults(2);
4266    
4267                    QueryPos qPos = QueryPos.getInstance(q);
4268    
4269                    qPos.add(threadId);
4270    
4271                    if (orderByComparator != null) {
4272                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4273    
4274                            for (Object value : values) {
4275                                    qPos.add(value);
4276                            }
4277                    }
4278    
4279                    List<MBMessage> list = q.list();
4280    
4281                    if (list.size() == 2) {
4282                            return list.get(1);
4283                    }
4284                    else {
4285                            return null;
4286                    }
4287            }
4288    
4289            /**
4290             * Removes all the message-boards messages where threadId = &#63; from the database.
4291             *
4292             * @param threadId the thread ID
4293             */
4294            @Override
4295            public void removeByThreadReplies(long threadId) {
4296                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4297                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4298                            remove(mbMessage);
4299                    }
4300            }
4301    
4302            /**
4303             * Returns the number of message-boards messages where threadId = &#63;.
4304             *
4305             * @param threadId the thread ID
4306             * @return the number of matching message-boards messages
4307             */
4308            @Override
4309            public int countByThreadReplies(long threadId) {
4310                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4311    
4312                    Object[] finderArgs = new Object[] { threadId };
4313    
4314                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4315    
4316                    if (count == null) {
4317                            StringBundler query = new StringBundler(2);
4318    
4319                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4320    
4321                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4322    
4323                            String sql = query.toString();
4324    
4325                            Session session = null;
4326    
4327                            try {
4328                                    session = openSession();
4329    
4330                                    Query q = session.createQuery(sql);
4331    
4332                                    QueryPos qPos = QueryPos.getInstance(q);
4333    
4334                                    qPos.add(threadId);
4335    
4336                                    count = (Long)q.uniqueResult();
4337    
4338                                    finderCache.putResult(finderPath, finderArgs, count);
4339                            }
4340                            catch (Exception e) {
4341                                    finderCache.removeResult(finderPath, finderArgs);
4342    
4343                                    throw processException(e);
4344                            }
4345                            finally {
4346                                    closeSession(session);
4347                            }
4348                    }
4349    
4350                    return count.intValue();
4351            }
4352    
4353            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4354            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4355                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4356                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4357                            new String[] {
4358                                    Long.class.getName(), Long.class.getName(),
4359                                    
4360                            Integer.class.getName(), Integer.class.getName(),
4361                                    OrderByComparator.class.getName()
4362                            });
4363            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4364                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4365                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4366                            new String[] { Long.class.getName(), Long.class.getName() },
4367                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4368                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4369                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4370            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4371                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4372                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4373                            new String[] { Long.class.getName(), Long.class.getName() });
4374    
4375            /**
4376             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4377             *
4378             * @param groupId the group ID
4379             * @param userId the user ID
4380             * @return the matching message-boards messages
4381             */
4382            @Override
4383            public List<MBMessage> findByG_U(long groupId, long userId) {
4384                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4385                            null);
4386            }
4387    
4388            /**
4389             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4390             *
4391             * <p>
4392             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4393             * </p>
4394             *
4395             * @param groupId the group ID
4396             * @param userId the user ID
4397             * @param start the lower bound of the range of message-boards messages
4398             * @param end the upper bound of the range of message-boards messages (not inclusive)
4399             * @return the range of matching message-boards messages
4400             */
4401            @Override
4402            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4403                    int end) {
4404                    return findByG_U(groupId, userId, start, end, null);
4405            }
4406    
4407            /**
4408             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4409             *
4410             * <p>
4411             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4412             * </p>
4413             *
4414             * @param groupId the group ID
4415             * @param userId the user ID
4416             * @param start the lower bound of the range of message-boards messages
4417             * @param end the upper bound of the range of message-boards messages (not inclusive)
4418             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4419             * @return the ordered range of matching message-boards messages
4420             */
4421            @Override
4422            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4423                    int end, OrderByComparator<MBMessage> orderByComparator) {
4424                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
4425            }
4426    
4427            /**
4428             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4429             *
4430             * <p>
4431             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4432             * </p>
4433             *
4434             * @param groupId the group ID
4435             * @param userId the user ID
4436             * @param start the lower bound of the range of message-boards messages
4437             * @param end the upper bound of the range of message-boards messages (not inclusive)
4438             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4439             * @param retrieveFromCache whether to retrieve from the finder cache
4440             * @return the ordered range of matching message-boards messages
4441             */
4442            @Override
4443            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4444                    int end, OrderByComparator<MBMessage> orderByComparator,
4445                    boolean retrieveFromCache) {
4446                    boolean pagination = true;
4447                    FinderPath finderPath = null;
4448                    Object[] finderArgs = null;
4449    
4450                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4451                                    (orderByComparator == null)) {
4452                            pagination = false;
4453                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4454                            finderArgs = new Object[] { groupId, userId };
4455                    }
4456                    else {
4457                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4458                            finderArgs = new Object[] {
4459                                            groupId, userId,
4460                                            
4461                                            start, end, orderByComparator
4462                                    };
4463                    }
4464    
4465                    List<MBMessage> list = null;
4466    
4467                    if (retrieveFromCache) {
4468                            list = (List<MBMessage>)finderCache.getResult(finderPath,
4469                                            finderArgs, this);
4470    
4471                            if ((list != null) && !list.isEmpty()) {
4472                                    for (MBMessage mbMessage : list) {
4473                                            if ((groupId != mbMessage.getGroupId()) ||
4474                                                            (userId != mbMessage.getUserId())) {
4475                                                    list = null;
4476    
4477                                                    break;
4478                                            }
4479                                    }
4480                            }
4481                    }
4482    
4483                    if (list == null) {
4484                            StringBundler query = null;
4485    
4486                            if (orderByComparator != null) {
4487                                    query = new StringBundler(4 +
4488                                                    (orderByComparator.getOrderByFields().length * 3));
4489                            }
4490                            else {
4491                                    query = new StringBundler(4);
4492                            }
4493    
4494                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4495    
4496                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4497    
4498                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4499    
4500                            if (orderByComparator != null) {
4501                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4502                                            orderByComparator);
4503                            }
4504                            else
4505                             if (pagination) {
4506                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4507                            }
4508    
4509                            String sql = query.toString();
4510    
4511                            Session session = null;
4512    
4513                            try {
4514                                    session = openSession();
4515    
4516                                    Query q = session.createQuery(sql);
4517    
4518                                    QueryPos qPos = QueryPos.getInstance(q);
4519    
4520                                    qPos.add(groupId);
4521    
4522                                    qPos.add(userId);
4523    
4524                                    if (!pagination) {
4525                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4526                                                            start, end, false);
4527    
4528                                            Collections.sort(list);
4529    
4530                                            list = Collections.unmodifiableList(list);
4531                                    }
4532                                    else {
4533                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4534                                                            start, end);
4535                                    }
4536    
4537                                    cacheResult(list);
4538    
4539                                    finderCache.putResult(finderPath, finderArgs, list);
4540                            }
4541                            catch (Exception e) {
4542                                    finderCache.removeResult(finderPath, finderArgs);
4543    
4544                                    throw processException(e);
4545                            }
4546                            finally {
4547                                    closeSession(session);
4548                            }
4549                    }
4550    
4551                    return list;
4552            }
4553    
4554            /**
4555             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4556             *
4557             * @param groupId the group ID
4558             * @param userId the user ID
4559             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4560             * @return the first matching message-boards message
4561             * @throws NoSuchMessageException if a matching message-boards message could not be found
4562             */
4563            @Override
4564            public MBMessage findByG_U_First(long groupId, long userId,
4565                    OrderByComparator<MBMessage> orderByComparator)
4566                    throws NoSuchMessageException {
4567                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4568                                    orderByComparator);
4569    
4570                    if (mbMessage != null) {
4571                            return mbMessage;
4572                    }
4573    
4574                    StringBundler msg = new StringBundler(6);
4575    
4576                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4577    
4578                    msg.append("groupId=");
4579                    msg.append(groupId);
4580    
4581                    msg.append(", userId=");
4582                    msg.append(userId);
4583    
4584                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4585    
4586                    throw new NoSuchMessageException(msg.toString());
4587            }
4588    
4589            /**
4590             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4591             *
4592             * @param groupId the group ID
4593             * @param userId the user ID
4594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4595             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4596             */
4597            @Override
4598            public MBMessage fetchByG_U_First(long groupId, long userId,
4599                    OrderByComparator<MBMessage> orderByComparator) {
4600                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4601                                    orderByComparator);
4602    
4603                    if (!list.isEmpty()) {
4604                            return list.get(0);
4605                    }
4606    
4607                    return null;
4608            }
4609    
4610            /**
4611             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4612             *
4613             * @param groupId the group ID
4614             * @param userId the user ID
4615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4616             * @return the last matching message-boards message
4617             * @throws NoSuchMessageException if a matching message-boards message could not be found
4618             */
4619            @Override
4620            public MBMessage findByG_U_Last(long groupId, long userId,
4621                    OrderByComparator<MBMessage> orderByComparator)
4622                    throws NoSuchMessageException {
4623                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4624    
4625                    if (mbMessage != null) {
4626                            return mbMessage;
4627                    }
4628    
4629                    StringBundler msg = new StringBundler(6);
4630    
4631                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4632    
4633                    msg.append("groupId=");
4634                    msg.append(groupId);
4635    
4636                    msg.append(", userId=");
4637                    msg.append(userId);
4638    
4639                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4640    
4641                    throw new NoSuchMessageException(msg.toString());
4642            }
4643    
4644            /**
4645             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4646             *
4647             * @param groupId the group ID
4648             * @param userId the user ID
4649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4650             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4651             */
4652            @Override
4653            public MBMessage fetchByG_U_Last(long groupId, long userId,
4654                    OrderByComparator<MBMessage> orderByComparator) {
4655                    int count = countByG_U(groupId, userId);
4656    
4657                    if (count == 0) {
4658                            return null;
4659                    }
4660    
4661                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4662                                    orderByComparator);
4663    
4664                    if (!list.isEmpty()) {
4665                            return list.get(0);
4666                    }
4667    
4668                    return null;
4669            }
4670    
4671            /**
4672             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4673             *
4674             * @param messageId the primary key of the current message-boards message
4675             * @param groupId the group ID
4676             * @param userId the user ID
4677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4678             * @return the previous, current, and next message-boards message
4679             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4680             */
4681            @Override
4682            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4683                    long userId, OrderByComparator<MBMessage> orderByComparator)
4684                    throws NoSuchMessageException {
4685                    MBMessage mbMessage = findByPrimaryKey(messageId);
4686    
4687                    Session session = null;
4688    
4689                    try {
4690                            session = openSession();
4691    
4692                            MBMessage[] array = new MBMessageImpl[3];
4693    
4694                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4695                                            userId, orderByComparator, true);
4696    
4697                            array[1] = mbMessage;
4698    
4699                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4700                                            userId, orderByComparator, false);
4701    
4702                            return array;
4703                    }
4704                    catch (Exception e) {
4705                            throw processException(e);
4706                    }
4707                    finally {
4708                            closeSession(session);
4709                    }
4710            }
4711    
4712            protected MBMessage getByG_U_PrevAndNext(Session session,
4713                    MBMessage mbMessage, long groupId, long userId,
4714                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4715                    StringBundler query = null;
4716    
4717                    if (orderByComparator != null) {
4718                            query = new StringBundler(6 +
4719                                            (orderByComparator.getOrderByFields().length * 6));
4720                    }
4721                    else {
4722                            query = new StringBundler(3);
4723                    }
4724    
4725                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4726    
4727                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4728    
4729                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4730    
4731                    if (orderByComparator != null) {
4732                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4733    
4734                            if (orderByConditionFields.length > 0) {
4735                                    query.append(WHERE_AND);
4736                            }
4737    
4738                            for (int i = 0; i < orderByConditionFields.length; i++) {
4739                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4740                                    query.append(orderByConditionFields[i]);
4741    
4742                                    if ((i + 1) < orderByConditionFields.length) {
4743                                            if (orderByComparator.isAscending() ^ previous) {
4744                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4745                                            }
4746                                            else {
4747                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4748                                            }
4749                                    }
4750                                    else {
4751                                            if (orderByComparator.isAscending() ^ previous) {
4752                                                    query.append(WHERE_GREATER_THAN);
4753                                            }
4754                                            else {
4755                                                    query.append(WHERE_LESSER_THAN);
4756                                            }
4757                                    }
4758                            }
4759    
4760                            query.append(ORDER_BY_CLAUSE);
4761    
4762                            String[] orderByFields = orderByComparator.getOrderByFields();
4763    
4764                            for (int i = 0; i < orderByFields.length; i++) {
4765                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4766                                    query.append(orderByFields[i]);
4767    
4768                                    if ((i + 1) < orderByFields.length) {
4769                                            if (orderByComparator.isAscending() ^ previous) {
4770                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4771                                            }
4772                                            else {
4773                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4774                                            }
4775                                    }
4776                                    else {
4777                                            if (orderByComparator.isAscending() ^ previous) {
4778                                                    query.append(ORDER_BY_ASC);
4779                                            }
4780                                            else {
4781                                                    query.append(ORDER_BY_DESC);
4782                                            }
4783                                    }
4784                            }
4785                    }
4786                    else {
4787                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4788                    }
4789    
4790                    String sql = query.toString();
4791    
4792                    Query q = session.createQuery(sql);
4793    
4794                    q.setFirstResult(0);
4795                    q.setMaxResults(2);
4796    
4797                    QueryPos qPos = QueryPos.getInstance(q);
4798    
4799                    qPos.add(groupId);
4800    
4801                    qPos.add(userId);
4802    
4803                    if (orderByComparator != null) {
4804                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4805    
4806                            for (Object value : values) {
4807                                    qPos.add(value);
4808                            }
4809                    }
4810    
4811                    List<MBMessage> list = q.list();
4812    
4813                    if (list.size() == 2) {
4814                            return list.get(1);
4815                    }
4816                    else {
4817                            return null;
4818                    }
4819            }
4820    
4821            /**
4822             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4823             *
4824             * @param groupId the group ID
4825             * @param userId the user ID
4826             * @return the matching message-boards messages that the user has permission to view
4827             */
4828            @Override
4829            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4830                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4831                            QueryUtil.ALL_POS, null);
4832            }
4833    
4834            /**
4835             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4836             *
4837             * <p>
4838             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4839             * </p>
4840             *
4841             * @param groupId the group ID
4842             * @param userId the user ID
4843             * @param start the lower bound of the range of message-boards messages
4844             * @param end the upper bound of the range of message-boards messages (not inclusive)
4845             * @return the range of matching message-boards messages that the user has permission to view
4846             */
4847            @Override
4848            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4849                    int start, int end) {
4850                    return filterFindByG_U(groupId, userId, start, end, null);
4851            }
4852    
4853            /**
4854             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4855             *
4856             * <p>
4857             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4858             * </p>
4859             *
4860             * @param groupId the group ID
4861             * @param userId the user ID
4862             * @param start the lower bound of the range of message-boards messages
4863             * @param end the upper bound of the range of message-boards messages (not inclusive)
4864             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4865             * @return the ordered range of matching message-boards messages that the user has permission to view
4866             */
4867            @Override
4868            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4869                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4870                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4871                            return findByG_U(groupId, userId, start, end, orderByComparator);
4872                    }
4873    
4874                    StringBundler query = null;
4875    
4876                    if (orderByComparator != null) {
4877                            query = new StringBundler(4 +
4878                                            (orderByComparator.getOrderByFields().length * 3));
4879                    }
4880                    else {
4881                            query = new StringBundler(4);
4882                    }
4883    
4884                    if (getDB().isSupportsInlineDistinct()) {
4885                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4886                    }
4887                    else {
4888                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4889                    }
4890    
4891                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4892    
4893                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4894    
4895                    if (!getDB().isSupportsInlineDistinct()) {
4896                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4897                    }
4898    
4899                    if (orderByComparator != null) {
4900                            if (getDB().isSupportsInlineDistinct()) {
4901                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4902                                            orderByComparator, true);
4903                            }
4904                            else {
4905                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4906                                            orderByComparator, true);
4907                            }
4908                    }
4909                    else {
4910                            if (getDB().isSupportsInlineDistinct()) {
4911                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4912                            }
4913                            else {
4914                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4915                            }
4916                    }
4917    
4918                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4919                                    MBMessage.class.getName(),
4920                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4921    
4922                    Session session = null;
4923    
4924                    try {
4925                            session = openSession();
4926    
4927                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4928    
4929                            if (getDB().isSupportsInlineDistinct()) {
4930                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4931                            }
4932                            else {
4933                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4934                            }
4935    
4936                            QueryPos qPos = QueryPos.getInstance(q);
4937    
4938                            qPos.add(groupId);
4939    
4940                            qPos.add(userId);
4941    
4942                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4943                    }
4944                    catch (Exception e) {
4945                            throw processException(e);
4946                    }
4947                    finally {
4948                            closeSession(session);
4949                    }
4950            }
4951    
4952            /**
4953             * 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;.
4954             *
4955             * @param messageId the primary key of the current message-boards message
4956             * @param groupId the group ID
4957             * @param userId the user ID
4958             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4959             * @return the previous, current, and next message-boards message
4960             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4961             */
4962            @Override
4963            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4964                    long groupId, long userId,
4965                    OrderByComparator<MBMessage> orderByComparator)
4966                    throws NoSuchMessageException {
4967                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4968                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4969                                    orderByComparator);
4970                    }
4971    
4972                    MBMessage mbMessage = findByPrimaryKey(messageId);
4973    
4974                    Session session = null;
4975    
4976                    try {
4977                            session = openSession();
4978    
4979                            MBMessage[] array = new MBMessageImpl[3];
4980    
4981                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4982                                            userId, orderByComparator, true);
4983    
4984                            array[1] = mbMessage;
4985    
4986                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4987                                            userId, orderByComparator, false);
4988    
4989                            return array;
4990                    }
4991                    catch (Exception e) {
4992                            throw processException(e);
4993                    }
4994                    finally {
4995                            closeSession(session);
4996                    }
4997            }
4998    
4999            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5000                    MBMessage mbMessage, long groupId, long userId,
5001                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5002                    StringBundler query = null;
5003    
5004                    if (orderByComparator != null) {
5005                            query = new StringBundler(6 +
5006                                            (orderByComparator.getOrderByFields().length * 6));
5007                    }
5008                    else {
5009                            query = new StringBundler(3);
5010                    }
5011    
5012                    if (getDB().isSupportsInlineDistinct()) {
5013                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5014                    }
5015                    else {
5016                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5017                    }
5018    
5019                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5020    
5021                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5022    
5023                    if (!getDB().isSupportsInlineDistinct()) {
5024                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5025                    }
5026    
5027                    if (orderByComparator != null) {
5028                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5029    
5030                            if (orderByConditionFields.length > 0) {
5031                                    query.append(WHERE_AND);
5032                            }
5033    
5034                            for (int i = 0; i < orderByConditionFields.length; i++) {
5035                                    if (getDB().isSupportsInlineDistinct()) {
5036                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5037                                    }
5038                                    else {
5039                                            query.append(_ORDER_BY_ENTITY_TABLE);
5040                                    }
5041    
5042                                    query.append(orderByConditionFields[i]);
5043    
5044                                    if ((i + 1) < orderByConditionFields.length) {
5045                                            if (orderByComparator.isAscending() ^ previous) {
5046                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5047                                            }
5048                                            else {
5049                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5050                                            }
5051                                    }
5052                                    else {
5053                                            if (orderByComparator.isAscending() ^ previous) {
5054                                                    query.append(WHERE_GREATER_THAN);
5055                                            }
5056                                            else {
5057                                                    query.append(WHERE_LESSER_THAN);
5058                                            }
5059                                    }
5060                            }
5061    
5062                            query.append(ORDER_BY_CLAUSE);
5063    
5064                            String[] orderByFields = orderByComparator.getOrderByFields();
5065    
5066                            for (int i = 0; i < orderByFields.length; i++) {
5067                                    if (getDB().isSupportsInlineDistinct()) {
5068                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5069                                    }
5070                                    else {
5071                                            query.append(_ORDER_BY_ENTITY_TABLE);
5072                                    }
5073    
5074                                    query.append(orderByFields[i]);
5075    
5076                                    if ((i + 1) < orderByFields.length) {
5077                                            if (orderByComparator.isAscending() ^ previous) {
5078                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5079                                            }
5080                                            else {
5081                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5082                                            }
5083                                    }
5084                                    else {
5085                                            if (orderByComparator.isAscending() ^ previous) {
5086                                                    query.append(ORDER_BY_ASC);
5087                                            }
5088                                            else {
5089                                                    query.append(ORDER_BY_DESC);
5090                                            }
5091                                    }
5092                            }
5093                    }
5094                    else {
5095                            if (getDB().isSupportsInlineDistinct()) {
5096                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5097                            }
5098                            else {
5099                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5100                            }
5101                    }
5102    
5103                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5104                                    MBMessage.class.getName(),
5105                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5106    
5107                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5108    
5109                    q.setFirstResult(0);
5110                    q.setMaxResults(2);
5111    
5112                    if (getDB().isSupportsInlineDistinct()) {
5113                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5114                    }
5115                    else {
5116                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5117                    }
5118    
5119                    QueryPos qPos = QueryPos.getInstance(q);
5120    
5121                    qPos.add(groupId);
5122    
5123                    qPos.add(userId);
5124    
5125                    if (orderByComparator != null) {
5126                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5127    
5128                            for (Object value : values) {
5129                                    qPos.add(value);
5130                            }
5131                    }
5132    
5133                    List<MBMessage> list = q.list();
5134    
5135                    if (list.size() == 2) {
5136                            return list.get(1);
5137                    }
5138                    else {
5139                            return null;
5140                    }
5141            }
5142    
5143            /**
5144             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5145             *
5146             * @param groupId the group ID
5147             * @param userId the user ID
5148             */
5149            @Override
5150            public void removeByG_U(long groupId, long userId) {
5151                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5152                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5153                            remove(mbMessage);
5154                    }
5155            }
5156    
5157            /**
5158             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5159             *
5160             * @param groupId the group ID
5161             * @param userId the user ID
5162             * @return the number of matching message-boards messages
5163             */
5164            @Override
5165            public int countByG_U(long groupId, long userId) {
5166                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5167    
5168                    Object[] finderArgs = new Object[] { groupId, userId };
5169    
5170                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5171    
5172                    if (count == null) {
5173                            StringBundler query = new StringBundler(3);
5174    
5175                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5176    
5177                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5178    
5179                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5180    
5181                            String sql = query.toString();
5182    
5183                            Session session = null;
5184    
5185                            try {
5186                                    session = openSession();
5187    
5188                                    Query q = session.createQuery(sql);
5189    
5190                                    QueryPos qPos = QueryPos.getInstance(q);
5191    
5192                                    qPos.add(groupId);
5193    
5194                                    qPos.add(userId);
5195    
5196                                    count = (Long)q.uniqueResult();
5197    
5198                                    finderCache.putResult(finderPath, finderArgs, count);
5199                            }
5200                            catch (Exception e) {
5201                                    finderCache.removeResult(finderPath, finderArgs);
5202    
5203                                    throw processException(e);
5204                            }
5205                            finally {
5206                                    closeSession(session);
5207                            }
5208                    }
5209    
5210                    return count.intValue();
5211            }
5212    
5213            /**
5214             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5215             *
5216             * @param groupId the group ID
5217             * @param userId the user ID
5218             * @return the number of matching message-boards messages that the user has permission to view
5219             */
5220            @Override
5221            public int filterCountByG_U(long groupId, long userId) {
5222                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5223                            return countByG_U(groupId, userId);
5224                    }
5225    
5226                    StringBundler query = new StringBundler(3);
5227    
5228                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5229    
5230                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5231    
5232                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5233    
5234                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5235                                    MBMessage.class.getName(),
5236                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5237    
5238                    Session session = null;
5239    
5240                    try {
5241                            session = openSession();
5242    
5243                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5244    
5245                            q.addScalar(COUNT_COLUMN_NAME,
5246                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5247    
5248                            QueryPos qPos = QueryPos.getInstance(q);
5249    
5250                            qPos.add(groupId);
5251    
5252                            qPos.add(userId);
5253    
5254                            Long count = (Long)q.uniqueResult();
5255    
5256                            return count.intValue();
5257                    }
5258                    catch (Exception e) {
5259                            throw processException(e);
5260                    }
5261                    finally {
5262                            closeSession(session);
5263                    }
5264            }
5265    
5266            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5267            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5268            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5269                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5270                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5271                            new String[] {
5272                                    Long.class.getName(), Long.class.getName(),
5273                                    
5274                            Integer.class.getName(), Integer.class.getName(),
5275                                    OrderByComparator.class.getName()
5276                            });
5277            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5278                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5279                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5280                            new String[] { Long.class.getName(), Long.class.getName() },
5281                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5282                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5283                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5284            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5285                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5286                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5287                            new String[] { Long.class.getName(), Long.class.getName() });
5288    
5289            /**
5290             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5291             *
5292             * @param groupId the group ID
5293             * @param categoryId the category ID
5294             * @return the matching message-boards messages
5295             */
5296            @Override
5297            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5298                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5299                            QueryUtil.ALL_POS, null);
5300            }
5301    
5302            /**
5303             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5304             *
5305             * <p>
5306             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5307             * </p>
5308             *
5309             * @param groupId the group ID
5310             * @param categoryId the category ID
5311             * @param start the lower bound of the range of message-boards messages
5312             * @param end the upper bound of the range of message-boards messages (not inclusive)
5313             * @return the range of matching message-boards messages
5314             */
5315            @Override
5316            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5317                    int end) {
5318                    return findByG_C(groupId, categoryId, start, end, null);
5319            }
5320    
5321            /**
5322             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5323             *
5324             * <p>
5325             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5326             * </p>
5327             *
5328             * @param groupId the group ID
5329             * @param categoryId the category ID
5330             * @param start the lower bound of the range of message-boards messages
5331             * @param end the upper bound of the range of message-boards messages (not inclusive)
5332             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5333             * @return the ordered range of matching message-boards messages
5334             */
5335            @Override
5336            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5337                    int end, OrderByComparator<MBMessage> orderByComparator) {
5338                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
5339                            true);
5340            }
5341    
5342            /**
5343             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5344             *
5345             * <p>
5346             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5347             * </p>
5348             *
5349             * @param groupId the group ID
5350             * @param categoryId the category ID
5351             * @param start the lower bound of the range of message-boards messages
5352             * @param end the upper bound of the range of message-boards messages (not inclusive)
5353             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5354             * @param retrieveFromCache whether to retrieve from the finder cache
5355             * @return the ordered range of matching message-boards messages
5356             */
5357            @Override
5358            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5359                    int end, OrderByComparator<MBMessage> orderByComparator,
5360                    boolean retrieveFromCache) {
5361                    boolean pagination = true;
5362                    FinderPath finderPath = null;
5363                    Object[] finderArgs = null;
5364    
5365                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5366                                    (orderByComparator == null)) {
5367                            pagination = false;
5368                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5369                            finderArgs = new Object[] { groupId, categoryId };
5370                    }
5371                    else {
5372                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5373                            finderArgs = new Object[] {
5374                                            groupId, categoryId,
5375                                            
5376                                            start, end, orderByComparator
5377                                    };
5378                    }
5379    
5380                    List<MBMessage> list = null;
5381    
5382                    if (retrieveFromCache) {
5383                            list = (List<MBMessage>)finderCache.getResult(finderPath,
5384                                            finderArgs, this);
5385    
5386                            if ((list != null) && !list.isEmpty()) {
5387                                    for (MBMessage mbMessage : list) {
5388                                            if ((groupId != mbMessage.getGroupId()) ||
5389                                                            (categoryId != mbMessage.getCategoryId())) {
5390                                                    list = null;
5391    
5392                                                    break;
5393                                            }
5394                                    }
5395                            }
5396                    }
5397    
5398                    if (list == null) {
5399                            StringBundler query = null;
5400    
5401                            if (orderByComparator != null) {
5402                                    query = new StringBundler(4 +
5403                                                    (orderByComparator.getOrderByFields().length * 3));
5404                            }
5405                            else {
5406                                    query = new StringBundler(4);
5407                            }
5408    
5409                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5410    
5411                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5412    
5413                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5414    
5415                            if (orderByComparator != null) {
5416                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5417                                            orderByComparator);
5418                            }
5419                            else
5420                             if (pagination) {
5421                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5422                            }
5423    
5424                            String sql = query.toString();
5425    
5426                            Session session = null;
5427    
5428                            try {
5429                                    session = openSession();
5430    
5431                                    Query q = session.createQuery(sql);
5432    
5433                                    QueryPos qPos = QueryPos.getInstance(q);
5434    
5435                                    qPos.add(groupId);
5436    
5437                                    qPos.add(categoryId);
5438    
5439                                    if (!pagination) {
5440                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5441                                                            start, end, false);
5442    
5443                                            Collections.sort(list);
5444    
5445                                            list = Collections.unmodifiableList(list);
5446                                    }
5447                                    else {
5448                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5449                                                            start, end);
5450                                    }
5451    
5452                                    cacheResult(list);
5453    
5454                                    finderCache.putResult(finderPath, finderArgs, list);
5455                            }
5456                            catch (Exception e) {
5457                                    finderCache.removeResult(finderPath, finderArgs);
5458    
5459                                    throw processException(e);
5460                            }
5461                            finally {
5462                                    closeSession(session);
5463                            }
5464                    }
5465    
5466                    return list;
5467            }
5468    
5469            /**
5470             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5471             *
5472             * @param groupId the group ID
5473             * @param categoryId the category ID
5474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5475             * @return the first matching message-boards message
5476             * @throws NoSuchMessageException if a matching message-boards message could not be found
5477             */
5478            @Override
5479            public MBMessage findByG_C_First(long groupId, long categoryId,
5480                    OrderByComparator<MBMessage> orderByComparator)
5481                    throws NoSuchMessageException {
5482                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5483                                    orderByComparator);
5484    
5485                    if (mbMessage != null) {
5486                            return mbMessage;
5487                    }
5488    
5489                    StringBundler msg = new StringBundler(6);
5490    
5491                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5492    
5493                    msg.append("groupId=");
5494                    msg.append(groupId);
5495    
5496                    msg.append(", categoryId=");
5497                    msg.append(categoryId);
5498    
5499                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5500    
5501                    throw new NoSuchMessageException(msg.toString());
5502            }
5503    
5504            /**
5505             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5506             *
5507             * @param groupId the group ID
5508             * @param categoryId the category ID
5509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5510             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5511             */
5512            @Override
5513            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5514                    OrderByComparator<MBMessage> orderByComparator) {
5515                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5516                                    orderByComparator);
5517    
5518                    if (!list.isEmpty()) {
5519                            return list.get(0);
5520                    }
5521    
5522                    return null;
5523            }
5524    
5525            /**
5526             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5527             *
5528             * @param groupId the group ID
5529             * @param categoryId the category ID
5530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5531             * @return the last matching message-boards message
5532             * @throws NoSuchMessageException if a matching message-boards message could not be found
5533             */
5534            @Override
5535            public MBMessage findByG_C_Last(long groupId, long categoryId,
5536                    OrderByComparator<MBMessage> orderByComparator)
5537                    throws NoSuchMessageException {
5538                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5539                                    orderByComparator);
5540    
5541                    if (mbMessage != null) {
5542                            return mbMessage;
5543                    }
5544    
5545                    StringBundler msg = new StringBundler(6);
5546    
5547                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5548    
5549                    msg.append("groupId=");
5550                    msg.append(groupId);
5551    
5552                    msg.append(", categoryId=");
5553                    msg.append(categoryId);
5554    
5555                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5556    
5557                    throw new NoSuchMessageException(msg.toString());
5558            }
5559    
5560            /**
5561             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5562             *
5563             * @param groupId the group ID
5564             * @param categoryId the category ID
5565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5566             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5567             */
5568            @Override
5569            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5570                    OrderByComparator<MBMessage> orderByComparator) {
5571                    int count = countByG_C(groupId, categoryId);
5572    
5573                    if (count == 0) {
5574                            return null;
5575                    }
5576    
5577                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5578                                    orderByComparator);
5579    
5580                    if (!list.isEmpty()) {
5581                            return list.get(0);
5582                    }
5583    
5584                    return null;
5585            }
5586    
5587            /**
5588             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5589             *
5590             * @param messageId the primary key of the current message-boards message
5591             * @param groupId the group ID
5592             * @param categoryId the category ID
5593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5594             * @return the previous, current, and next message-boards message
5595             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5596             */
5597            @Override
5598            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5599                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5600                    throws NoSuchMessageException {
5601                    MBMessage mbMessage = findByPrimaryKey(messageId);
5602    
5603                    Session session = null;
5604    
5605                    try {
5606                            session = openSession();
5607    
5608                            MBMessage[] array = new MBMessageImpl[3];
5609    
5610                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5611                                            categoryId, orderByComparator, true);
5612    
5613                            array[1] = mbMessage;
5614    
5615                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5616                                            categoryId, orderByComparator, false);
5617    
5618                            return array;
5619                    }
5620                    catch (Exception e) {
5621                            throw processException(e);
5622                    }
5623                    finally {
5624                            closeSession(session);
5625                    }
5626            }
5627    
5628            protected MBMessage getByG_C_PrevAndNext(Session session,
5629                    MBMessage mbMessage, long groupId, long categoryId,
5630                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5631                    StringBundler query = null;
5632    
5633                    if (orderByComparator != null) {
5634                            query = new StringBundler(6 +
5635                                            (orderByComparator.getOrderByFields().length * 6));
5636                    }
5637                    else {
5638                            query = new StringBundler(3);
5639                    }
5640    
5641                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5642    
5643                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5644    
5645                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5646    
5647                    if (orderByComparator != null) {
5648                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5649    
5650                            if (orderByConditionFields.length > 0) {
5651                                    query.append(WHERE_AND);
5652                            }
5653    
5654                            for (int i = 0; i < orderByConditionFields.length; i++) {
5655                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5656                                    query.append(orderByConditionFields[i]);
5657    
5658                                    if ((i + 1) < orderByConditionFields.length) {
5659                                            if (orderByComparator.isAscending() ^ previous) {
5660                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5661                                            }
5662                                            else {
5663                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5664                                            }
5665                                    }
5666                                    else {
5667                                            if (orderByComparator.isAscending() ^ previous) {
5668                                                    query.append(WHERE_GREATER_THAN);
5669                                            }
5670                                            else {
5671                                                    query.append(WHERE_LESSER_THAN);
5672                                            }
5673                                    }
5674                            }
5675    
5676                            query.append(ORDER_BY_CLAUSE);
5677    
5678                            String[] orderByFields = orderByComparator.getOrderByFields();
5679    
5680                            for (int i = 0; i < orderByFields.length; i++) {
5681                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5682                                    query.append(orderByFields[i]);
5683    
5684                                    if ((i + 1) < orderByFields.length) {
5685                                            if (orderByComparator.isAscending() ^ previous) {
5686                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5687                                            }
5688                                            else {
5689                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5690                                            }
5691                                    }
5692                                    else {
5693                                            if (orderByComparator.isAscending() ^ previous) {
5694                                                    query.append(ORDER_BY_ASC);
5695                                            }
5696                                            else {
5697                                                    query.append(ORDER_BY_DESC);
5698                                            }
5699                                    }
5700                            }
5701                    }
5702                    else {
5703                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5704                    }
5705    
5706                    String sql = query.toString();
5707    
5708                    Query q = session.createQuery(sql);
5709    
5710                    q.setFirstResult(0);
5711                    q.setMaxResults(2);
5712    
5713                    QueryPos qPos = QueryPos.getInstance(q);
5714    
5715                    qPos.add(groupId);
5716    
5717                    qPos.add(categoryId);
5718    
5719                    if (orderByComparator != null) {
5720                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5721    
5722                            for (Object value : values) {
5723                                    qPos.add(value);
5724                            }
5725                    }
5726    
5727                    List<MBMessage> list = q.list();
5728    
5729                    if (list.size() == 2) {
5730                            return list.get(1);
5731                    }
5732                    else {
5733                            return null;
5734                    }
5735            }
5736    
5737            /**
5738             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5739             *
5740             * @param groupId the group ID
5741             * @param categoryId the category ID
5742             * @return the matching message-boards messages that the user has permission to view
5743             */
5744            @Override
5745            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5746                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5747                            QueryUtil.ALL_POS, null);
5748            }
5749    
5750            /**
5751             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5752             *
5753             * <p>
5754             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5755             * </p>
5756             *
5757             * @param groupId the group ID
5758             * @param categoryId the category ID
5759             * @param start the lower bound of the range of message-boards messages
5760             * @param end the upper bound of the range of message-boards messages (not inclusive)
5761             * @return the range of matching message-boards messages that the user has permission to view
5762             */
5763            @Override
5764            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5765                    int start, int end) {
5766                    return filterFindByG_C(groupId, categoryId, start, end, null);
5767            }
5768    
5769            /**
5770             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5771             *
5772             * <p>
5773             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5774             * </p>
5775             *
5776             * @param groupId the group ID
5777             * @param categoryId the category ID
5778             * @param start the lower bound of the range of message-boards messages
5779             * @param end the upper bound of the range of message-boards messages (not inclusive)
5780             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5781             * @return the ordered range of matching message-boards messages that the user has permission to view
5782             */
5783            @Override
5784            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5785                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5786                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5787                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5788                    }
5789    
5790                    StringBundler query = null;
5791    
5792                    if (orderByComparator != null) {
5793                            query = new StringBundler(4 +
5794                                            (orderByComparator.getOrderByFields().length * 3));
5795                    }
5796                    else {
5797                            query = new StringBundler(4);
5798                    }
5799    
5800                    if (getDB().isSupportsInlineDistinct()) {
5801                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5802                    }
5803                    else {
5804                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5805                    }
5806    
5807                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5808    
5809                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5810    
5811                    if (!getDB().isSupportsInlineDistinct()) {
5812                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5813                    }
5814    
5815                    if (orderByComparator != null) {
5816                            if (getDB().isSupportsInlineDistinct()) {
5817                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5818                                            orderByComparator, true);
5819                            }
5820                            else {
5821                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5822                                            orderByComparator, true);
5823                            }
5824                    }
5825                    else {
5826                            if (getDB().isSupportsInlineDistinct()) {
5827                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5828                            }
5829                            else {
5830                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5831                            }
5832                    }
5833    
5834                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5835                                    MBMessage.class.getName(),
5836                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5837    
5838                    Session session = null;
5839    
5840                    try {
5841                            session = openSession();
5842    
5843                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5844    
5845                            if (getDB().isSupportsInlineDistinct()) {
5846                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5847                            }
5848                            else {
5849                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5850                            }
5851    
5852                            QueryPos qPos = QueryPos.getInstance(q);
5853    
5854                            qPos.add(groupId);
5855    
5856                            qPos.add(categoryId);
5857    
5858                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5859                    }
5860                    catch (Exception e) {
5861                            throw processException(e);
5862                    }
5863                    finally {
5864                            closeSession(session);
5865                    }
5866            }
5867    
5868            /**
5869             * 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;.
5870             *
5871             * @param messageId the primary key of the current message-boards message
5872             * @param groupId the group ID
5873             * @param categoryId the category ID
5874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5875             * @return the previous, current, and next message-boards message
5876             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5877             */
5878            @Override
5879            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5880                    long groupId, long categoryId,
5881                    OrderByComparator<MBMessage> orderByComparator)
5882                    throws NoSuchMessageException {
5883                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5884                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5885                                    orderByComparator);
5886                    }
5887    
5888                    MBMessage mbMessage = findByPrimaryKey(messageId);
5889    
5890                    Session session = null;
5891    
5892                    try {
5893                            session = openSession();
5894    
5895                            MBMessage[] array = new MBMessageImpl[3];
5896    
5897                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5898                                            categoryId, orderByComparator, true);
5899    
5900                            array[1] = mbMessage;
5901    
5902                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5903                                            categoryId, orderByComparator, false);
5904    
5905                            return array;
5906                    }
5907                    catch (Exception e) {
5908                            throw processException(e);
5909                    }
5910                    finally {
5911                            closeSession(session);
5912                    }
5913            }
5914    
5915            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5916                    MBMessage mbMessage, long groupId, long categoryId,
5917                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5918                    StringBundler query = null;
5919    
5920                    if (orderByComparator != null) {
5921                            query = new StringBundler(6 +
5922                                            (orderByComparator.getOrderByFields().length * 6));
5923                    }
5924                    else {
5925                            query = new StringBundler(3);
5926                    }
5927    
5928                    if (getDB().isSupportsInlineDistinct()) {
5929                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5930                    }
5931                    else {
5932                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5933                    }
5934    
5935                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5936    
5937                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5938    
5939                    if (!getDB().isSupportsInlineDistinct()) {
5940                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5941                    }
5942    
5943                    if (orderByComparator != null) {
5944                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5945    
5946                            if (orderByConditionFields.length > 0) {
5947                                    query.append(WHERE_AND);
5948                            }
5949    
5950                            for (int i = 0; i < orderByConditionFields.length; i++) {
5951                                    if (getDB().isSupportsInlineDistinct()) {
5952                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5953                                    }
5954                                    else {
5955                                            query.append(_ORDER_BY_ENTITY_TABLE);
5956                                    }
5957    
5958                                    query.append(orderByConditionFields[i]);
5959    
5960                                    if ((i + 1) < orderByConditionFields.length) {
5961                                            if (orderByComparator.isAscending() ^ previous) {
5962                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5963                                            }
5964                                            else {
5965                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5966                                            }
5967                                    }
5968                                    else {
5969                                            if (orderByComparator.isAscending() ^ previous) {
5970                                                    query.append(WHERE_GREATER_THAN);
5971                                            }
5972                                            else {
5973                                                    query.append(WHERE_LESSER_THAN);
5974                                            }
5975                                    }
5976                            }
5977    
5978                            query.append(ORDER_BY_CLAUSE);
5979    
5980                            String[] orderByFields = orderByComparator.getOrderByFields();
5981    
5982                            for (int i = 0; i < orderByFields.length; i++) {
5983                                    if (getDB().isSupportsInlineDistinct()) {
5984                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5985                                    }
5986                                    else {
5987                                            query.append(_ORDER_BY_ENTITY_TABLE);
5988                                    }
5989    
5990                                    query.append(orderByFields[i]);
5991    
5992                                    if ((i + 1) < orderByFields.length) {
5993                                            if (orderByComparator.isAscending() ^ previous) {
5994                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5995                                            }
5996                                            else {
5997                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5998                                            }
5999                                    }
6000                                    else {
6001                                            if (orderByComparator.isAscending() ^ previous) {
6002                                                    query.append(ORDER_BY_ASC);
6003                                            }
6004                                            else {
6005                                                    query.append(ORDER_BY_DESC);
6006                                            }
6007                                    }
6008                            }
6009                    }
6010                    else {
6011                            if (getDB().isSupportsInlineDistinct()) {
6012                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6013                            }
6014                            else {
6015                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6016                            }
6017                    }
6018    
6019                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6020                                    MBMessage.class.getName(),
6021                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6022    
6023                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6024    
6025                    q.setFirstResult(0);
6026                    q.setMaxResults(2);
6027    
6028                    if (getDB().isSupportsInlineDistinct()) {
6029                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6030                    }
6031                    else {
6032                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6033                    }
6034    
6035                    QueryPos qPos = QueryPos.getInstance(q);
6036    
6037                    qPos.add(groupId);
6038    
6039                    qPos.add(categoryId);
6040    
6041                    if (orderByComparator != null) {
6042                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6043    
6044                            for (Object value : values) {
6045                                    qPos.add(value);
6046                            }
6047                    }
6048    
6049                    List<MBMessage> list = q.list();
6050    
6051                    if (list.size() == 2) {
6052                            return list.get(1);
6053                    }
6054                    else {
6055                            return null;
6056                    }
6057            }
6058    
6059            /**
6060             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
6061             *
6062             * @param groupId the group ID
6063             * @param categoryId the category ID
6064             */
6065            @Override
6066            public void removeByG_C(long groupId, long categoryId) {
6067                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
6068                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6069                            remove(mbMessage);
6070                    }
6071            }
6072    
6073            /**
6074             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
6075             *
6076             * @param groupId the group ID
6077             * @param categoryId the category ID
6078             * @return the number of matching message-boards messages
6079             */
6080            @Override
6081            public int countByG_C(long groupId, long categoryId) {
6082                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6083    
6084                    Object[] finderArgs = new Object[] { groupId, categoryId };
6085    
6086                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6087    
6088                    if (count == null) {
6089                            StringBundler query = new StringBundler(3);
6090    
6091                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6092    
6093                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6094    
6095                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6096    
6097                            String sql = query.toString();
6098    
6099                            Session session = null;
6100    
6101                            try {
6102                                    session = openSession();
6103    
6104                                    Query q = session.createQuery(sql);
6105    
6106                                    QueryPos qPos = QueryPos.getInstance(q);
6107    
6108                                    qPos.add(groupId);
6109    
6110                                    qPos.add(categoryId);
6111    
6112                                    count = (Long)q.uniqueResult();
6113    
6114                                    finderCache.putResult(finderPath, finderArgs, count);
6115                            }
6116                            catch (Exception e) {
6117                                    finderCache.removeResult(finderPath, finderArgs);
6118    
6119                                    throw processException(e);
6120                            }
6121                            finally {
6122                                    closeSession(session);
6123                            }
6124                    }
6125    
6126                    return count.intValue();
6127            }
6128    
6129            /**
6130             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6131             *
6132             * @param groupId the group ID
6133             * @param categoryId the category ID
6134             * @return the number of matching message-boards messages that the user has permission to view
6135             */
6136            @Override
6137            public int filterCountByG_C(long groupId, long categoryId) {
6138                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6139                            return countByG_C(groupId, categoryId);
6140                    }
6141    
6142                    StringBundler query = new StringBundler(3);
6143    
6144                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6145    
6146                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6147    
6148                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6149    
6150                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6151                                    MBMessage.class.getName(),
6152                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6153    
6154                    Session session = null;
6155    
6156                    try {
6157                            session = openSession();
6158    
6159                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6160    
6161                            q.addScalar(COUNT_COLUMN_NAME,
6162                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6163    
6164                            QueryPos qPos = QueryPos.getInstance(q);
6165    
6166                            qPos.add(groupId);
6167    
6168                            qPos.add(categoryId);
6169    
6170                            Long count = (Long)q.uniqueResult();
6171    
6172                            return count.intValue();
6173                    }
6174                    catch (Exception e) {
6175                            throw processException(e);
6176                    }
6177                    finally {
6178                            closeSession(session);
6179                    }
6180            }
6181    
6182            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6183            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6184            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6186                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6187                            new String[] {
6188                                    Long.class.getName(), Integer.class.getName(),
6189                                    
6190                            Integer.class.getName(), Integer.class.getName(),
6191                                    OrderByComparator.class.getName()
6192                            });
6193            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6194                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6195                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6196                            new String[] { Long.class.getName(), Integer.class.getName() },
6197                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6198                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6199                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6200            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6201                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6202                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6203                            new String[] { Long.class.getName(), Integer.class.getName() });
6204    
6205            /**
6206             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6207             *
6208             * @param groupId the group ID
6209             * @param status the status
6210             * @return the matching message-boards messages
6211             */
6212            @Override
6213            public List<MBMessage> findByG_S(long groupId, int status) {
6214                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6215                            null);
6216            }
6217    
6218            /**
6219             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6220             *
6221             * <p>
6222             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6223             * </p>
6224             *
6225             * @param groupId the group ID
6226             * @param status the status
6227             * @param start the lower bound of the range of message-boards messages
6228             * @param end the upper bound of the range of message-boards messages (not inclusive)
6229             * @return the range of matching message-boards messages
6230             */
6231            @Override
6232            public List<MBMessage> findByG_S(long groupId, int status, int start,
6233                    int end) {
6234                    return findByG_S(groupId, status, start, end, null);
6235            }
6236    
6237            /**
6238             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6239             *
6240             * <p>
6241             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6242             * </p>
6243             *
6244             * @param groupId the group ID
6245             * @param status the status
6246             * @param start the lower bound of the range of message-boards messages
6247             * @param end the upper bound of the range of message-boards messages (not inclusive)
6248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6249             * @return the ordered range of matching message-boards messages
6250             */
6251            @Override
6252            public List<MBMessage> findByG_S(long groupId, int status, int start,
6253                    int end, OrderByComparator<MBMessage> orderByComparator) {
6254                    return findByG_S(groupId, status, start, end, orderByComparator, true);
6255            }
6256    
6257            /**
6258             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6259             *
6260             * <p>
6261             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6262             * </p>
6263             *
6264             * @param groupId the group ID
6265             * @param status the status
6266             * @param start the lower bound of the range of message-boards messages
6267             * @param end the upper bound of the range of message-boards messages (not inclusive)
6268             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6269             * @param retrieveFromCache whether to retrieve from the finder cache
6270             * @return the ordered range of matching message-boards messages
6271             */
6272            @Override
6273            public List<MBMessage> findByG_S(long groupId, int status, int start,
6274                    int end, OrderByComparator<MBMessage> orderByComparator,
6275                    boolean retrieveFromCache) {
6276                    boolean pagination = true;
6277                    FinderPath finderPath = null;
6278                    Object[] finderArgs = null;
6279    
6280                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6281                                    (orderByComparator == null)) {
6282                            pagination = false;
6283                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6284                            finderArgs = new Object[] { groupId, status };
6285                    }
6286                    else {
6287                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6288                            finderArgs = new Object[] {
6289                                            groupId, status,
6290                                            
6291                                            start, end, orderByComparator
6292                                    };
6293                    }
6294    
6295                    List<MBMessage> list = null;
6296    
6297                    if (retrieveFromCache) {
6298                            list = (List<MBMessage>)finderCache.getResult(finderPath,
6299                                            finderArgs, this);
6300    
6301                            if ((list != null) && !list.isEmpty()) {
6302                                    for (MBMessage mbMessage : list) {
6303                                            if ((groupId != mbMessage.getGroupId()) ||
6304                                                            (status != mbMessage.getStatus())) {
6305                                                    list = null;
6306    
6307                                                    break;
6308                                            }
6309                                    }
6310                            }
6311                    }
6312    
6313                    if (list == null) {
6314                            StringBundler query = null;
6315    
6316                            if (orderByComparator != null) {
6317                                    query = new StringBundler(4 +
6318                                                    (orderByComparator.getOrderByFields().length * 3));
6319                            }
6320                            else {
6321                                    query = new StringBundler(4);
6322                            }
6323    
6324                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6325    
6326                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6327    
6328                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6329    
6330                            if (orderByComparator != null) {
6331                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6332                                            orderByComparator);
6333                            }
6334                            else
6335                             if (pagination) {
6336                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6337                            }
6338    
6339                            String sql = query.toString();
6340    
6341                            Session session = null;
6342    
6343                            try {
6344                                    session = openSession();
6345    
6346                                    Query q = session.createQuery(sql);
6347    
6348                                    QueryPos qPos = QueryPos.getInstance(q);
6349    
6350                                    qPos.add(groupId);
6351    
6352                                    qPos.add(status);
6353    
6354                                    if (!pagination) {
6355                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6356                                                            start, end, false);
6357    
6358                                            Collections.sort(list);
6359    
6360                                            list = Collections.unmodifiableList(list);
6361                                    }
6362                                    else {
6363                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6364                                                            start, end);
6365                                    }
6366    
6367                                    cacheResult(list);
6368    
6369                                    finderCache.putResult(finderPath, finderArgs, list);
6370                            }
6371                            catch (Exception e) {
6372                                    finderCache.removeResult(finderPath, finderArgs);
6373    
6374                                    throw processException(e);
6375                            }
6376                            finally {
6377                                    closeSession(session);
6378                            }
6379                    }
6380    
6381                    return list;
6382            }
6383    
6384            /**
6385             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6386             *
6387             * @param groupId the group ID
6388             * @param status the status
6389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6390             * @return the first matching message-boards message
6391             * @throws NoSuchMessageException if a matching message-boards message could not be found
6392             */
6393            @Override
6394            public MBMessage findByG_S_First(long groupId, int status,
6395                    OrderByComparator<MBMessage> orderByComparator)
6396                    throws NoSuchMessageException {
6397                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6398                                    orderByComparator);
6399    
6400                    if (mbMessage != null) {
6401                            return mbMessage;
6402                    }
6403    
6404                    StringBundler msg = new StringBundler(6);
6405    
6406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6407    
6408                    msg.append("groupId=");
6409                    msg.append(groupId);
6410    
6411                    msg.append(", status=");
6412                    msg.append(status);
6413    
6414                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6415    
6416                    throw new NoSuchMessageException(msg.toString());
6417            }
6418    
6419            /**
6420             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6421             *
6422             * @param groupId the group ID
6423             * @param status the status
6424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6425             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6426             */
6427            @Override
6428            public MBMessage fetchByG_S_First(long groupId, int status,
6429                    OrderByComparator<MBMessage> orderByComparator) {
6430                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6431                                    orderByComparator);
6432    
6433                    if (!list.isEmpty()) {
6434                            return list.get(0);
6435                    }
6436    
6437                    return null;
6438            }
6439    
6440            /**
6441             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6442             *
6443             * @param groupId the group ID
6444             * @param status the status
6445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6446             * @return the last matching message-boards message
6447             * @throws NoSuchMessageException if a matching message-boards message could not be found
6448             */
6449            @Override
6450            public MBMessage findByG_S_Last(long groupId, int status,
6451                    OrderByComparator<MBMessage> orderByComparator)
6452                    throws NoSuchMessageException {
6453                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6454    
6455                    if (mbMessage != null) {
6456                            return mbMessage;
6457                    }
6458    
6459                    StringBundler msg = new StringBundler(6);
6460    
6461                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6462    
6463                    msg.append("groupId=");
6464                    msg.append(groupId);
6465    
6466                    msg.append(", status=");
6467                    msg.append(status);
6468    
6469                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6470    
6471                    throw new NoSuchMessageException(msg.toString());
6472            }
6473    
6474            /**
6475             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6476             *
6477             * @param groupId the group ID
6478             * @param status the status
6479             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6480             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6481             */
6482            @Override
6483            public MBMessage fetchByG_S_Last(long groupId, int status,
6484                    OrderByComparator<MBMessage> orderByComparator) {
6485                    int count = countByG_S(groupId, status);
6486    
6487                    if (count == 0) {
6488                            return null;
6489                    }
6490    
6491                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6492                                    orderByComparator);
6493    
6494                    if (!list.isEmpty()) {
6495                            return list.get(0);
6496                    }
6497    
6498                    return null;
6499            }
6500    
6501            /**
6502             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6503             *
6504             * @param messageId the primary key of the current message-boards message
6505             * @param groupId the group ID
6506             * @param status the status
6507             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6508             * @return the previous, current, and next message-boards message
6509             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6510             */
6511            @Override
6512            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6513                    int status, OrderByComparator<MBMessage> orderByComparator)
6514                    throws NoSuchMessageException {
6515                    MBMessage mbMessage = findByPrimaryKey(messageId);
6516    
6517                    Session session = null;
6518    
6519                    try {
6520                            session = openSession();
6521    
6522                            MBMessage[] array = new MBMessageImpl[3];
6523    
6524                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6525                                            status, orderByComparator, true);
6526    
6527                            array[1] = mbMessage;
6528    
6529                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6530                                            status, orderByComparator, false);
6531    
6532                            return array;
6533                    }
6534                    catch (Exception e) {
6535                            throw processException(e);
6536                    }
6537                    finally {
6538                            closeSession(session);
6539                    }
6540            }
6541    
6542            protected MBMessage getByG_S_PrevAndNext(Session session,
6543                    MBMessage mbMessage, long groupId, int status,
6544                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6545                    StringBundler query = null;
6546    
6547                    if (orderByComparator != null) {
6548                            query = new StringBundler(6 +
6549                                            (orderByComparator.getOrderByFields().length * 6));
6550                    }
6551                    else {
6552                            query = new StringBundler(3);
6553                    }
6554    
6555                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6556    
6557                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6558    
6559                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6560    
6561                    if (orderByComparator != null) {
6562                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6563    
6564                            if (orderByConditionFields.length > 0) {
6565                                    query.append(WHERE_AND);
6566                            }
6567    
6568                            for (int i = 0; i < orderByConditionFields.length; i++) {
6569                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6570                                    query.append(orderByConditionFields[i]);
6571    
6572                                    if ((i + 1) < orderByConditionFields.length) {
6573                                            if (orderByComparator.isAscending() ^ previous) {
6574                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6575                                            }
6576                                            else {
6577                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6578                                            }
6579                                    }
6580                                    else {
6581                                            if (orderByComparator.isAscending() ^ previous) {
6582                                                    query.append(WHERE_GREATER_THAN);
6583                                            }
6584                                            else {
6585                                                    query.append(WHERE_LESSER_THAN);
6586                                            }
6587                                    }
6588                            }
6589    
6590                            query.append(ORDER_BY_CLAUSE);
6591    
6592                            String[] orderByFields = orderByComparator.getOrderByFields();
6593    
6594                            for (int i = 0; i < orderByFields.length; i++) {
6595                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6596                                    query.append(orderByFields[i]);
6597    
6598                                    if ((i + 1) < orderByFields.length) {
6599                                            if (orderByComparator.isAscending() ^ previous) {
6600                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6601                                            }
6602                                            else {
6603                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6604                                            }
6605                                    }
6606                                    else {
6607                                            if (orderByComparator.isAscending() ^ previous) {
6608                                                    query.append(ORDER_BY_ASC);
6609                                            }
6610                                            else {
6611                                                    query.append(ORDER_BY_DESC);
6612                                            }
6613                                    }
6614                            }
6615                    }
6616                    else {
6617                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6618                    }
6619    
6620                    String sql = query.toString();
6621    
6622                    Query q = session.createQuery(sql);
6623    
6624                    q.setFirstResult(0);
6625                    q.setMaxResults(2);
6626    
6627                    QueryPos qPos = QueryPos.getInstance(q);
6628    
6629                    qPos.add(groupId);
6630    
6631                    qPos.add(status);
6632    
6633                    if (orderByComparator != null) {
6634                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6635    
6636                            for (Object value : values) {
6637                                    qPos.add(value);
6638                            }
6639                    }
6640    
6641                    List<MBMessage> list = q.list();
6642    
6643                    if (list.size() == 2) {
6644                            return list.get(1);
6645                    }
6646                    else {
6647                            return null;
6648                    }
6649            }
6650    
6651            /**
6652             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6653             *
6654             * @param groupId the group ID
6655             * @param status the status
6656             * @return the matching message-boards messages that the user has permission to view
6657             */
6658            @Override
6659            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6660                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6661                            QueryUtil.ALL_POS, null);
6662            }
6663    
6664            /**
6665             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6666             *
6667             * <p>
6668             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6669             * </p>
6670             *
6671             * @param groupId the group ID
6672             * @param status the status
6673             * @param start the lower bound of the range of message-boards messages
6674             * @param end the upper bound of the range of message-boards messages (not inclusive)
6675             * @return the range of matching message-boards messages that the user has permission to view
6676             */
6677            @Override
6678            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6679                    int end) {
6680                    return filterFindByG_S(groupId, status, start, end, null);
6681            }
6682    
6683            /**
6684             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6685             *
6686             * <p>
6687             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6688             * </p>
6689             *
6690             * @param groupId the group ID
6691             * @param status the status
6692             * @param start the lower bound of the range of message-boards messages
6693             * @param end the upper bound of the range of message-boards messages (not inclusive)
6694             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6695             * @return the ordered range of matching message-boards messages that the user has permission to view
6696             */
6697            @Override
6698            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6699                    int end, OrderByComparator<MBMessage> orderByComparator) {
6700                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6701                            return findByG_S(groupId, status, start, end, orderByComparator);
6702                    }
6703    
6704                    StringBundler query = null;
6705    
6706                    if (orderByComparator != null) {
6707                            query = new StringBundler(4 +
6708                                            (orderByComparator.getOrderByFields().length * 3));
6709                    }
6710                    else {
6711                            query = new StringBundler(4);
6712                    }
6713    
6714                    if (getDB().isSupportsInlineDistinct()) {
6715                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6716                    }
6717                    else {
6718                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6719                    }
6720    
6721                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6722    
6723                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6724    
6725                    if (!getDB().isSupportsInlineDistinct()) {
6726                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6727                    }
6728    
6729                    if (orderByComparator != null) {
6730                            if (getDB().isSupportsInlineDistinct()) {
6731                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6732                                            orderByComparator, true);
6733                            }
6734                            else {
6735                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6736                                            orderByComparator, true);
6737                            }
6738                    }
6739                    else {
6740                            if (getDB().isSupportsInlineDistinct()) {
6741                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6742                            }
6743                            else {
6744                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6745                            }
6746                    }
6747    
6748                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6749                                    MBMessage.class.getName(),
6750                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6751    
6752                    Session session = null;
6753    
6754                    try {
6755                            session = openSession();
6756    
6757                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6758    
6759                            if (getDB().isSupportsInlineDistinct()) {
6760                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6761                            }
6762                            else {
6763                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6764                            }
6765    
6766                            QueryPos qPos = QueryPos.getInstance(q);
6767    
6768                            qPos.add(groupId);
6769    
6770                            qPos.add(status);
6771    
6772                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6773                    }
6774                    catch (Exception e) {
6775                            throw processException(e);
6776                    }
6777                    finally {
6778                            closeSession(session);
6779                    }
6780            }
6781    
6782            /**
6783             * 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;.
6784             *
6785             * @param messageId the primary key of the current message-boards message
6786             * @param groupId the group ID
6787             * @param status the status
6788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6789             * @return the previous, current, and next message-boards message
6790             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6791             */
6792            @Override
6793            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6794                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6795                    throws NoSuchMessageException {
6796                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6797                            return findByG_S_PrevAndNext(messageId, groupId, status,
6798                                    orderByComparator);
6799                    }
6800    
6801                    MBMessage mbMessage = findByPrimaryKey(messageId);
6802    
6803                    Session session = null;
6804    
6805                    try {
6806                            session = openSession();
6807    
6808                            MBMessage[] array = new MBMessageImpl[3];
6809    
6810                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6811                                            status, orderByComparator, true);
6812    
6813                            array[1] = mbMessage;
6814    
6815                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6816                                            status, orderByComparator, false);
6817    
6818                            return array;
6819                    }
6820                    catch (Exception e) {
6821                            throw processException(e);
6822                    }
6823                    finally {
6824                            closeSession(session);
6825                    }
6826            }
6827    
6828            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6829                    MBMessage mbMessage, long groupId, int status,
6830                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6831                    StringBundler query = null;
6832    
6833                    if (orderByComparator != null) {
6834                            query = new StringBundler(6 +
6835                                            (orderByComparator.getOrderByFields().length * 6));
6836                    }
6837                    else {
6838                            query = new StringBundler(3);
6839                    }
6840    
6841                    if (getDB().isSupportsInlineDistinct()) {
6842                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6843                    }
6844                    else {
6845                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6846                    }
6847    
6848                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6849    
6850                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6851    
6852                    if (!getDB().isSupportsInlineDistinct()) {
6853                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6854                    }
6855    
6856                    if (orderByComparator != null) {
6857                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6858    
6859                            if (orderByConditionFields.length > 0) {
6860                                    query.append(WHERE_AND);
6861                            }
6862    
6863                            for (int i = 0; i < orderByConditionFields.length; i++) {
6864                                    if (getDB().isSupportsInlineDistinct()) {
6865                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6866                                    }
6867                                    else {
6868                                            query.append(_ORDER_BY_ENTITY_TABLE);
6869                                    }
6870    
6871                                    query.append(orderByConditionFields[i]);
6872    
6873                                    if ((i + 1) < orderByConditionFields.length) {
6874                                            if (orderByComparator.isAscending() ^ previous) {
6875                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6876                                            }
6877                                            else {
6878                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6879                                            }
6880                                    }
6881                                    else {
6882                                            if (orderByComparator.isAscending() ^ previous) {
6883                                                    query.append(WHERE_GREATER_THAN);
6884                                            }
6885                                            else {
6886                                                    query.append(WHERE_LESSER_THAN);
6887                                            }
6888                                    }
6889                            }
6890    
6891                            query.append(ORDER_BY_CLAUSE);
6892    
6893                            String[] orderByFields = orderByComparator.getOrderByFields();
6894    
6895                            for (int i = 0; i < orderByFields.length; i++) {
6896                                    if (getDB().isSupportsInlineDistinct()) {
6897                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6898                                    }
6899                                    else {
6900                                            query.append(_ORDER_BY_ENTITY_TABLE);
6901                                    }
6902    
6903                                    query.append(orderByFields[i]);
6904    
6905                                    if ((i + 1) < orderByFields.length) {
6906                                            if (orderByComparator.isAscending() ^ previous) {
6907                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6908                                            }
6909                                            else {
6910                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6911                                            }
6912                                    }
6913                                    else {
6914                                            if (orderByComparator.isAscending() ^ previous) {
6915                                                    query.append(ORDER_BY_ASC);
6916                                            }
6917                                            else {
6918                                                    query.append(ORDER_BY_DESC);
6919                                            }
6920                                    }
6921                            }
6922                    }
6923                    else {
6924                            if (getDB().isSupportsInlineDistinct()) {
6925                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6926                            }
6927                            else {
6928                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6929                            }
6930                    }
6931    
6932                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6933                                    MBMessage.class.getName(),
6934                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6935    
6936                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6937    
6938                    q.setFirstResult(0);
6939                    q.setMaxResults(2);
6940    
6941                    if (getDB().isSupportsInlineDistinct()) {
6942                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6943                    }
6944                    else {
6945                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6946                    }
6947    
6948                    QueryPos qPos = QueryPos.getInstance(q);
6949    
6950                    qPos.add(groupId);
6951    
6952                    qPos.add(status);
6953    
6954                    if (orderByComparator != null) {
6955                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6956    
6957                            for (Object value : values) {
6958                                    qPos.add(value);
6959                            }
6960                    }
6961    
6962                    List<MBMessage> list = q.list();
6963    
6964                    if (list.size() == 2) {
6965                            return list.get(1);
6966                    }
6967                    else {
6968                            return null;
6969                    }
6970            }
6971    
6972            /**
6973             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6974             *
6975             * @param groupId the group ID
6976             * @param status the status
6977             */
6978            @Override
6979            public void removeByG_S(long groupId, int status) {
6980                    for (MBMessage mbMessage : findByG_S(groupId, status,
6981                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6982                            remove(mbMessage);
6983                    }
6984            }
6985    
6986            /**
6987             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6988             *
6989             * @param groupId the group ID
6990             * @param status the status
6991             * @return the number of matching message-boards messages
6992             */
6993            @Override
6994            public int countByG_S(long groupId, int status) {
6995                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6996    
6997                    Object[] finderArgs = new Object[] { groupId, status };
6998    
6999                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7000    
7001                    if (count == null) {
7002                            StringBundler query = new StringBundler(3);
7003    
7004                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7005    
7006                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7007    
7008                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
7009    
7010                            String sql = query.toString();
7011    
7012                            Session session = null;
7013    
7014                            try {
7015                                    session = openSession();
7016    
7017                                    Query q = session.createQuery(sql);
7018    
7019                                    QueryPos qPos = QueryPos.getInstance(q);
7020    
7021                                    qPos.add(groupId);
7022    
7023                                    qPos.add(status);
7024    
7025                                    count = (Long)q.uniqueResult();
7026    
7027                                    finderCache.putResult(finderPath, finderArgs, count);
7028                            }
7029                            catch (Exception e) {
7030                                    finderCache.removeResult(finderPath, finderArgs);
7031    
7032                                    throw processException(e);
7033                            }
7034                            finally {
7035                                    closeSession(session);
7036                            }
7037                    }
7038    
7039                    return count.intValue();
7040            }
7041    
7042            /**
7043             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
7044             *
7045             * @param groupId the group ID
7046             * @param status the status
7047             * @return the number of matching message-boards messages that the user has permission to view
7048             */
7049            @Override
7050            public int filterCountByG_S(long groupId, int status) {
7051                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7052                            return countByG_S(groupId, status);
7053                    }
7054    
7055                    StringBundler query = new StringBundler(3);
7056    
7057                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
7058    
7059                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7060    
7061                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
7062    
7063                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7064                                    MBMessage.class.getName(),
7065                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7066    
7067                    Session session = null;
7068    
7069                    try {
7070                            session = openSession();
7071    
7072                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7073    
7074                            q.addScalar(COUNT_COLUMN_NAME,
7075                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7076    
7077                            QueryPos qPos = QueryPos.getInstance(q);
7078    
7079                            qPos.add(groupId);
7080    
7081                            qPos.add(status);
7082    
7083                            Long count = (Long)q.uniqueResult();
7084    
7085                            return count.intValue();
7086                    }
7087                    catch (Exception e) {
7088                            throw processException(e);
7089                    }
7090                    finally {
7091                            closeSession(session);
7092                    }
7093            }
7094    
7095            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
7096            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7098                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7099                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7100                            new String[] {
7101                                    Long.class.getName(), Integer.class.getName(),
7102                                    
7103                            Integer.class.getName(), Integer.class.getName(),
7104                                    OrderByComparator.class.getName()
7105                            });
7106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7107                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7109                            new String[] { Long.class.getName(), Integer.class.getName() },
7110                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7111                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7112                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7113            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7114                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7116                            new String[] { Long.class.getName(), Integer.class.getName() });
7117    
7118            /**
7119             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7120             *
7121             * @param companyId the company ID
7122             * @param status the status
7123             * @return the matching message-boards messages
7124             */
7125            @Override
7126            public List<MBMessage> findByC_S(long companyId, int status) {
7127                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7128                            QueryUtil.ALL_POS, null);
7129            }
7130    
7131            /**
7132             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7133             *
7134             * <p>
7135             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7136             * </p>
7137             *
7138             * @param companyId the company ID
7139             * @param status the status
7140             * @param start the lower bound of the range of message-boards messages
7141             * @param end the upper bound of the range of message-boards messages (not inclusive)
7142             * @return the range of matching message-boards messages
7143             */
7144            @Override
7145            public List<MBMessage> findByC_S(long companyId, int status, int start,
7146                    int end) {
7147                    return findByC_S(companyId, status, start, end, null);
7148            }
7149    
7150            /**
7151             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7152             *
7153             * <p>
7154             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7155             * </p>
7156             *
7157             * @param companyId the company ID
7158             * @param status the status
7159             * @param start the lower bound of the range of message-boards messages
7160             * @param end the upper bound of the range of message-boards messages (not inclusive)
7161             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7162             * @return the ordered range of matching message-boards messages
7163             */
7164            @Override
7165            public List<MBMessage> findByC_S(long companyId, int status, int start,
7166                    int end, OrderByComparator<MBMessage> orderByComparator) {
7167                    return findByC_S(companyId, status, start, end, orderByComparator, true);
7168            }
7169    
7170            /**
7171             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7172             *
7173             * <p>
7174             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7175             * </p>
7176             *
7177             * @param companyId the company ID
7178             * @param status the status
7179             * @param start the lower bound of the range of message-boards messages
7180             * @param end the upper bound of the range of message-boards messages (not inclusive)
7181             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7182             * @param retrieveFromCache whether to retrieve from the finder cache
7183             * @return the ordered range of matching message-boards messages
7184             */
7185            @Override
7186            public List<MBMessage> findByC_S(long companyId, int status, int start,
7187                    int end, OrderByComparator<MBMessage> orderByComparator,
7188                    boolean retrieveFromCache) {
7189                    boolean pagination = true;
7190                    FinderPath finderPath = null;
7191                    Object[] finderArgs = null;
7192    
7193                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7194                                    (orderByComparator == null)) {
7195                            pagination = false;
7196                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7197                            finderArgs = new Object[] { companyId, status };
7198                    }
7199                    else {
7200                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7201                            finderArgs = new Object[] {
7202                                            companyId, status,
7203                                            
7204                                            start, end, orderByComparator
7205                                    };
7206                    }
7207    
7208                    List<MBMessage> list = null;
7209    
7210                    if (retrieveFromCache) {
7211                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7212                                            finderArgs, this);
7213    
7214                            if ((list != null) && !list.isEmpty()) {
7215                                    for (MBMessage mbMessage : list) {
7216                                            if ((companyId != mbMessage.getCompanyId()) ||
7217                                                            (status != mbMessage.getStatus())) {
7218                                                    list = null;
7219    
7220                                                    break;
7221                                            }
7222                                    }
7223                            }
7224                    }
7225    
7226                    if (list == null) {
7227                            StringBundler query = null;
7228    
7229                            if (orderByComparator != null) {
7230                                    query = new StringBundler(4 +
7231                                                    (orderByComparator.getOrderByFields().length * 3));
7232                            }
7233                            else {
7234                                    query = new StringBundler(4);
7235                            }
7236    
7237                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7238    
7239                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7240    
7241                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7242    
7243                            if (orderByComparator != null) {
7244                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7245                                            orderByComparator);
7246                            }
7247                            else
7248                             if (pagination) {
7249                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7250                            }
7251    
7252                            String sql = query.toString();
7253    
7254                            Session session = null;
7255    
7256                            try {
7257                                    session = openSession();
7258    
7259                                    Query q = session.createQuery(sql);
7260    
7261                                    QueryPos qPos = QueryPos.getInstance(q);
7262    
7263                                    qPos.add(companyId);
7264    
7265                                    qPos.add(status);
7266    
7267                                    if (!pagination) {
7268                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7269                                                            start, end, false);
7270    
7271                                            Collections.sort(list);
7272    
7273                                            list = Collections.unmodifiableList(list);
7274                                    }
7275                                    else {
7276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7277                                                            start, end);
7278                                    }
7279    
7280                                    cacheResult(list);
7281    
7282                                    finderCache.putResult(finderPath, finderArgs, list);
7283                            }
7284                            catch (Exception e) {
7285                                    finderCache.removeResult(finderPath, finderArgs);
7286    
7287                                    throw processException(e);
7288                            }
7289                            finally {
7290                                    closeSession(session);
7291                            }
7292                    }
7293    
7294                    return list;
7295            }
7296    
7297            /**
7298             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7299             *
7300             * @param companyId the company ID
7301             * @param status the status
7302             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7303             * @return the first matching message-boards message
7304             * @throws NoSuchMessageException if a matching message-boards message could not be found
7305             */
7306            @Override
7307            public MBMessage findByC_S_First(long companyId, int status,
7308                    OrderByComparator<MBMessage> orderByComparator)
7309                    throws NoSuchMessageException {
7310                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7311                                    orderByComparator);
7312    
7313                    if (mbMessage != null) {
7314                            return mbMessage;
7315                    }
7316    
7317                    StringBundler msg = new StringBundler(6);
7318    
7319                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7320    
7321                    msg.append("companyId=");
7322                    msg.append(companyId);
7323    
7324                    msg.append(", status=");
7325                    msg.append(status);
7326    
7327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7328    
7329                    throw new NoSuchMessageException(msg.toString());
7330            }
7331    
7332            /**
7333             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7334             *
7335             * @param companyId the company ID
7336             * @param status the status
7337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7338             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7339             */
7340            @Override
7341            public MBMessage fetchByC_S_First(long companyId, int status,
7342                    OrderByComparator<MBMessage> orderByComparator) {
7343                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7344                                    orderByComparator);
7345    
7346                    if (!list.isEmpty()) {
7347                            return list.get(0);
7348                    }
7349    
7350                    return null;
7351            }
7352    
7353            /**
7354             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7355             *
7356             * @param companyId the company ID
7357             * @param status the status
7358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7359             * @return the last matching message-boards message
7360             * @throws NoSuchMessageException if a matching message-boards message could not be found
7361             */
7362            @Override
7363            public MBMessage findByC_S_Last(long companyId, int status,
7364                    OrderByComparator<MBMessage> orderByComparator)
7365                    throws NoSuchMessageException {
7366                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7367                                    orderByComparator);
7368    
7369                    if (mbMessage != null) {
7370                            return mbMessage;
7371                    }
7372    
7373                    StringBundler msg = new StringBundler(6);
7374    
7375                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7376    
7377                    msg.append("companyId=");
7378                    msg.append(companyId);
7379    
7380                    msg.append(", status=");
7381                    msg.append(status);
7382    
7383                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7384    
7385                    throw new NoSuchMessageException(msg.toString());
7386            }
7387    
7388            /**
7389             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7390             *
7391             * @param companyId the company ID
7392             * @param status the status
7393             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7394             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7395             */
7396            @Override
7397            public MBMessage fetchByC_S_Last(long companyId, int status,
7398                    OrderByComparator<MBMessage> orderByComparator) {
7399                    int count = countByC_S(companyId, status);
7400    
7401                    if (count == 0) {
7402                            return null;
7403                    }
7404    
7405                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7406                                    orderByComparator);
7407    
7408                    if (!list.isEmpty()) {
7409                            return list.get(0);
7410                    }
7411    
7412                    return null;
7413            }
7414    
7415            /**
7416             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7417             *
7418             * @param messageId the primary key of the current message-boards message
7419             * @param companyId the company ID
7420             * @param status the status
7421             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7422             * @return the previous, current, and next message-boards message
7423             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7424             */
7425            @Override
7426            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7427                    int status, OrderByComparator<MBMessage> orderByComparator)
7428                    throws NoSuchMessageException {
7429                    MBMessage mbMessage = findByPrimaryKey(messageId);
7430    
7431                    Session session = null;
7432    
7433                    try {
7434                            session = openSession();
7435    
7436                            MBMessage[] array = new MBMessageImpl[3];
7437    
7438                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7439                                            status, orderByComparator, true);
7440    
7441                            array[1] = mbMessage;
7442    
7443                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7444                                            status, orderByComparator, false);
7445    
7446                            return array;
7447                    }
7448                    catch (Exception e) {
7449                            throw processException(e);
7450                    }
7451                    finally {
7452                            closeSession(session);
7453                    }
7454            }
7455    
7456            protected MBMessage getByC_S_PrevAndNext(Session session,
7457                    MBMessage mbMessage, long companyId, int status,
7458                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7459                    StringBundler query = null;
7460    
7461                    if (orderByComparator != null) {
7462                            query = new StringBundler(6 +
7463                                            (orderByComparator.getOrderByFields().length * 6));
7464                    }
7465                    else {
7466                            query = new StringBundler(3);
7467                    }
7468    
7469                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7470    
7471                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7472    
7473                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7474    
7475                    if (orderByComparator != null) {
7476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7477    
7478                            if (orderByConditionFields.length > 0) {
7479                                    query.append(WHERE_AND);
7480                            }
7481    
7482                            for (int i = 0; i < orderByConditionFields.length; i++) {
7483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7484                                    query.append(orderByConditionFields[i]);
7485    
7486                                    if ((i + 1) < orderByConditionFields.length) {
7487                                            if (orderByComparator.isAscending() ^ previous) {
7488                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7489                                            }
7490                                            else {
7491                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7492                                            }
7493                                    }
7494                                    else {
7495                                            if (orderByComparator.isAscending() ^ previous) {
7496                                                    query.append(WHERE_GREATER_THAN);
7497                                            }
7498                                            else {
7499                                                    query.append(WHERE_LESSER_THAN);
7500                                            }
7501                                    }
7502                            }
7503    
7504                            query.append(ORDER_BY_CLAUSE);
7505    
7506                            String[] orderByFields = orderByComparator.getOrderByFields();
7507    
7508                            for (int i = 0; i < orderByFields.length; i++) {
7509                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7510                                    query.append(orderByFields[i]);
7511    
7512                                    if ((i + 1) < orderByFields.length) {
7513                                            if (orderByComparator.isAscending() ^ previous) {
7514                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7515                                            }
7516                                            else {
7517                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7518                                            }
7519                                    }
7520                                    else {
7521                                            if (orderByComparator.isAscending() ^ previous) {
7522                                                    query.append(ORDER_BY_ASC);
7523                                            }
7524                                            else {
7525                                                    query.append(ORDER_BY_DESC);
7526                                            }
7527                                    }
7528                            }
7529                    }
7530                    else {
7531                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7532                    }
7533    
7534                    String sql = query.toString();
7535    
7536                    Query q = session.createQuery(sql);
7537    
7538                    q.setFirstResult(0);
7539                    q.setMaxResults(2);
7540    
7541                    QueryPos qPos = QueryPos.getInstance(q);
7542    
7543                    qPos.add(companyId);
7544    
7545                    qPos.add(status);
7546    
7547                    if (orderByComparator != null) {
7548                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7549    
7550                            for (Object value : values) {
7551                                    qPos.add(value);
7552                            }
7553                    }
7554    
7555                    List<MBMessage> list = q.list();
7556    
7557                    if (list.size() == 2) {
7558                            return list.get(1);
7559                    }
7560                    else {
7561                            return null;
7562                    }
7563            }
7564    
7565            /**
7566             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7567             *
7568             * @param companyId the company ID
7569             * @param status the status
7570             */
7571            @Override
7572            public void removeByC_S(long companyId, int status) {
7573                    for (MBMessage mbMessage : findByC_S(companyId, status,
7574                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7575                            remove(mbMessage);
7576                    }
7577            }
7578    
7579            /**
7580             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7581             *
7582             * @param companyId the company ID
7583             * @param status the status
7584             * @return the number of matching message-boards messages
7585             */
7586            @Override
7587            public int countByC_S(long companyId, int status) {
7588                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7589    
7590                    Object[] finderArgs = new Object[] { companyId, status };
7591    
7592                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7593    
7594                    if (count == null) {
7595                            StringBundler query = new StringBundler(3);
7596    
7597                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7598    
7599                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7600    
7601                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7602    
7603                            String sql = query.toString();
7604    
7605                            Session session = null;
7606    
7607                            try {
7608                                    session = openSession();
7609    
7610                                    Query q = session.createQuery(sql);
7611    
7612                                    QueryPos qPos = QueryPos.getInstance(q);
7613    
7614                                    qPos.add(companyId);
7615    
7616                                    qPos.add(status);
7617    
7618                                    count = (Long)q.uniqueResult();
7619    
7620                                    finderCache.putResult(finderPath, finderArgs, count);
7621                            }
7622                            catch (Exception e) {
7623                                    finderCache.removeResult(finderPath, finderArgs);
7624    
7625                                    throw processException(e);
7626                            }
7627                            finally {
7628                                    closeSession(session);
7629                            }
7630                    }
7631    
7632                    return count.intValue();
7633            }
7634    
7635            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7636            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7637            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7638                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7639                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7640                            new String[] {
7641                                    Long.class.getName(), Long.class.getName(),
7642                                    
7643                            Integer.class.getName(), Integer.class.getName(),
7644                                    OrderByComparator.class.getName()
7645                            });
7646            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7647                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7649                            new String[] { Long.class.getName(), Long.class.getName() },
7650                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7651                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7652                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7653            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7656                            new String[] { Long.class.getName(), Long.class.getName() });
7657            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7658                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7659                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7660                            new String[] { Long.class.getName(), Long.class.getName() });
7661    
7662            /**
7663             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7664             *
7665             * @param userId the user ID
7666             * @param classNameId the class name ID
7667             * @return the matching message-boards messages
7668             */
7669            @Override
7670            public List<MBMessage> findByU_C(long userId, long classNameId) {
7671                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7672                            QueryUtil.ALL_POS, null);
7673            }
7674    
7675            /**
7676             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7677             *
7678             * <p>
7679             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7680             * </p>
7681             *
7682             * @param userId the user ID
7683             * @param classNameId the class name ID
7684             * @param start the lower bound of the range of message-boards messages
7685             * @param end the upper bound of the range of message-boards messages (not inclusive)
7686             * @return the range of matching message-boards messages
7687             */
7688            @Override
7689            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7690                    int end) {
7691                    return findByU_C(userId, classNameId, start, end, null);
7692            }
7693    
7694            /**
7695             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7696             *
7697             * <p>
7698             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7699             * </p>
7700             *
7701             * @param userId the user ID
7702             * @param classNameId the class name ID
7703             * @param start the lower bound of the range of message-boards messages
7704             * @param end the upper bound of the range of message-boards messages (not inclusive)
7705             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7706             * @return the ordered range of matching message-boards messages
7707             */
7708            @Override
7709            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7710                    int end, OrderByComparator<MBMessage> orderByComparator) {
7711                    return findByU_C(userId, classNameId, start, end, orderByComparator,
7712                            true);
7713            }
7714    
7715            /**
7716             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7717             *
7718             * <p>
7719             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7720             * </p>
7721             *
7722             * @param userId the user ID
7723             * @param classNameId the class name ID
7724             * @param start the lower bound of the range of message-boards messages
7725             * @param end the upper bound of the range of message-boards messages (not inclusive)
7726             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7727             * @param retrieveFromCache whether to retrieve from the finder cache
7728             * @return the ordered range of matching message-boards messages
7729             */
7730            @Override
7731            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7732                    int end, OrderByComparator<MBMessage> orderByComparator,
7733                    boolean retrieveFromCache) {
7734                    boolean pagination = true;
7735                    FinderPath finderPath = null;
7736                    Object[] finderArgs = null;
7737    
7738                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7739                                    (orderByComparator == null)) {
7740                            pagination = false;
7741                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7742                            finderArgs = new Object[] { userId, classNameId };
7743                    }
7744                    else {
7745                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7746                            finderArgs = new Object[] {
7747                                            userId, classNameId,
7748                                            
7749                                            start, end, orderByComparator
7750                                    };
7751                    }
7752    
7753                    List<MBMessage> list = null;
7754    
7755                    if (retrieveFromCache) {
7756                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7757                                            finderArgs, this);
7758    
7759                            if ((list != null) && !list.isEmpty()) {
7760                                    for (MBMessage mbMessage : list) {
7761                                            if ((userId != mbMessage.getUserId()) ||
7762                                                            (classNameId != mbMessage.getClassNameId())) {
7763                                                    list = null;
7764    
7765                                                    break;
7766                                            }
7767                                    }
7768                            }
7769                    }
7770    
7771                    if (list == null) {
7772                            StringBundler query = null;
7773    
7774                            if (orderByComparator != null) {
7775                                    query = new StringBundler(4 +
7776                                                    (orderByComparator.getOrderByFields().length * 3));
7777                            }
7778                            else {
7779                                    query = new StringBundler(4);
7780                            }
7781    
7782                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7783    
7784                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7785    
7786                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7787    
7788                            if (orderByComparator != null) {
7789                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7790                                            orderByComparator);
7791                            }
7792                            else
7793                             if (pagination) {
7794                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7795                            }
7796    
7797                            String sql = query.toString();
7798    
7799                            Session session = null;
7800    
7801                            try {
7802                                    session = openSession();
7803    
7804                                    Query q = session.createQuery(sql);
7805    
7806                                    QueryPos qPos = QueryPos.getInstance(q);
7807    
7808                                    qPos.add(userId);
7809    
7810                                    qPos.add(classNameId);
7811    
7812                                    if (!pagination) {
7813                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7814                                                            start, end, false);
7815    
7816                                            Collections.sort(list);
7817    
7818                                            list = Collections.unmodifiableList(list);
7819                                    }
7820                                    else {
7821                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7822                                                            start, end);
7823                                    }
7824    
7825                                    cacheResult(list);
7826    
7827                                    finderCache.putResult(finderPath, finderArgs, list);
7828                            }
7829                            catch (Exception e) {
7830                                    finderCache.removeResult(finderPath, finderArgs);
7831    
7832                                    throw processException(e);
7833                            }
7834                            finally {
7835                                    closeSession(session);
7836                            }
7837                    }
7838    
7839                    return list;
7840            }
7841    
7842            /**
7843             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7844             *
7845             * @param userId the user ID
7846             * @param classNameId the class name ID
7847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7848             * @return the first matching message-boards message
7849             * @throws NoSuchMessageException if a matching message-boards message could not be found
7850             */
7851            @Override
7852            public MBMessage findByU_C_First(long userId, long classNameId,
7853                    OrderByComparator<MBMessage> orderByComparator)
7854                    throws NoSuchMessageException {
7855                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7856                                    orderByComparator);
7857    
7858                    if (mbMessage != null) {
7859                            return mbMessage;
7860                    }
7861    
7862                    StringBundler msg = new StringBundler(6);
7863    
7864                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7865    
7866                    msg.append("userId=");
7867                    msg.append(userId);
7868    
7869                    msg.append(", classNameId=");
7870                    msg.append(classNameId);
7871    
7872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7873    
7874                    throw new NoSuchMessageException(msg.toString());
7875            }
7876    
7877            /**
7878             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7879             *
7880             * @param userId the user ID
7881             * @param classNameId the class name ID
7882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7883             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7884             */
7885            @Override
7886            public MBMessage fetchByU_C_First(long userId, long classNameId,
7887                    OrderByComparator<MBMessage> orderByComparator) {
7888                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7889                                    orderByComparator);
7890    
7891                    if (!list.isEmpty()) {
7892                            return list.get(0);
7893                    }
7894    
7895                    return null;
7896            }
7897    
7898            /**
7899             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7900             *
7901             * @param userId the user ID
7902             * @param classNameId the class name ID
7903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7904             * @return the last matching message-boards message
7905             * @throws NoSuchMessageException if a matching message-boards message could not be found
7906             */
7907            @Override
7908            public MBMessage findByU_C_Last(long userId, long classNameId,
7909                    OrderByComparator<MBMessage> orderByComparator)
7910                    throws NoSuchMessageException {
7911                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7912                                    orderByComparator);
7913    
7914                    if (mbMessage != null) {
7915                            return mbMessage;
7916                    }
7917    
7918                    StringBundler msg = new StringBundler(6);
7919    
7920                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7921    
7922                    msg.append("userId=");
7923                    msg.append(userId);
7924    
7925                    msg.append(", classNameId=");
7926                    msg.append(classNameId);
7927    
7928                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7929    
7930                    throw new NoSuchMessageException(msg.toString());
7931            }
7932    
7933            /**
7934             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7935             *
7936             * @param userId the user ID
7937             * @param classNameId the class name ID
7938             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7939             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7940             */
7941            @Override
7942            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7943                    OrderByComparator<MBMessage> orderByComparator) {
7944                    int count = countByU_C(userId, classNameId);
7945    
7946                    if (count == 0) {
7947                            return null;
7948                    }
7949    
7950                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7951                                    orderByComparator);
7952    
7953                    if (!list.isEmpty()) {
7954                            return list.get(0);
7955                    }
7956    
7957                    return null;
7958            }
7959    
7960            /**
7961             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7962             *
7963             * @param messageId the primary key of the current message-boards message
7964             * @param userId the user ID
7965             * @param classNameId the class name ID
7966             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7967             * @return the previous, current, and next message-boards message
7968             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7969             */
7970            @Override
7971            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7972                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7973                    throws NoSuchMessageException {
7974                    MBMessage mbMessage = findByPrimaryKey(messageId);
7975    
7976                    Session session = null;
7977    
7978                    try {
7979                            session = openSession();
7980    
7981                            MBMessage[] array = new MBMessageImpl[3];
7982    
7983                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7984                                            classNameId, orderByComparator, true);
7985    
7986                            array[1] = mbMessage;
7987    
7988                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7989                                            classNameId, orderByComparator, false);
7990    
7991                            return array;
7992                    }
7993                    catch (Exception e) {
7994                            throw processException(e);
7995                    }
7996                    finally {
7997                            closeSession(session);
7998                    }
7999            }
8000    
8001            protected MBMessage getByU_C_PrevAndNext(Session session,
8002                    MBMessage mbMessage, long userId, long classNameId,
8003                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8004                    StringBundler query = null;
8005    
8006                    if (orderByComparator != null) {
8007                            query = new StringBundler(6 +
8008                                            (orderByComparator.getOrderByFields().length * 6));
8009                    }
8010                    else {
8011                            query = new StringBundler(3);
8012                    }
8013    
8014                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8015    
8016                    query.append(_FINDER_COLUMN_U_C_USERID_2);
8017    
8018                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8019    
8020                    if (orderByComparator != null) {
8021                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8022    
8023                            if (orderByConditionFields.length > 0) {
8024                                    query.append(WHERE_AND);
8025                            }
8026    
8027                            for (int i = 0; i < orderByConditionFields.length; i++) {
8028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8029                                    query.append(orderByConditionFields[i]);
8030    
8031                                    if ((i + 1) < orderByConditionFields.length) {
8032                                            if (orderByComparator.isAscending() ^ previous) {
8033                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8034                                            }
8035                                            else {
8036                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8037                                            }
8038                                    }
8039                                    else {
8040                                            if (orderByComparator.isAscending() ^ previous) {
8041                                                    query.append(WHERE_GREATER_THAN);
8042                                            }
8043                                            else {
8044                                                    query.append(WHERE_LESSER_THAN);
8045                                            }
8046                                    }
8047                            }
8048    
8049                            query.append(ORDER_BY_CLAUSE);
8050    
8051                            String[] orderByFields = orderByComparator.getOrderByFields();
8052    
8053                            for (int i = 0; i < orderByFields.length; i++) {
8054                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8055                                    query.append(orderByFields[i]);
8056    
8057                                    if ((i + 1) < orderByFields.length) {
8058                                            if (orderByComparator.isAscending() ^ previous) {
8059                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8060                                            }
8061                                            else {
8062                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8063                                            }
8064                                    }
8065                                    else {
8066                                            if (orderByComparator.isAscending() ^ previous) {
8067                                                    query.append(ORDER_BY_ASC);
8068                                            }
8069                                            else {
8070                                                    query.append(ORDER_BY_DESC);
8071                                            }
8072                                    }
8073                            }
8074                    }
8075                    else {
8076                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8077                    }
8078    
8079                    String sql = query.toString();
8080    
8081                    Query q = session.createQuery(sql);
8082    
8083                    q.setFirstResult(0);
8084                    q.setMaxResults(2);
8085    
8086                    QueryPos qPos = QueryPos.getInstance(q);
8087    
8088                    qPos.add(userId);
8089    
8090                    qPos.add(classNameId);
8091    
8092                    if (orderByComparator != null) {
8093                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8094    
8095                            for (Object value : values) {
8096                                    qPos.add(value);
8097                            }
8098                    }
8099    
8100                    List<MBMessage> list = q.list();
8101    
8102                    if (list.size() == 2) {
8103                            return list.get(1);
8104                    }
8105                    else {
8106                            return null;
8107                    }
8108            }
8109    
8110            /**
8111             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8112             *
8113             * <p>
8114             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8115             * </p>
8116             *
8117             * @param userId the user ID
8118             * @param classNameIds the class name IDs
8119             * @return the matching message-boards messages
8120             */
8121            @Override
8122            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
8123                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
8124                            QueryUtil.ALL_POS, null);
8125            }
8126    
8127            /**
8128             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8129             *
8130             * <p>
8131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8132             * </p>
8133             *
8134             * @param userId the user ID
8135             * @param classNameIds the class name IDs
8136             * @param start the lower bound of the range of message-boards messages
8137             * @param end the upper bound of the range of message-boards messages (not inclusive)
8138             * @return the range of matching message-boards messages
8139             */
8140            @Override
8141            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8142                    int start, int end) {
8143                    return findByU_C(userId, classNameIds, start, end, null);
8144            }
8145    
8146            /**
8147             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8148             *
8149             * <p>
8150             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8151             * </p>
8152             *
8153             * @param userId the user ID
8154             * @param classNameIds the class name IDs
8155             * @param start the lower bound of the range of message-boards messages
8156             * @param end the upper bound of the range of message-boards messages (not inclusive)
8157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8158             * @return the ordered range of matching message-boards messages
8159             */
8160            @Override
8161            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8162                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8163                    return findByU_C(userId, classNameIds, start, end, orderByComparator,
8164                            true);
8165            }
8166    
8167            /**
8168             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;, optionally using the finder cache.
8169             *
8170             * <p>
8171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8172             * </p>
8173             *
8174             * @param userId the user ID
8175             * @param classNameId the class name ID
8176             * @param start the lower bound of the range of message-boards messages
8177             * @param end the upper bound of the range of message-boards messages (not inclusive)
8178             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8179             * @param retrieveFromCache whether to retrieve from the finder cache
8180             * @return the ordered range of matching message-boards messages
8181             */
8182            @Override
8183            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8184                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
8185                    boolean retrieveFromCache) {
8186                    if (classNameIds == null) {
8187                            classNameIds = new long[0];
8188                    }
8189                    else if (classNameIds.length > 1) {
8190                            classNameIds = ArrayUtil.unique(classNameIds);
8191    
8192                            Arrays.sort(classNameIds);
8193                    }
8194    
8195                    if (classNameIds.length == 1) {
8196                            return findByU_C(userId, classNameIds[0], start, end,
8197                                    orderByComparator);
8198                    }
8199    
8200                    boolean pagination = true;
8201                    Object[] finderArgs = null;
8202    
8203                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8204                                    (orderByComparator == null)) {
8205                            pagination = false;
8206                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8207                    }
8208                    else {
8209                            finderArgs = new Object[] {
8210                                            userId, StringUtil.merge(classNameIds),
8211                                            
8212                                            start, end, orderByComparator
8213                                    };
8214                    }
8215    
8216                    List<MBMessage> list = null;
8217    
8218                    if (retrieveFromCache) {
8219                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8220                                            finderArgs, this);
8221    
8222                            if ((list != null) && !list.isEmpty()) {
8223                                    for (MBMessage mbMessage : list) {
8224                                            if ((userId != mbMessage.getUserId()) ||
8225                                                            !ArrayUtil.contains(classNameIds,
8226                                                                    mbMessage.getClassNameId())) {
8227                                                    list = null;
8228    
8229                                                    break;
8230                                            }
8231                                    }
8232                            }
8233                    }
8234    
8235                    if (list == null) {
8236                            StringBundler query = new StringBundler();
8237    
8238                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8239    
8240                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8241    
8242                            if (classNameIds.length > 0) {
8243                                    query.append(StringPool.OPEN_PARENTHESIS);
8244    
8245                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8246    
8247                                    query.append(StringUtil.merge(classNameIds));
8248    
8249                                    query.append(StringPool.CLOSE_PARENTHESIS);
8250    
8251                                    query.append(StringPool.CLOSE_PARENTHESIS);
8252                            }
8253    
8254                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8255                                                    1)), query.index() - 1);
8256    
8257                            if (orderByComparator != null) {
8258                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8259                                            orderByComparator);
8260                            }
8261                            else
8262                             if (pagination) {
8263                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8264                            }
8265    
8266                            String sql = query.toString();
8267    
8268                            Session session = null;
8269    
8270                            try {
8271                                    session = openSession();
8272    
8273                                    Query q = session.createQuery(sql);
8274    
8275                                    QueryPos qPos = QueryPos.getInstance(q);
8276    
8277                                    qPos.add(userId);
8278    
8279                                    if (!pagination) {
8280                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8281                                                            start, end, false);
8282    
8283                                            Collections.sort(list);
8284    
8285                                            list = Collections.unmodifiableList(list);
8286                                    }
8287                                    else {
8288                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8289                                                            start, end);
8290                                    }
8291    
8292                                    cacheResult(list);
8293    
8294                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8295                                            finderArgs, list);
8296                            }
8297                            catch (Exception e) {
8298                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8299                                            finderArgs);
8300    
8301                                    throw processException(e);
8302                            }
8303                            finally {
8304                                    closeSession(session);
8305                            }
8306                    }
8307    
8308                    return list;
8309            }
8310    
8311            /**
8312             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8313             *
8314             * @param userId the user ID
8315             * @param classNameId the class name ID
8316             */
8317            @Override
8318            public void removeByU_C(long userId, long classNameId) {
8319                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8320                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8321                            remove(mbMessage);
8322                    }
8323            }
8324    
8325            /**
8326             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8327             *
8328             * @param userId the user ID
8329             * @param classNameId the class name ID
8330             * @return the number of matching message-boards messages
8331             */
8332            @Override
8333            public int countByU_C(long userId, long classNameId) {
8334                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8335    
8336                    Object[] finderArgs = new Object[] { userId, classNameId };
8337    
8338                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8339    
8340                    if (count == null) {
8341                            StringBundler query = new StringBundler(3);
8342    
8343                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8344    
8345                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8346    
8347                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8348    
8349                            String sql = query.toString();
8350    
8351                            Session session = null;
8352    
8353                            try {
8354                                    session = openSession();
8355    
8356                                    Query q = session.createQuery(sql);
8357    
8358                                    QueryPos qPos = QueryPos.getInstance(q);
8359    
8360                                    qPos.add(userId);
8361    
8362                                    qPos.add(classNameId);
8363    
8364                                    count = (Long)q.uniqueResult();
8365    
8366                                    finderCache.putResult(finderPath, finderArgs, count);
8367                            }
8368                            catch (Exception e) {
8369                                    finderCache.removeResult(finderPath, finderArgs);
8370    
8371                                    throw processException(e);
8372                            }
8373                            finally {
8374                                    closeSession(session);
8375                            }
8376                    }
8377    
8378                    return count.intValue();
8379            }
8380    
8381            /**
8382             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8383             *
8384             * @param userId the user ID
8385             * @param classNameIds the class name IDs
8386             * @return the number of matching message-boards messages
8387             */
8388            @Override
8389            public int countByU_C(long userId, long[] classNameIds) {
8390                    if (classNameIds == null) {
8391                            classNameIds = new long[0];
8392                    }
8393                    else if (classNameIds.length > 1) {
8394                            classNameIds = ArrayUtil.unique(classNameIds);
8395    
8396                            Arrays.sort(classNameIds);
8397                    }
8398    
8399                    Object[] finderArgs = new Object[] {
8400                                    userId, StringUtil.merge(classNameIds)
8401                            };
8402    
8403                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8404                                    finderArgs, this);
8405    
8406                    if (count == null) {
8407                            StringBundler query = new StringBundler();
8408    
8409                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8410    
8411                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8412    
8413                            if (classNameIds.length > 0) {
8414                                    query.append(StringPool.OPEN_PARENTHESIS);
8415    
8416                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8417    
8418                                    query.append(StringUtil.merge(classNameIds));
8419    
8420                                    query.append(StringPool.CLOSE_PARENTHESIS);
8421    
8422                                    query.append(StringPool.CLOSE_PARENTHESIS);
8423                            }
8424    
8425                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8426                                                    1)), query.index() - 1);
8427    
8428                            String sql = query.toString();
8429    
8430                            Session session = null;
8431    
8432                            try {
8433                                    session = openSession();
8434    
8435                                    Query q = session.createQuery(sql);
8436    
8437                                    QueryPos qPos = QueryPos.getInstance(q);
8438    
8439                                    qPos.add(userId);
8440    
8441                                    count = (Long)q.uniqueResult();
8442    
8443                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8444                                            finderArgs, count);
8445                            }
8446                            catch (Exception e) {
8447                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8448                                            finderArgs);
8449    
8450                                    throw processException(e);
8451                            }
8452                            finally {
8453                                    closeSession(session);
8454                            }
8455                    }
8456    
8457                    return count.intValue();
8458            }
8459    
8460            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8461            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8462            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8463            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8464                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8465                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8466                            new String[] {
8467                                    Long.class.getName(), Long.class.getName(),
8468                                    
8469                            Integer.class.getName(), Integer.class.getName(),
8470                                    OrderByComparator.class.getName()
8471                            });
8472            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8473                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8474                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8475                            new String[] { Long.class.getName(), Long.class.getName() },
8476                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8477                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8478                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8479            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8480                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8481                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8482                            new String[] { Long.class.getName(), Long.class.getName() });
8483    
8484            /**
8485             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8486             *
8487             * @param classNameId the class name ID
8488             * @param classPK the class p k
8489             * @return the matching message-boards messages
8490             */
8491            @Override
8492            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8493                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8494                            QueryUtil.ALL_POS, null);
8495            }
8496    
8497            /**
8498             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8499             *
8500             * <p>
8501             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8502             * </p>
8503             *
8504             * @param classNameId the class name ID
8505             * @param classPK the class p k
8506             * @param start the lower bound of the range of message-boards messages
8507             * @param end the upper bound of the range of message-boards messages (not inclusive)
8508             * @return the range of matching message-boards messages
8509             */
8510            @Override
8511            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8512                    int end) {
8513                    return findByC_C(classNameId, classPK, start, end, null);
8514            }
8515    
8516            /**
8517             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8518             *
8519             * <p>
8520             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8521             * </p>
8522             *
8523             * @param classNameId the class name ID
8524             * @param classPK the class p k
8525             * @param start the lower bound of the range of message-boards messages
8526             * @param end the upper bound of the range of message-boards messages (not inclusive)
8527             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8528             * @return the ordered range of matching message-boards messages
8529             */
8530            @Override
8531            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8532                    int end, OrderByComparator<MBMessage> orderByComparator) {
8533                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
8534                            true);
8535            }
8536    
8537            /**
8538             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8539             *
8540             * <p>
8541             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8542             * </p>
8543             *
8544             * @param classNameId the class name ID
8545             * @param classPK the class p k
8546             * @param start the lower bound of the range of message-boards messages
8547             * @param end the upper bound of the range of message-boards messages (not inclusive)
8548             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8549             * @param retrieveFromCache whether to retrieve from the finder cache
8550             * @return the ordered range of matching message-boards messages
8551             */
8552            @Override
8553            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8554                    int end, OrderByComparator<MBMessage> orderByComparator,
8555                    boolean retrieveFromCache) {
8556                    boolean pagination = true;
8557                    FinderPath finderPath = null;
8558                    Object[] finderArgs = null;
8559    
8560                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8561                                    (orderByComparator == null)) {
8562                            pagination = false;
8563                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8564                            finderArgs = new Object[] { classNameId, classPK };
8565                    }
8566                    else {
8567                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8568                            finderArgs = new Object[] {
8569                                            classNameId, classPK,
8570                                            
8571                                            start, end, orderByComparator
8572                                    };
8573                    }
8574    
8575                    List<MBMessage> list = null;
8576    
8577                    if (retrieveFromCache) {
8578                            list = (List<MBMessage>)finderCache.getResult(finderPath,
8579                                            finderArgs, this);
8580    
8581                            if ((list != null) && !list.isEmpty()) {
8582                                    for (MBMessage mbMessage : list) {
8583                                            if ((classNameId != mbMessage.getClassNameId()) ||
8584                                                            (classPK != mbMessage.getClassPK())) {
8585                                                    list = null;
8586    
8587                                                    break;
8588                                            }
8589                                    }
8590                            }
8591                    }
8592    
8593                    if (list == null) {
8594                            StringBundler query = null;
8595    
8596                            if (orderByComparator != null) {
8597                                    query = new StringBundler(4 +
8598                                                    (orderByComparator.getOrderByFields().length * 3));
8599                            }
8600                            else {
8601                                    query = new StringBundler(4);
8602                            }
8603    
8604                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8605    
8606                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8607    
8608                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8609    
8610                            if (orderByComparator != null) {
8611                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8612                                            orderByComparator);
8613                            }
8614                            else
8615                             if (pagination) {
8616                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8617                            }
8618    
8619                            String sql = query.toString();
8620    
8621                            Session session = null;
8622    
8623                            try {
8624                                    session = openSession();
8625    
8626                                    Query q = session.createQuery(sql);
8627    
8628                                    QueryPos qPos = QueryPos.getInstance(q);
8629    
8630                                    qPos.add(classNameId);
8631    
8632                                    qPos.add(classPK);
8633    
8634                                    if (!pagination) {
8635                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8636                                                            start, end, false);
8637    
8638                                            Collections.sort(list);
8639    
8640                                            list = Collections.unmodifiableList(list);
8641                                    }
8642                                    else {
8643                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8644                                                            start, end);
8645                                    }
8646    
8647                                    cacheResult(list);
8648    
8649                                    finderCache.putResult(finderPath, finderArgs, list);
8650                            }
8651                            catch (Exception e) {
8652                                    finderCache.removeResult(finderPath, finderArgs);
8653    
8654                                    throw processException(e);
8655                            }
8656                            finally {
8657                                    closeSession(session);
8658                            }
8659                    }
8660    
8661                    return list;
8662            }
8663    
8664            /**
8665             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8666             *
8667             * @param classNameId the class name ID
8668             * @param classPK the class p k
8669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8670             * @return the first matching message-boards message
8671             * @throws NoSuchMessageException if a matching message-boards message could not be found
8672             */
8673            @Override
8674            public MBMessage findByC_C_First(long classNameId, long classPK,
8675                    OrderByComparator<MBMessage> orderByComparator)
8676                    throws NoSuchMessageException {
8677                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8678                                    orderByComparator);
8679    
8680                    if (mbMessage != null) {
8681                            return mbMessage;
8682                    }
8683    
8684                    StringBundler msg = new StringBundler(6);
8685    
8686                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8687    
8688                    msg.append("classNameId=");
8689                    msg.append(classNameId);
8690    
8691                    msg.append(", classPK=");
8692                    msg.append(classPK);
8693    
8694                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8695    
8696                    throw new NoSuchMessageException(msg.toString());
8697            }
8698    
8699            /**
8700             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8701             *
8702             * @param classNameId the class name ID
8703             * @param classPK the class p k
8704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8705             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8706             */
8707            @Override
8708            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8709                    OrderByComparator<MBMessage> orderByComparator) {
8710                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8711                                    orderByComparator);
8712    
8713                    if (!list.isEmpty()) {
8714                            return list.get(0);
8715                    }
8716    
8717                    return null;
8718            }
8719    
8720            /**
8721             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8722             *
8723             * @param classNameId the class name ID
8724             * @param classPK the class p k
8725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8726             * @return the last matching message-boards message
8727             * @throws NoSuchMessageException if a matching message-boards message could not be found
8728             */
8729            @Override
8730            public MBMessage findByC_C_Last(long classNameId, long classPK,
8731                    OrderByComparator<MBMessage> orderByComparator)
8732                    throws NoSuchMessageException {
8733                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8734                                    orderByComparator);
8735    
8736                    if (mbMessage != null) {
8737                            return mbMessage;
8738                    }
8739    
8740                    StringBundler msg = new StringBundler(6);
8741    
8742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8743    
8744                    msg.append("classNameId=");
8745                    msg.append(classNameId);
8746    
8747                    msg.append(", classPK=");
8748                    msg.append(classPK);
8749    
8750                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8751    
8752                    throw new NoSuchMessageException(msg.toString());
8753            }
8754    
8755            /**
8756             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8757             *
8758             * @param classNameId the class name ID
8759             * @param classPK the class p k
8760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8761             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8762             */
8763            @Override
8764            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8765                    OrderByComparator<MBMessage> orderByComparator) {
8766                    int count = countByC_C(classNameId, classPK);
8767    
8768                    if (count == 0) {
8769                            return null;
8770                    }
8771    
8772                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8773                                    count, orderByComparator);
8774    
8775                    if (!list.isEmpty()) {
8776                            return list.get(0);
8777                    }
8778    
8779                    return null;
8780            }
8781    
8782            /**
8783             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8784             *
8785             * @param messageId the primary key of the current message-boards message
8786             * @param classNameId the class name ID
8787             * @param classPK the class p k
8788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8789             * @return the previous, current, and next message-boards message
8790             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8791             */
8792            @Override
8793            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8794                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8795                    throws NoSuchMessageException {
8796                    MBMessage mbMessage = findByPrimaryKey(messageId);
8797    
8798                    Session session = null;
8799    
8800                    try {
8801                            session = openSession();
8802    
8803                            MBMessage[] array = new MBMessageImpl[3];
8804    
8805                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8806                                            classPK, orderByComparator, true);
8807    
8808                            array[1] = mbMessage;
8809    
8810                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8811                                            classPK, orderByComparator, false);
8812    
8813                            return array;
8814                    }
8815                    catch (Exception e) {
8816                            throw processException(e);
8817                    }
8818                    finally {
8819                            closeSession(session);
8820                    }
8821            }
8822    
8823            protected MBMessage getByC_C_PrevAndNext(Session session,
8824                    MBMessage mbMessage, long classNameId, long classPK,
8825                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8826                    StringBundler query = null;
8827    
8828                    if (orderByComparator != null) {
8829                            query = new StringBundler(6 +
8830                                            (orderByComparator.getOrderByFields().length * 6));
8831                    }
8832                    else {
8833                            query = new StringBundler(3);
8834                    }
8835    
8836                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8837    
8838                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8839    
8840                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8841    
8842                    if (orderByComparator != null) {
8843                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8844    
8845                            if (orderByConditionFields.length > 0) {
8846                                    query.append(WHERE_AND);
8847                            }
8848    
8849                            for (int i = 0; i < orderByConditionFields.length; i++) {
8850                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8851                                    query.append(orderByConditionFields[i]);
8852    
8853                                    if ((i + 1) < orderByConditionFields.length) {
8854                                            if (orderByComparator.isAscending() ^ previous) {
8855                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8856                                            }
8857                                            else {
8858                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8859                                            }
8860                                    }
8861                                    else {
8862                                            if (orderByComparator.isAscending() ^ previous) {
8863                                                    query.append(WHERE_GREATER_THAN);
8864                                            }
8865                                            else {
8866                                                    query.append(WHERE_LESSER_THAN);
8867                                            }
8868                                    }
8869                            }
8870    
8871                            query.append(ORDER_BY_CLAUSE);
8872    
8873                            String[] orderByFields = orderByComparator.getOrderByFields();
8874    
8875                            for (int i = 0; i < orderByFields.length; i++) {
8876                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8877                                    query.append(orderByFields[i]);
8878    
8879                                    if ((i + 1) < orderByFields.length) {
8880                                            if (orderByComparator.isAscending() ^ previous) {
8881                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8882                                            }
8883                                            else {
8884                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8885                                            }
8886                                    }
8887                                    else {
8888                                            if (orderByComparator.isAscending() ^ previous) {
8889                                                    query.append(ORDER_BY_ASC);
8890                                            }
8891                                            else {
8892                                                    query.append(ORDER_BY_DESC);
8893                                            }
8894                                    }
8895                            }
8896                    }
8897                    else {
8898                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8899                    }
8900    
8901                    String sql = query.toString();
8902    
8903                    Query q = session.createQuery(sql);
8904    
8905                    q.setFirstResult(0);
8906                    q.setMaxResults(2);
8907    
8908                    QueryPos qPos = QueryPos.getInstance(q);
8909    
8910                    qPos.add(classNameId);
8911    
8912                    qPos.add(classPK);
8913    
8914                    if (orderByComparator != null) {
8915                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8916    
8917                            for (Object value : values) {
8918                                    qPos.add(value);
8919                            }
8920                    }
8921    
8922                    List<MBMessage> list = q.list();
8923    
8924                    if (list.size() == 2) {
8925                            return list.get(1);
8926                    }
8927                    else {
8928                            return null;
8929                    }
8930            }
8931    
8932            /**
8933             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8934             *
8935             * @param classNameId the class name ID
8936             * @param classPK the class p k
8937             */
8938            @Override
8939            public void removeByC_C(long classNameId, long classPK) {
8940                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8941                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8942                            remove(mbMessage);
8943                    }
8944            }
8945    
8946            /**
8947             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8948             *
8949             * @param classNameId the class name ID
8950             * @param classPK the class p k
8951             * @return the number of matching message-boards messages
8952             */
8953            @Override
8954            public int countByC_C(long classNameId, long classPK) {
8955                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8956    
8957                    Object[] finderArgs = new Object[] { classNameId, classPK };
8958    
8959                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8960    
8961                    if (count == null) {
8962                            StringBundler query = new StringBundler(3);
8963    
8964                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8965    
8966                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8967    
8968                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8969    
8970                            String sql = query.toString();
8971    
8972                            Session session = null;
8973    
8974                            try {
8975                                    session = openSession();
8976    
8977                                    Query q = session.createQuery(sql);
8978    
8979                                    QueryPos qPos = QueryPos.getInstance(q);
8980    
8981                                    qPos.add(classNameId);
8982    
8983                                    qPos.add(classPK);
8984    
8985                                    count = (Long)q.uniqueResult();
8986    
8987                                    finderCache.putResult(finderPath, finderArgs, count);
8988                            }
8989                            catch (Exception e) {
8990                                    finderCache.removeResult(finderPath, finderArgs);
8991    
8992                                    throw processException(e);
8993                            }
8994                            finally {
8995                                    closeSession(session);
8996                            }
8997                    }
8998    
8999                    return count.intValue();
9000            }
9001    
9002            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
9003            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
9004            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9005                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9006                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
9007                            new String[] {
9008                                    Long.class.getName(), Long.class.getName(),
9009                                    
9010                            Integer.class.getName(), Integer.class.getName(),
9011                                    OrderByComparator.class.getName()
9012                            });
9013            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9014                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9015                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
9016                            new String[] { Long.class.getName(), Long.class.getName() },
9017                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9018                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
9019                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9020            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9021                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9022                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
9023                            new String[] { Long.class.getName(), Long.class.getName() });
9024    
9025            /**
9026             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9027             *
9028             * @param threadId the thread ID
9029             * @param parentMessageId the parent message ID
9030             * @return the matching message-boards messages
9031             */
9032            @Override
9033            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
9034                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
9035                            QueryUtil.ALL_POS, null);
9036            }
9037    
9038            /**
9039             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9040             *
9041             * <p>
9042             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9043             * </p>
9044             *
9045             * @param threadId the thread ID
9046             * @param parentMessageId the parent message ID
9047             * @param start the lower bound of the range of message-boards messages
9048             * @param end the upper bound of the range of message-boards messages (not inclusive)
9049             * @return the range of matching message-boards messages
9050             */
9051            @Override
9052            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9053                    int start, int end) {
9054                    return findByT_P(threadId, parentMessageId, start, end, null);
9055            }
9056    
9057            /**
9058             * Returns an ordered 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             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9069             * @return the ordered range of matching message-boards messages
9070             */
9071            @Override
9072            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9073                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
9074                    return findByT_P(threadId, parentMessageId, start, end,
9075                            orderByComparator, true);
9076            }
9077    
9078            /**
9079             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9080             *
9081             * <p>
9082             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9083             * </p>
9084             *
9085             * @param threadId the thread ID
9086             * @param parentMessageId the parent message ID
9087             * @param start the lower bound of the range of message-boards messages
9088             * @param end the upper bound of the range of message-boards messages (not inclusive)
9089             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9090             * @param retrieveFromCache whether to retrieve from the finder cache
9091             * @return the ordered range of matching message-boards messages
9092             */
9093            @Override
9094            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9095                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
9096                    boolean retrieveFromCache) {
9097                    boolean pagination = true;
9098                    FinderPath finderPath = null;
9099                    Object[] finderArgs = null;
9100    
9101                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9102                                    (orderByComparator == null)) {
9103                            pagination = false;
9104                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
9105                            finderArgs = new Object[] { threadId, parentMessageId };
9106                    }
9107                    else {
9108                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
9109                            finderArgs = new Object[] {
9110                                            threadId, parentMessageId,
9111                                            
9112                                            start, end, orderByComparator
9113                                    };
9114                    }
9115    
9116                    List<MBMessage> list = null;
9117    
9118                    if (retrieveFromCache) {
9119                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9120                                            finderArgs, this);
9121    
9122                            if ((list != null) && !list.isEmpty()) {
9123                                    for (MBMessage mbMessage : list) {
9124                                            if ((threadId != mbMessage.getThreadId()) ||
9125                                                            (parentMessageId != mbMessage.getParentMessageId())) {
9126                                                    list = null;
9127    
9128                                                    break;
9129                                            }
9130                                    }
9131                            }
9132                    }
9133    
9134                    if (list == null) {
9135                            StringBundler query = null;
9136    
9137                            if (orderByComparator != null) {
9138                                    query = new StringBundler(4 +
9139                                                    (orderByComparator.getOrderByFields().length * 3));
9140                            }
9141                            else {
9142                                    query = new StringBundler(4);
9143                            }
9144    
9145                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9146    
9147                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9148    
9149                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9150    
9151                            if (orderByComparator != null) {
9152                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9153                                            orderByComparator);
9154                            }
9155                            else
9156                             if (pagination) {
9157                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9158                            }
9159    
9160                            String sql = query.toString();
9161    
9162                            Session session = null;
9163    
9164                            try {
9165                                    session = openSession();
9166    
9167                                    Query q = session.createQuery(sql);
9168    
9169                                    QueryPos qPos = QueryPos.getInstance(q);
9170    
9171                                    qPos.add(threadId);
9172    
9173                                    qPos.add(parentMessageId);
9174    
9175                                    if (!pagination) {
9176                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9177                                                            start, end, false);
9178    
9179                                            Collections.sort(list);
9180    
9181                                            list = Collections.unmodifiableList(list);
9182                                    }
9183                                    else {
9184                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9185                                                            start, end);
9186                                    }
9187    
9188                                    cacheResult(list);
9189    
9190                                    finderCache.putResult(finderPath, finderArgs, list);
9191                            }
9192                            catch (Exception e) {
9193                                    finderCache.removeResult(finderPath, finderArgs);
9194    
9195                                    throw processException(e);
9196                            }
9197                            finally {
9198                                    closeSession(session);
9199                            }
9200                    }
9201    
9202                    return list;
9203            }
9204    
9205            /**
9206             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9207             *
9208             * @param threadId the thread ID
9209             * @param parentMessageId the parent message ID
9210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9211             * @return the first matching message-boards message
9212             * @throws NoSuchMessageException if a matching message-boards message could not be found
9213             */
9214            @Override
9215            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9216                    OrderByComparator<MBMessage> orderByComparator)
9217                    throws NoSuchMessageException {
9218                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9219                                    orderByComparator);
9220    
9221                    if (mbMessage != null) {
9222                            return mbMessage;
9223                    }
9224    
9225                    StringBundler msg = new StringBundler(6);
9226    
9227                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9228    
9229                    msg.append("threadId=");
9230                    msg.append(threadId);
9231    
9232                    msg.append(", parentMessageId=");
9233                    msg.append(parentMessageId);
9234    
9235                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9236    
9237                    throw new NoSuchMessageException(msg.toString());
9238            }
9239    
9240            /**
9241             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9242             *
9243             * @param threadId the thread ID
9244             * @param parentMessageId the parent message ID
9245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9246             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9247             */
9248            @Override
9249            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9250                    OrderByComparator<MBMessage> orderByComparator) {
9251                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9252                                    orderByComparator);
9253    
9254                    if (!list.isEmpty()) {
9255                            return list.get(0);
9256                    }
9257    
9258                    return null;
9259            }
9260    
9261            /**
9262             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9263             *
9264             * @param threadId the thread ID
9265             * @param parentMessageId the parent message ID
9266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9267             * @return the last matching message-boards message
9268             * @throws NoSuchMessageException if a matching message-boards message could not be found
9269             */
9270            @Override
9271            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9272                    OrderByComparator<MBMessage> orderByComparator)
9273                    throws NoSuchMessageException {
9274                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9275                                    orderByComparator);
9276    
9277                    if (mbMessage != null) {
9278                            return mbMessage;
9279                    }
9280    
9281                    StringBundler msg = new StringBundler(6);
9282    
9283                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9284    
9285                    msg.append("threadId=");
9286                    msg.append(threadId);
9287    
9288                    msg.append(", parentMessageId=");
9289                    msg.append(parentMessageId);
9290    
9291                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9292    
9293                    throw new NoSuchMessageException(msg.toString());
9294            }
9295    
9296            /**
9297             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9298             *
9299             * @param threadId the thread ID
9300             * @param parentMessageId the parent message ID
9301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9302             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9303             */
9304            @Override
9305            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9306                    OrderByComparator<MBMessage> orderByComparator) {
9307                    int count = countByT_P(threadId, parentMessageId);
9308    
9309                    if (count == 0) {
9310                            return null;
9311                    }
9312    
9313                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9314                                    count, orderByComparator);
9315    
9316                    if (!list.isEmpty()) {
9317                            return list.get(0);
9318                    }
9319    
9320                    return null;
9321            }
9322    
9323            /**
9324             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9325             *
9326             * @param messageId the primary key of the current message-boards message
9327             * @param threadId the thread ID
9328             * @param parentMessageId the parent message ID
9329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9330             * @return the previous, current, and next message-boards message
9331             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9332             */
9333            @Override
9334            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9335                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
9336                    throws NoSuchMessageException {
9337                    MBMessage mbMessage = findByPrimaryKey(messageId);
9338    
9339                    Session session = null;
9340    
9341                    try {
9342                            session = openSession();
9343    
9344                            MBMessage[] array = new MBMessageImpl[3];
9345    
9346                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9347                                            parentMessageId, orderByComparator, true);
9348    
9349                            array[1] = mbMessage;
9350    
9351                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9352                                            parentMessageId, orderByComparator, false);
9353    
9354                            return array;
9355                    }
9356                    catch (Exception e) {
9357                            throw processException(e);
9358                    }
9359                    finally {
9360                            closeSession(session);
9361                    }
9362            }
9363    
9364            protected MBMessage getByT_P_PrevAndNext(Session session,
9365                    MBMessage mbMessage, long threadId, long parentMessageId,
9366                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9367                    StringBundler query = null;
9368    
9369                    if (orderByComparator != null) {
9370                            query = new StringBundler(6 +
9371                                            (orderByComparator.getOrderByFields().length * 6));
9372                    }
9373                    else {
9374                            query = new StringBundler(3);
9375                    }
9376    
9377                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9378    
9379                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9380    
9381                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9382    
9383                    if (orderByComparator != null) {
9384                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9385    
9386                            if (orderByConditionFields.length > 0) {
9387                                    query.append(WHERE_AND);
9388                            }
9389    
9390                            for (int i = 0; i < orderByConditionFields.length; i++) {
9391                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9392                                    query.append(orderByConditionFields[i]);
9393    
9394                                    if ((i + 1) < orderByConditionFields.length) {
9395                                            if (orderByComparator.isAscending() ^ previous) {
9396                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9397                                            }
9398                                            else {
9399                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9400                                            }
9401                                    }
9402                                    else {
9403                                            if (orderByComparator.isAscending() ^ previous) {
9404                                                    query.append(WHERE_GREATER_THAN);
9405                                            }
9406                                            else {
9407                                                    query.append(WHERE_LESSER_THAN);
9408                                            }
9409                                    }
9410                            }
9411    
9412                            query.append(ORDER_BY_CLAUSE);
9413    
9414                            String[] orderByFields = orderByComparator.getOrderByFields();
9415    
9416                            for (int i = 0; i < orderByFields.length; i++) {
9417                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9418                                    query.append(orderByFields[i]);
9419    
9420                                    if ((i + 1) < orderByFields.length) {
9421                                            if (orderByComparator.isAscending() ^ previous) {
9422                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9423                                            }
9424                                            else {
9425                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9426                                            }
9427                                    }
9428                                    else {
9429                                            if (orderByComparator.isAscending() ^ previous) {
9430                                                    query.append(ORDER_BY_ASC);
9431                                            }
9432                                            else {
9433                                                    query.append(ORDER_BY_DESC);
9434                                            }
9435                                    }
9436                            }
9437                    }
9438                    else {
9439                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9440                    }
9441    
9442                    String sql = query.toString();
9443    
9444                    Query q = session.createQuery(sql);
9445    
9446                    q.setFirstResult(0);
9447                    q.setMaxResults(2);
9448    
9449                    QueryPos qPos = QueryPos.getInstance(q);
9450    
9451                    qPos.add(threadId);
9452    
9453                    qPos.add(parentMessageId);
9454    
9455                    if (orderByComparator != null) {
9456                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9457    
9458                            for (Object value : values) {
9459                                    qPos.add(value);
9460                            }
9461                    }
9462    
9463                    List<MBMessage> list = q.list();
9464    
9465                    if (list.size() == 2) {
9466                            return list.get(1);
9467                    }
9468                    else {
9469                            return null;
9470                    }
9471            }
9472    
9473            /**
9474             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9475             *
9476             * @param threadId the thread ID
9477             * @param parentMessageId the parent message ID
9478             */
9479            @Override
9480            public void removeByT_P(long threadId, long parentMessageId) {
9481                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9482                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9483                            remove(mbMessage);
9484                    }
9485            }
9486    
9487            /**
9488             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9489             *
9490             * @param threadId the thread ID
9491             * @param parentMessageId the parent message ID
9492             * @return the number of matching message-boards messages
9493             */
9494            @Override
9495            public int countByT_P(long threadId, long parentMessageId) {
9496                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9497    
9498                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9499    
9500                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9501    
9502                    if (count == null) {
9503                            StringBundler query = new StringBundler(3);
9504    
9505                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9506    
9507                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9508    
9509                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9510    
9511                            String sql = query.toString();
9512    
9513                            Session session = null;
9514    
9515                            try {
9516                                    session = openSession();
9517    
9518                                    Query q = session.createQuery(sql);
9519    
9520                                    QueryPos qPos = QueryPos.getInstance(q);
9521    
9522                                    qPos.add(threadId);
9523    
9524                                    qPos.add(parentMessageId);
9525    
9526                                    count = (Long)q.uniqueResult();
9527    
9528                                    finderCache.putResult(finderPath, finderArgs, count);
9529                            }
9530                            catch (Exception e) {
9531                                    finderCache.removeResult(finderPath, finderArgs);
9532    
9533                                    throw processException(e);
9534                            }
9535                            finally {
9536                                    closeSession(session);
9537                            }
9538                    }
9539    
9540                    return count.intValue();
9541            }
9542    
9543            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9544            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9545            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9546                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9547                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9548                            new String[] {
9549                                    Long.class.getName(), Boolean.class.getName(),
9550                                    
9551                            Integer.class.getName(), Integer.class.getName(),
9552                                    OrderByComparator.class.getName()
9553                            });
9554            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9555                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9556                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9557                            new String[] { Long.class.getName(), Boolean.class.getName() },
9558                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9559                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9560                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9561            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9562                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9563                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9564                            new String[] { Long.class.getName(), Boolean.class.getName() });
9565    
9566            /**
9567             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9568             *
9569             * @param threadId the thread ID
9570             * @param answer the answer
9571             * @return the matching message-boards messages
9572             */
9573            @Override
9574            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9575                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9576                            QueryUtil.ALL_POS, null);
9577            }
9578    
9579            /**
9580             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9581             *
9582             * <p>
9583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9584             * </p>
9585             *
9586             * @param threadId the thread ID
9587             * @param answer the answer
9588             * @param start the lower bound of the range of message-boards messages
9589             * @param end the upper bound of the range of message-boards messages (not inclusive)
9590             * @return the range of matching message-boards messages
9591             */
9592            @Override
9593            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9594                    int end) {
9595                    return findByT_A(threadId, answer, start, end, null);
9596            }
9597    
9598            /**
9599             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9600             *
9601             * <p>
9602             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9603             * </p>
9604             *
9605             * @param threadId the thread ID
9606             * @param answer the answer
9607             * @param start the lower bound of the range of message-boards messages
9608             * @param end the upper bound of the range of message-boards messages (not inclusive)
9609             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9610             * @return the ordered range of matching message-boards messages
9611             */
9612            @Override
9613            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9614                    int end, OrderByComparator<MBMessage> orderByComparator) {
9615                    return findByT_A(threadId, answer, start, end, orderByComparator, true);
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             * @param retrieveFromCache whether to retrieve from the finder cache
9631             * @return the ordered range of matching message-boards messages
9632             */
9633            @Override
9634            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9635                    int end, OrderByComparator<MBMessage> orderByComparator,
9636                    boolean retrieveFromCache) {
9637                    boolean pagination = true;
9638                    FinderPath finderPath = null;
9639                    Object[] finderArgs = null;
9640    
9641                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9642                                    (orderByComparator == null)) {
9643                            pagination = false;
9644                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9645                            finderArgs = new Object[] { threadId, answer };
9646                    }
9647                    else {
9648                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9649                            finderArgs = new Object[] {
9650                                            threadId, answer,
9651                                            
9652                                            start, end, orderByComparator
9653                                    };
9654                    }
9655    
9656                    List<MBMessage> list = null;
9657    
9658                    if (retrieveFromCache) {
9659                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9660                                            finderArgs, this);
9661    
9662                            if ((list != null) && !list.isEmpty()) {
9663                                    for (MBMessage mbMessage : list) {
9664                                            if ((threadId != mbMessage.getThreadId()) ||
9665                                                            (answer != mbMessage.getAnswer())) {
9666                                                    list = null;
9667    
9668                                                    break;
9669                                            }
9670                                    }
9671                            }
9672                    }
9673    
9674                    if (list == null) {
9675                            StringBundler query = null;
9676    
9677                            if (orderByComparator != null) {
9678                                    query = new StringBundler(4 +
9679                                                    (orderByComparator.getOrderByFields().length * 3));
9680                            }
9681                            else {
9682                                    query = new StringBundler(4);
9683                            }
9684    
9685                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9686    
9687                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9688    
9689                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9690    
9691                            if (orderByComparator != null) {
9692                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9693                                            orderByComparator);
9694                            }
9695                            else
9696                             if (pagination) {
9697                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9698                            }
9699    
9700                            String sql = query.toString();
9701    
9702                            Session session = null;
9703    
9704                            try {
9705                                    session = openSession();
9706    
9707                                    Query q = session.createQuery(sql);
9708    
9709                                    QueryPos qPos = QueryPos.getInstance(q);
9710    
9711                                    qPos.add(threadId);
9712    
9713                                    qPos.add(answer);
9714    
9715                                    if (!pagination) {
9716                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9717                                                            start, end, false);
9718    
9719                                            Collections.sort(list);
9720    
9721                                            list = Collections.unmodifiableList(list);
9722                                    }
9723                                    else {
9724                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9725                                                            start, end);
9726                                    }
9727    
9728                                    cacheResult(list);
9729    
9730                                    finderCache.putResult(finderPath, finderArgs, list);
9731                            }
9732                            catch (Exception e) {
9733                                    finderCache.removeResult(finderPath, finderArgs);
9734    
9735                                    throw processException(e);
9736                            }
9737                            finally {
9738                                    closeSession(session);
9739                            }
9740                    }
9741    
9742                    return list;
9743            }
9744    
9745            /**
9746             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9747             *
9748             * @param threadId the thread ID
9749             * @param answer the answer
9750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9751             * @return the first matching message-boards message
9752             * @throws NoSuchMessageException if a matching message-boards message could not be found
9753             */
9754            @Override
9755            public MBMessage findByT_A_First(long threadId, boolean answer,
9756                    OrderByComparator<MBMessage> orderByComparator)
9757                    throws NoSuchMessageException {
9758                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9759                                    orderByComparator);
9760    
9761                    if (mbMessage != null) {
9762                            return mbMessage;
9763                    }
9764    
9765                    StringBundler msg = new StringBundler(6);
9766    
9767                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9768    
9769                    msg.append("threadId=");
9770                    msg.append(threadId);
9771    
9772                    msg.append(", answer=");
9773                    msg.append(answer);
9774    
9775                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9776    
9777                    throw new NoSuchMessageException(msg.toString());
9778            }
9779    
9780            /**
9781             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9782             *
9783             * @param threadId the thread ID
9784             * @param answer the answer
9785             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9786             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9787             */
9788            @Override
9789            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9790                    OrderByComparator<MBMessage> orderByComparator) {
9791                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9792                                    orderByComparator);
9793    
9794                    if (!list.isEmpty()) {
9795                            return list.get(0);
9796                    }
9797    
9798                    return null;
9799            }
9800    
9801            /**
9802             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9803             *
9804             * @param threadId the thread ID
9805             * @param answer the answer
9806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9807             * @return the last matching message-boards message
9808             * @throws NoSuchMessageException if a matching message-boards message could not be found
9809             */
9810            @Override
9811            public MBMessage findByT_A_Last(long threadId, boolean answer,
9812                    OrderByComparator<MBMessage> orderByComparator)
9813                    throws NoSuchMessageException {
9814                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9815                                    orderByComparator);
9816    
9817                    if (mbMessage != null) {
9818                            return mbMessage;
9819                    }
9820    
9821                    StringBundler msg = new StringBundler(6);
9822    
9823                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9824    
9825                    msg.append("threadId=");
9826                    msg.append(threadId);
9827    
9828                    msg.append(", answer=");
9829                    msg.append(answer);
9830    
9831                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9832    
9833                    throw new NoSuchMessageException(msg.toString());
9834            }
9835    
9836            /**
9837             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9838             *
9839             * @param threadId the thread ID
9840             * @param answer the answer
9841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9842             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9843             */
9844            @Override
9845            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9846                    OrderByComparator<MBMessage> orderByComparator) {
9847                    int count = countByT_A(threadId, answer);
9848    
9849                    if (count == 0) {
9850                            return null;
9851                    }
9852    
9853                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9854                                    orderByComparator);
9855    
9856                    if (!list.isEmpty()) {
9857                            return list.get(0);
9858                    }
9859    
9860                    return null;
9861            }
9862    
9863            /**
9864             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9865             *
9866             * @param messageId the primary key of the current message-boards message
9867             * @param threadId the thread ID
9868             * @param answer the answer
9869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9870             * @return the previous, current, and next message-boards message
9871             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9872             */
9873            @Override
9874            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9875                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9876                    throws NoSuchMessageException {
9877                    MBMessage mbMessage = findByPrimaryKey(messageId);
9878    
9879                    Session session = null;
9880    
9881                    try {
9882                            session = openSession();
9883    
9884                            MBMessage[] array = new MBMessageImpl[3];
9885    
9886                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9887                                            answer, orderByComparator, true);
9888    
9889                            array[1] = mbMessage;
9890    
9891                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9892                                            answer, orderByComparator, false);
9893    
9894                            return array;
9895                    }
9896                    catch (Exception e) {
9897                            throw processException(e);
9898                    }
9899                    finally {
9900                            closeSession(session);
9901                    }
9902            }
9903    
9904            protected MBMessage getByT_A_PrevAndNext(Session session,
9905                    MBMessage mbMessage, long threadId, boolean answer,
9906                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9907                    StringBundler query = null;
9908    
9909                    if (orderByComparator != null) {
9910                            query = new StringBundler(6 +
9911                                            (orderByComparator.getOrderByFields().length * 6));
9912                    }
9913                    else {
9914                            query = new StringBundler(3);
9915                    }
9916    
9917                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9918    
9919                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9920    
9921                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9922    
9923                    if (orderByComparator != null) {
9924                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9925    
9926                            if (orderByConditionFields.length > 0) {
9927                                    query.append(WHERE_AND);
9928                            }
9929    
9930                            for (int i = 0; i < orderByConditionFields.length; i++) {
9931                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9932                                    query.append(orderByConditionFields[i]);
9933    
9934                                    if ((i + 1) < orderByConditionFields.length) {
9935                                            if (orderByComparator.isAscending() ^ previous) {
9936                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9937                                            }
9938                                            else {
9939                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9940                                            }
9941                                    }
9942                                    else {
9943                                            if (orderByComparator.isAscending() ^ previous) {
9944                                                    query.append(WHERE_GREATER_THAN);
9945                                            }
9946                                            else {
9947                                                    query.append(WHERE_LESSER_THAN);
9948                                            }
9949                                    }
9950                            }
9951    
9952                            query.append(ORDER_BY_CLAUSE);
9953    
9954                            String[] orderByFields = orderByComparator.getOrderByFields();
9955    
9956                            for (int i = 0; i < orderByFields.length; i++) {
9957                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9958                                    query.append(orderByFields[i]);
9959    
9960                                    if ((i + 1) < orderByFields.length) {
9961                                            if (orderByComparator.isAscending() ^ previous) {
9962                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9963                                            }
9964                                            else {
9965                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9966                                            }
9967                                    }
9968                                    else {
9969                                            if (orderByComparator.isAscending() ^ previous) {
9970                                                    query.append(ORDER_BY_ASC);
9971                                            }
9972                                            else {
9973                                                    query.append(ORDER_BY_DESC);
9974                                            }
9975                                    }
9976                            }
9977                    }
9978                    else {
9979                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9980                    }
9981    
9982                    String sql = query.toString();
9983    
9984                    Query q = session.createQuery(sql);
9985    
9986                    q.setFirstResult(0);
9987                    q.setMaxResults(2);
9988    
9989                    QueryPos qPos = QueryPos.getInstance(q);
9990    
9991                    qPos.add(threadId);
9992    
9993                    qPos.add(answer);
9994    
9995                    if (orderByComparator != null) {
9996                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9997    
9998                            for (Object value : values) {
9999                                    qPos.add(value);
10000                            }
10001                    }
10002    
10003                    List<MBMessage> list = q.list();
10004    
10005                    if (list.size() == 2) {
10006                            return list.get(1);
10007                    }
10008                    else {
10009                            return null;
10010                    }
10011            }
10012    
10013            /**
10014             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
10015             *
10016             * @param threadId the thread ID
10017             * @param answer the answer
10018             */
10019            @Override
10020            public void removeByT_A(long threadId, boolean answer) {
10021                    for (MBMessage mbMessage : findByT_A(threadId, answer,
10022                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10023                            remove(mbMessage);
10024                    }
10025            }
10026    
10027            /**
10028             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
10029             *
10030             * @param threadId the thread ID
10031             * @param answer the answer
10032             * @return the number of matching message-boards messages
10033             */
10034            @Override
10035            public int countByT_A(long threadId, boolean answer) {
10036                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
10037    
10038                    Object[] finderArgs = new Object[] { threadId, answer };
10039    
10040                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10041    
10042                    if (count == null) {
10043                            StringBundler query = new StringBundler(3);
10044    
10045                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10046    
10047                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
10048    
10049                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
10050    
10051                            String sql = query.toString();
10052    
10053                            Session session = null;
10054    
10055                            try {
10056                                    session = openSession();
10057    
10058                                    Query q = session.createQuery(sql);
10059    
10060                                    QueryPos qPos = QueryPos.getInstance(q);
10061    
10062                                    qPos.add(threadId);
10063    
10064                                    qPos.add(answer);
10065    
10066                                    count = (Long)q.uniqueResult();
10067    
10068                                    finderCache.putResult(finderPath, finderArgs, count);
10069                            }
10070                            catch (Exception e) {
10071                                    finderCache.removeResult(finderPath, finderArgs);
10072    
10073                                    throw processException(e);
10074                            }
10075                            finally {
10076                                    closeSession(session);
10077                            }
10078                    }
10079    
10080                    return count.intValue();
10081            }
10082    
10083            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
10084            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
10085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10086                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
10088                            new String[] {
10089                                    Long.class.getName(), Integer.class.getName(),
10090                                    
10091                            Integer.class.getName(), Integer.class.getName(),
10092                                    OrderByComparator.class.getName()
10093                            });
10094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10095                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
10097                            new String[] { Long.class.getName(), Integer.class.getName() },
10098                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10099                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10100                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10101            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
10104                            new String[] { Long.class.getName(), Integer.class.getName() });
10105    
10106            /**
10107             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10108             *
10109             * @param threadId the thread ID
10110             * @param status the status
10111             * @return the matching message-boards messages
10112             */
10113            @Override
10114            public List<MBMessage> findByT_S(long threadId, int status) {
10115                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
10116                            QueryUtil.ALL_POS, null);
10117            }
10118    
10119            /**
10120             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10121             *
10122             * <p>
10123             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10124             * </p>
10125             *
10126             * @param threadId the thread ID
10127             * @param status the status
10128             * @param start the lower bound of the range of message-boards messages
10129             * @param end the upper bound of the range of message-boards messages (not inclusive)
10130             * @return the range of matching message-boards messages
10131             */
10132            @Override
10133            public List<MBMessage> findByT_S(long threadId, int status, int start,
10134                    int end) {
10135                    return findByT_S(threadId, status, start, end, null);
10136            }
10137    
10138            /**
10139             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10140             *
10141             * <p>
10142             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10143             * </p>
10144             *
10145             * @param threadId the thread ID
10146             * @param status the status
10147             * @param start the lower bound of the range of message-boards messages
10148             * @param end the upper bound of the range of message-boards messages (not inclusive)
10149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10150             * @return the ordered range of matching message-boards messages
10151             */
10152            @Override
10153            public List<MBMessage> findByT_S(long threadId, int status, int start,
10154                    int end, OrderByComparator<MBMessage> orderByComparator) {
10155                    return findByT_S(threadId, status, start, end, orderByComparator, true);
10156            }
10157    
10158            /**
10159             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10160             *
10161             * <p>
10162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10163             * </p>
10164             *
10165             * @param threadId the thread ID
10166             * @param status the status
10167             * @param start the lower bound of the range of message-boards messages
10168             * @param end the upper bound of the range of message-boards messages (not inclusive)
10169             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10170             * @param retrieveFromCache whether to retrieve from the finder cache
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                    boolean retrieveFromCache) {
10177                    boolean pagination = true;
10178                    FinderPath finderPath = null;
10179                    Object[] finderArgs = null;
10180    
10181                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10182                                    (orderByComparator == null)) {
10183                            pagination = false;
10184                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10185                            finderArgs = new Object[] { threadId, status };
10186                    }
10187                    else {
10188                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10189                            finderArgs = new Object[] {
10190                                            threadId, status,
10191                                            
10192                                            start, end, orderByComparator
10193                                    };
10194                    }
10195    
10196                    List<MBMessage> list = null;
10197    
10198                    if (retrieveFromCache) {
10199                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10200                                            finderArgs, this);
10201    
10202                            if ((list != null) && !list.isEmpty()) {
10203                                    for (MBMessage mbMessage : list) {
10204                                            if ((threadId != mbMessage.getThreadId()) ||
10205                                                            (status != mbMessage.getStatus())) {
10206                                                    list = null;
10207    
10208                                                    break;
10209                                            }
10210                                    }
10211                            }
10212                    }
10213    
10214                    if (list == null) {
10215                            StringBundler query = null;
10216    
10217                            if (orderByComparator != null) {
10218                                    query = new StringBundler(4 +
10219                                                    (orderByComparator.getOrderByFields().length * 3));
10220                            }
10221                            else {
10222                                    query = new StringBundler(4);
10223                            }
10224    
10225                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10226    
10227                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10228    
10229                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10230    
10231                            if (orderByComparator != null) {
10232                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10233                                            orderByComparator);
10234                            }
10235                            else
10236                             if (pagination) {
10237                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10238                            }
10239    
10240                            String sql = query.toString();
10241    
10242                            Session session = null;
10243    
10244                            try {
10245                                    session = openSession();
10246    
10247                                    Query q = session.createQuery(sql);
10248    
10249                                    QueryPos qPos = QueryPos.getInstance(q);
10250    
10251                                    qPos.add(threadId);
10252    
10253                                    qPos.add(status);
10254    
10255                                    if (!pagination) {
10256                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10257                                                            start, end, false);
10258    
10259                                            Collections.sort(list);
10260    
10261                                            list = Collections.unmodifiableList(list);
10262                                    }
10263                                    else {
10264                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10265                                                            start, end);
10266                                    }
10267    
10268                                    cacheResult(list);
10269    
10270                                    finderCache.putResult(finderPath, finderArgs, list);
10271                            }
10272                            catch (Exception e) {
10273                                    finderCache.removeResult(finderPath, finderArgs);
10274    
10275                                    throw processException(e);
10276                            }
10277                            finally {
10278                                    closeSession(session);
10279                            }
10280                    }
10281    
10282                    return list;
10283            }
10284    
10285            /**
10286             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10287             *
10288             * @param threadId the thread ID
10289             * @param status the status
10290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10291             * @return the first matching message-boards message
10292             * @throws NoSuchMessageException if a matching message-boards message could not be found
10293             */
10294            @Override
10295            public MBMessage findByT_S_First(long threadId, int status,
10296                    OrderByComparator<MBMessage> orderByComparator)
10297                    throws NoSuchMessageException {
10298                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10299                                    orderByComparator);
10300    
10301                    if (mbMessage != null) {
10302                            return mbMessage;
10303                    }
10304    
10305                    StringBundler msg = new StringBundler(6);
10306    
10307                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10308    
10309                    msg.append("threadId=");
10310                    msg.append(threadId);
10311    
10312                    msg.append(", status=");
10313                    msg.append(status);
10314    
10315                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10316    
10317                    throw new NoSuchMessageException(msg.toString());
10318            }
10319    
10320            /**
10321             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10322             *
10323             * @param threadId the thread ID
10324             * @param status the status
10325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10326             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10327             */
10328            @Override
10329            public MBMessage fetchByT_S_First(long threadId, int status,
10330                    OrderByComparator<MBMessage> orderByComparator) {
10331                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10332                                    orderByComparator);
10333    
10334                    if (!list.isEmpty()) {
10335                            return list.get(0);
10336                    }
10337    
10338                    return null;
10339            }
10340    
10341            /**
10342             * Returns the last 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 last matching message-boards message
10348             * @throws NoSuchMessageException if a matching message-boards message could not be found
10349             */
10350            @Override
10351            public MBMessage findByT_S_Last(long threadId, int status,
10352                    OrderByComparator<MBMessage> orderByComparator)
10353                    throws NoSuchMessageException {
10354                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10355                                    orderByComparator);
10356    
10357                    if (mbMessage != null) {
10358                            return mbMessage;
10359                    }
10360    
10361                    StringBundler msg = new StringBundler(6);
10362    
10363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10364    
10365                    msg.append("threadId=");
10366                    msg.append(threadId);
10367    
10368                    msg.append(", status=");
10369                    msg.append(status);
10370    
10371                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10372    
10373                    throw new NoSuchMessageException(msg.toString());
10374            }
10375    
10376            /**
10377             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10378             *
10379             * @param threadId the thread ID
10380             * @param status the status
10381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10382             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10383             */
10384            @Override
10385            public MBMessage fetchByT_S_Last(long threadId, int status,
10386                    OrderByComparator<MBMessage> orderByComparator) {
10387                    int count = countByT_S(threadId, status);
10388    
10389                    if (count == 0) {
10390                            return null;
10391                    }
10392    
10393                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10394                                    orderByComparator);
10395    
10396                    if (!list.isEmpty()) {
10397                            return list.get(0);
10398                    }
10399    
10400                    return null;
10401            }
10402    
10403            /**
10404             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10405             *
10406             * @param messageId the primary key of the current message-boards message
10407             * @param threadId the thread ID
10408             * @param status the status
10409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10410             * @return the previous, current, and next message-boards message
10411             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10412             */
10413            @Override
10414            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10415                    int status, OrderByComparator<MBMessage> orderByComparator)
10416                    throws NoSuchMessageException {
10417                    MBMessage mbMessage = findByPrimaryKey(messageId);
10418    
10419                    Session session = null;
10420    
10421                    try {
10422                            session = openSession();
10423    
10424                            MBMessage[] array = new MBMessageImpl[3];
10425    
10426                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10427                                            status, orderByComparator, true);
10428    
10429                            array[1] = mbMessage;
10430    
10431                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10432                                            status, orderByComparator, false);
10433    
10434                            return array;
10435                    }
10436                    catch (Exception e) {
10437                            throw processException(e);
10438                    }
10439                    finally {
10440                            closeSession(session);
10441                    }
10442            }
10443    
10444            protected MBMessage getByT_S_PrevAndNext(Session session,
10445                    MBMessage mbMessage, long threadId, int status,
10446                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10447                    StringBundler query = null;
10448    
10449                    if (orderByComparator != null) {
10450                            query = new StringBundler(6 +
10451                                            (orderByComparator.getOrderByFields().length * 6));
10452                    }
10453                    else {
10454                            query = new StringBundler(3);
10455                    }
10456    
10457                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10458    
10459                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10460    
10461                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10462    
10463                    if (orderByComparator != null) {
10464                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10465    
10466                            if (orderByConditionFields.length > 0) {
10467                                    query.append(WHERE_AND);
10468                            }
10469    
10470                            for (int i = 0; i < orderByConditionFields.length; i++) {
10471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10472                                    query.append(orderByConditionFields[i]);
10473    
10474                                    if ((i + 1) < orderByConditionFields.length) {
10475                                            if (orderByComparator.isAscending() ^ previous) {
10476                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10477                                            }
10478                                            else {
10479                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10480                                            }
10481                                    }
10482                                    else {
10483                                            if (orderByComparator.isAscending() ^ previous) {
10484                                                    query.append(WHERE_GREATER_THAN);
10485                                            }
10486                                            else {
10487                                                    query.append(WHERE_LESSER_THAN);
10488                                            }
10489                                    }
10490                            }
10491    
10492                            query.append(ORDER_BY_CLAUSE);
10493    
10494                            String[] orderByFields = orderByComparator.getOrderByFields();
10495    
10496                            for (int i = 0; i < orderByFields.length; i++) {
10497                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10498                                    query.append(orderByFields[i]);
10499    
10500                                    if ((i + 1) < orderByFields.length) {
10501                                            if (orderByComparator.isAscending() ^ previous) {
10502                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10503                                            }
10504                                            else {
10505                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10506                                            }
10507                                    }
10508                                    else {
10509                                            if (orderByComparator.isAscending() ^ previous) {
10510                                                    query.append(ORDER_BY_ASC);
10511                                            }
10512                                            else {
10513                                                    query.append(ORDER_BY_DESC);
10514                                            }
10515                                    }
10516                            }
10517                    }
10518                    else {
10519                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10520                    }
10521    
10522                    String sql = query.toString();
10523    
10524                    Query q = session.createQuery(sql);
10525    
10526                    q.setFirstResult(0);
10527                    q.setMaxResults(2);
10528    
10529                    QueryPos qPos = QueryPos.getInstance(q);
10530    
10531                    qPos.add(threadId);
10532    
10533                    qPos.add(status);
10534    
10535                    if (orderByComparator != null) {
10536                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10537    
10538                            for (Object value : values) {
10539                                    qPos.add(value);
10540                            }
10541                    }
10542    
10543                    List<MBMessage> list = q.list();
10544    
10545                    if (list.size() == 2) {
10546                            return list.get(1);
10547                    }
10548                    else {
10549                            return null;
10550                    }
10551            }
10552    
10553            /**
10554             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10555             *
10556             * @param threadId the thread ID
10557             * @param status the status
10558             */
10559            @Override
10560            public void removeByT_S(long threadId, int status) {
10561                    for (MBMessage mbMessage : findByT_S(threadId, status,
10562                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10563                            remove(mbMessage);
10564                    }
10565            }
10566    
10567            /**
10568             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10569             *
10570             * @param threadId the thread ID
10571             * @param status the status
10572             * @return the number of matching message-boards messages
10573             */
10574            @Override
10575            public int countByT_S(long threadId, int status) {
10576                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10577    
10578                    Object[] finderArgs = new Object[] { threadId, status };
10579    
10580                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10581    
10582                    if (count == null) {
10583                            StringBundler query = new StringBundler(3);
10584    
10585                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10586    
10587                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10588    
10589                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10590    
10591                            String sql = query.toString();
10592    
10593                            Session session = null;
10594    
10595                            try {
10596                                    session = openSession();
10597    
10598                                    Query q = session.createQuery(sql);
10599    
10600                                    QueryPos qPos = QueryPos.getInstance(q);
10601    
10602                                    qPos.add(threadId);
10603    
10604                                    qPos.add(status);
10605    
10606                                    count = (Long)q.uniqueResult();
10607    
10608                                    finderCache.putResult(finderPath, finderArgs, count);
10609                            }
10610                            catch (Exception e) {
10611                                    finderCache.removeResult(finderPath, finderArgs);
10612    
10613                                    throw processException(e);
10614                            }
10615                            finally {
10616                                    closeSession(session);
10617                            }
10618                    }
10619    
10620                    return count.intValue();
10621            }
10622    
10623            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10624            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10625            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10626                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10627                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10628                            new String[] {
10629                                    Long.class.getName(), Integer.class.getName(),
10630                                    
10631                            Integer.class.getName(), Integer.class.getName(),
10632                                    OrderByComparator.class.getName()
10633                            });
10634            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10635                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10636                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10637                            new String[] { Long.class.getName(), Integer.class.getName() },
10638                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10639                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10640                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10641            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10642                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10643                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10644                            new String[] { Long.class.getName(), Integer.class.getName() });
10645    
10646            /**
10647             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10648             *
10649             * @param threadId the thread ID
10650             * @param status the status
10651             * @return the matching message-boards messages
10652             */
10653            @Override
10654            public List<MBMessage> findByTR_S(long threadId, int status) {
10655                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10656                            QueryUtil.ALL_POS, null);
10657            }
10658    
10659            /**
10660             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10661             *
10662             * <p>
10663             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10664             * </p>
10665             *
10666             * @param threadId the thread ID
10667             * @param status the status
10668             * @param start the lower bound of the range of message-boards messages
10669             * @param end the upper bound of the range of message-boards messages (not inclusive)
10670             * @return the range of matching message-boards messages
10671             */
10672            @Override
10673            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10674                    int end) {
10675                    return findByTR_S(threadId, status, start, end, null);
10676            }
10677    
10678            /**
10679             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10680             *
10681             * <p>
10682             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10683             * </p>
10684             *
10685             * @param threadId the thread ID
10686             * @param status the status
10687             * @param start the lower bound of the range of message-boards messages
10688             * @param end the upper bound of the range of message-boards messages (not inclusive)
10689             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10690             * @return the ordered range of matching message-boards messages
10691             */
10692            @Override
10693            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10694                    int end, OrderByComparator<MBMessage> orderByComparator) {
10695                    return findByTR_S(threadId, status, start, end, orderByComparator, true);
10696            }
10697    
10698            /**
10699             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10700             *
10701             * <p>
10702             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10703             * </p>
10704             *
10705             * @param threadId the thread ID
10706             * @param status the status
10707             * @param start the lower bound of the range of message-boards messages
10708             * @param end the upper bound of the range of message-boards messages (not inclusive)
10709             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10710             * @param retrieveFromCache whether to retrieve from the finder cache
10711             * @return the ordered range of matching message-boards messages
10712             */
10713            @Override
10714            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10715                    int end, OrderByComparator<MBMessage> orderByComparator,
10716                    boolean retrieveFromCache) {
10717                    boolean pagination = true;
10718                    FinderPath finderPath = null;
10719                    Object[] finderArgs = null;
10720    
10721                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10722                                    (orderByComparator == null)) {
10723                            pagination = false;
10724                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10725                            finderArgs = new Object[] { threadId, status };
10726                    }
10727                    else {
10728                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10729                            finderArgs = new Object[] {
10730                                            threadId, status,
10731                                            
10732                                            start, end, orderByComparator
10733                                    };
10734                    }
10735    
10736                    List<MBMessage> list = null;
10737    
10738                    if (retrieveFromCache) {
10739                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10740                                            finderArgs, this);
10741    
10742                            if ((list != null) && !list.isEmpty()) {
10743                                    for (MBMessage mbMessage : list) {
10744                                            if ((threadId != mbMessage.getThreadId()) ||
10745                                                            (status != mbMessage.getStatus())) {
10746                                                    list = null;
10747    
10748                                                    break;
10749                                            }
10750                                    }
10751                            }
10752                    }
10753    
10754                    if (list == null) {
10755                            StringBundler query = null;
10756    
10757                            if (orderByComparator != null) {
10758                                    query = new StringBundler(4 +
10759                                                    (orderByComparator.getOrderByFields().length * 3));
10760                            }
10761                            else {
10762                                    query = new StringBundler(4);
10763                            }
10764    
10765                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10766    
10767                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10768    
10769                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10770    
10771                            if (orderByComparator != null) {
10772                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10773                                            orderByComparator);
10774                            }
10775                            else
10776                             if (pagination) {
10777                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10778                            }
10779    
10780                            String sql = query.toString();
10781    
10782                            Session session = null;
10783    
10784                            try {
10785                                    session = openSession();
10786    
10787                                    Query q = session.createQuery(sql);
10788    
10789                                    QueryPos qPos = QueryPos.getInstance(q);
10790    
10791                                    qPos.add(threadId);
10792    
10793                                    qPos.add(status);
10794    
10795                                    if (!pagination) {
10796                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10797                                                            start, end, false);
10798    
10799                                            Collections.sort(list);
10800    
10801                                            list = Collections.unmodifiableList(list);
10802                                    }
10803                                    else {
10804                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10805                                                            start, end);
10806                                    }
10807    
10808                                    cacheResult(list);
10809    
10810                                    finderCache.putResult(finderPath, finderArgs, list);
10811                            }
10812                            catch (Exception e) {
10813                                    finderCache.removeResult(finderPath, finderArgs);
10814    
10815                                    throw processException(e);
10816                            }
10817                            finally {
10818                                    closeSession(session);
10819                            }
10820                    }
10821    
10822                    return list;
10823            }
10824    
10825            /**
10826             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10827             *
10828             * @param threadId the thread ID
10829             * @param status the status
10830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10831             * @return the first matching message-boards message
10832             * @throws NoSuchMessageException if a matching message-boards message could not be found
10833             */
10834            @Override
10835            public MBMessage findByTR_S_First(long threadId, int status,
10836                    OrderByComparator<MBMessage> orderByComparator)
10837                    throws NoSuchMessageException {
10838                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10839                                    orderByComparator);
10840    
10841                    if (mbMessage != null) {
10842                            return mbMessage;
10843                    }
10844    
10845                    StringBundler msg = new StringBundler(6);
10846    
10847                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10848    
10849                    msg.append("threadId=");
10850                    msg.append(threadId);
10851    
10852                    msg.append(", status=");
10853                    msg.append(status);
10854    
10855                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10856    
10857                    throw new NoSuchMessageException(msg.toString());
10858            }
10859    
10860            /**
10861             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10862             *
10863             * @param threadId the thread ID
10864             * @param status the status
10865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10866             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10867             */
10868            @Override
10869            public MBMessage fetchByTR_S_First(long threadId, int status,
10870                    OrderByComparator<MBMessage> orderByComparator) {
10871                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10872                                    orderByComparator);
10873    
10874                    if (!list.isEmpty()) {
10875                            return list.get(0);
10876                    }
10877    
10878                    return null;
10879            }
10880    
10881            /**
10882             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10883             *
10884             * @param threadId the thread ID
10885             * @param status the status
10886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10887             * @return the last matching message-boards message
10888             * @throws NoSuchMessageException if a matching message-boards message could not be found
10889             */
10890            @Override
10891            public MBMessage findByTR_S_Last(long threadId, int status,
10892                    OrderByComparator<MBMessage> orderByComparator)
10893                    throws NoSuchMessageException {
10894                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10895                                    orderByComparator);
10896    
10897                    if (mbMessage != null) {
10898                            return mbMessage;
10899                    }
10900    
10901                    StringBundler msg = new StringBundler(6);
10902    
10903                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10904    
10905                    msg.append("threadId=");
10906                    msg.append(threadId);
10907    
10908                    msg.append(", status=");
10909                    msg.append(status);
10910    
10911                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10912    
10913                    throw new NoSuchMessageException(msg.toString());
10914            }
10915    
10916            /**
10917             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10918             *
10919             * @param threadId the thread ID
10920             * @param status the status
10921             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10922             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10923             */
10924            @Override
10925            public MBMessage fetchByTR_S_Last(long threadId, int status,
10926                    OrderByComparator<MBMessage> orderByComparator) {
10927                    int count = countByTR_S(threadId, status);
10928    
10929                    if (count == 0) {
10930                            return null;
10931                    }
10932    
10933                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10934                                    orderByComparator);
10935    
10936                    if (!list.isEmpty()) {
10937                            return list.get(0);
10938                    }
10939    
10940                    return null;
10941            }
10942    
10943            /**
10944             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10945             *
10946             * @param messageId the primary key of the current message-boards message
10947             * @param threadId the thread ID
10948             * @param status the status
10949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10950             * @return the previous, current, and next message-boards message
10951             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10952             */
10953            @Override
10954            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10955                    int status, OrderByComparator<MBMessage> orderByComparator)
10956                    throws NoSuchMessageException {
10957                    MBMessage mbMessage = findByPrimaryKey(messageId);
10958    
10959                    Session session = null;
10960    
10961                    try {
10962                            session = openSession();
10963    
10964                            MBMessage[] array = new MBMessageImpl[3];
10965    
10966                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10967                                            status, orderByComparator, true);
10968    
10969                            array[1] = mbMessage;
10970    
10971                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10972                                            status, orderByComparator, false);
10973    
10974                            return array;
10975                    }
10976                    catch (Exception e) {
10977                            throw processException(e);
10978                    }
10979                    finally {
10980                            closeSession(session);
10981                    }
10982            }
10983    
10984            protected MBMessage getByTR_S_PrevAndNext(Session session,
10985                    MBMessage mbMessage, long threadId, int status,
10986                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10987                    StringBundler query = null;
10988    
10989                    if (orderByComparator != null) {
10990                            query = new StringBundler(6 +
10991                                            (orderByComparator.getOrderByFields().length * 6));
10992                    }
10993                    else {
10994                            query = new StringBundler(3);
10995                    }
10996    
10997                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10998    
10999                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11000    
11001                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11002    
11003                    if (orderByComparator != null) {
11004                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11005    
11006                            if (orderByConditionFields.length > 0) {
11007                                    query.append(WHERE_AND);
11008                            }
11009    
11010                            for (int i = 0; i < orderByConditionFields.length; i++) {
11011                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11012                                    query.append(orderByConditionFields[i]);
11013    
11014                                    if ((i + 1) < orderByConditionFields.length) {
11015                                            if (orderByComparator.isAscending() ^ previous) {
11016                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11017                                            }
11018                                            else {
11019                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11020                                            }
11021                                    }
11022                                    else {
11023                                            if (orderByComparator.isAscending() ^ previous) {
11024                                                    query.append(WHERE_GREATER_THAN);
11025                                            }
11026                                            else {
11027                                                    query.append(WHERE_LESSER_THAN);
11028                                            }
11029                                    }
11030                            }
11031    
11032                            query.append(ORDER_BY_CLAUSE);
11033    
11034                            String[] orderByFields = orderByComparator.getOrderByFields();
11035    
11036                            for (int i = 0; i < orderByFields.length; i++) {
11037                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11038                                    query.append(orderByFields[i]);
11039    
11040                                    if ((i + 1) < orderByFields.length) {
11041                                            if (orderByComparator.isAscending() ^ previous) {
11042                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11043                                            }
11044                                            else {
11045                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11046                                            }
11047                                    }
11048                                    else {
11049                                            if (orderByComparator.isAscending() ^ previous) {
11050                                                    query.append(ORDER_BY_ASC);
11051                                            }
11052                                            else {
11053                                                    query.append(ORDER_BY_DESC);
11054                                            }
11055                                    }
11056                            }
11057                    }
11058                    else {
11059                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11060                    }
11061    
11062                    String sql = query.toString();
11063    
11064                    Query q = session.createQuery(sql);
11065    
11066                    q.setFirstResult(0);
11067                    q.setMaxResults(2);
11068    
11069                    QueryPos qPos = QueryPos.getInstance(q);
11070    
11071                    qPos.add(threadId);
11072    
11073                    qPos.add(status);
11074    
11075                    if (orderByComparator != null) {
11076                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11077    
11078                            for (Object value : values) {
11079                                    qPos.add(value);
11080                            }
11081                    }
11082    
11083                    List<MBMessage> list = q.list();
11084    
11085                    if (list.size() == 2) {
11086                            return list.get(1);
11087                    }
11088                    else {
11089                            return null;
11090                    }
11091            }
11092    
11093            /**
11094             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
11095             *
11096             * @param threadId the thread ID
11097             * @param status the status
11098             */
11099            @Override
11100            public void removeByTR_S(long threadId, int status) {
11101                    for (MBMessage mbMessage : findByTR_S(threadId, status,
11102                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11103                            remove(mbMessage);
11104                    }
11105            }
11106    
11107            /**
11108             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
11109             *
11110             * @param threadId the thread ID
11111             * @param status the status
11112             * @return the number of matching message-boards messages
11113             */
11114            @Override
11115            public int countByTR_S(long threadId, int status) {
11116                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
11117    
11118                    Object[] finderArgs = new Object[] { threadId, status };
11119    
11120                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
11121    
11122                    if (count == null) {
11123                            StringBundler query = new StringBundler(3);
11124    
11125                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11126    
11127                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11128    
11129                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11130    
11131                            String sql = query.toString();
11132    
11133                            Session session = null;
11134    
11135                            try {
11136                                    session = openSession();
11137    
11138                                    Query q = session.createQuery(sql);
11139    
11140                                    QueryPos qPos = QueryPos.getInstance(q);
11141    
11142                                    qPos.add(threadId);
11143    
11144                                    qPos.add(status);
11145    
11146                                    count = (Long)q.uniqueResult();
11147    
11148                                    finderCache.putResult(finderPath, finderArgs, count);
11149                            }
11150                            catch (Exception e) {
11151                                    finderCache.removeResult(finderPath, finderArgs);
11152    
11153                                    throw processException(e);
11154                            }
11155                            finally {
11156                                    closeSession(session);
11157                            }
11158                    }
11159    
11160                    return count.intValue();
11161            }
11162    
11163            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11164            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11165            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11167                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
11168                            new String[] {
11169                                    Long.class.getName(), Long.class.getName(),
11170                                    Integer.class.getName(),
11171                                    
11172                            Integer.class.getName(), Integer.class.getName(),
11173                                    OrderByComparator.class.getName()
11174                            });
11175            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11176                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11177                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
11178                            new String[] {
11179                                    Long.class.getName(), Long.class.getName(),
11180                                    Integer.class.getName()
11181                            },
11182                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11183                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
11184                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
11185                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11186            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11187                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11188                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
11189                            new String[] {
11190                                    Long.class.getName(), Long.class.getName(),
11191                                    Integer.class.getName()
11192                            });
11193    
11194            /**
11195             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11196             *
11197             * @param groupId the group ID
11198             * @param userId the user ID
11199             * @param status the status
11200             * @return the matching message-boards messages
11201             */
11202            @Override
11203            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
11204                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11205                            QueryUtil.ALL_POS, null);
11206            }
11207    
11208            /**
11209             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11210             *
11211             * <p>
11212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11213             * </p>
11214             *
11215             * @param groupId the group ID
11216             * @param userId the user ID
11217             * @param status the status
11218             * @param start the lower bound of the range of message-boards messages
11219             * @param end the upper bound of the range of message-boards messages (not inclusive)
11220             * @return the range of matching message-boards messages
11221             */
11222            @Override
11223            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11224                    int start, int end) {
11225                    return findByG_U_S(groupId, userId, status, start, end, null);
11226            }
11227    
11228            /**
11229             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11230             *
11231             * <p>
11232             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11233             * </p>
11234             *
11235             * @param groupId the group ID
11236             * @param userId the user ID
11237             * @param status the status
11238             * @param start the lower bound of the range of message-boards messages
11239             * @param end the upper bound of the range of message-boards messages (not inclusive)
11240             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11241             * @return the ordered range of matching message-boards messages
11242             */
11243            @Override
11244            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11245                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
11246                    return findByG_U_S(groupId, userId, status, start, end,
11247                            orderByComparator, true);
11248            }
11249    
11250            /**
11251             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11252             *
11253             * <p>
11254             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11255             * </p>
11256             *
11257             * @param groupId the group ID
11258             * @param userId the user ID
11259             * @param status the status
11260             * @param start the lower bound of the range of message-boards messages
11261             * @param end the upper bound of the range of message-boards messages (not inclusive)
11262             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11263             * @param retrieveFromCache whether to retrieve from the finder cache
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                    boolean retrieveFromCache) {
11270                    boolean pagination = true;
11271                    FinderPath finderPath = null;
11272                    Object[] finderArgs = null;
11273    
11274                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11275                                    (orderByComparator == null)) {
11276                            pagination = false;
11277                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11278                            finderArgs = new Object[] { groupId, userId, status };
11279                    }
11280                    else {
11281                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11282                            finderArgs = new Object[] {
11283                                            groupId, userId, status,
11284                                            
11285                                            start, end, orderByComparator
11286                                    };
11287                    }
11288    
11289                    List<MBMessage> list = null;
11290    
11291                    if (retrieveFromCache) {
11292                            list = (List<MBMessage>)finderCache.getResult(finderPath,
11293                                            finderArgs, this);
11294    
11295                            if ((list != null) && !list.isEmpty()) {
11296                                    for (MBMessage mbMessage : list) {
11297                                            if ((groupId != mbMessage.getGroupId()) ||
11298                                                            (userId != mbMessage.getUserId()) ||
11299                                                            (status != mbMessage.getStatus())) {
11300                                                    list = null;
11301    
11302                                                    break;
11303                                            }
11304                                    }
11305                            }
11306                    }
11307    
11308                    if (list == null) {
11309                            StringBundler query = null;
11310    
11311                            if (orderByComparator != null) {
11312                                    query = new StringBundler(5 +
11313                                                    (orderByComparator.getOrderByFields().length * 3));
11314                            }
11315                            else {
11316                                    query = new StringBundler(5);
11317                            }
11318    
11319                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11320    
11321                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11322    
11323                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11324    
11325                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11326    
11327                            if (orderByComparator != null) {
11328                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11329                                            orderByComparator);
11330                            }
11331                            else
11332                             if (pagination) {
11333                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11334                            }
11335    
11336                            String sql = query.toString();
11337    
11338                            Session session = null;
11339    
11340                            try {
11341                                    session = openSession();
11342    
11343                                    Query q = session.createQuery(sql);
11344    
11345                                    QueryPos qPos = QueryPos.getInstance(q);
11346    
11347                                    qPos.add(groupId);
11348    
11349                                    qPos.add(userId);
11350    
11351                                    qPos.add(status);
11352    
11353                                    if (!pagination) {
11354                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11355                                                            start, end, false);
11356    
11357                                            Collections.sort(list);
11358    
11359                                            list = Collections.unmodifiableList(list);
11360                                    }
11361                                    else {
11362                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11363                                                            start, end);
11364                                    }
11365    
11366                                    cacheResult(list);
11367    
11368                                    finderCache.putResult(finderPath, finderArgs, list);
11369                            }
11370                            catch (Exception e) {
11371                                    finderCache.removeResult(finderPath, finderArgs);
11372    
11373                                    throw processException(e);
11374                            }
11375                            finally {
11376                                    closeSession(session);
11377                            }
11378                    }
11379    
11380                    return list;
11381            }
11382    
11383            /**
11384             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11385             *
11386             * @param groupId the group ID
11387             * @param userId the user ID
11388             * @param status the status
11389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11390             * @return the first matching message-boards message
11391             * @throws NoSuchMessageException if a matching message-boards message could not be found
11392             */
11393            @Override
11394            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11395                    OrderByComparator<MBMessage> orderByComparator)
11396                    throws NoSuchMessageException {
11397                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11398                                    orderByComparator);
11399    
11400                    if (mbMessage != null) {
11401                            return mbMessage;
11402                    }
11403    
11404                    StringBundler msg = new StringBundler(8);
11405    
11406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11407    
11408                    msg.append("groupId=");
11409                    msg.append(groupId);
11410    
11411                    msg.append(", userId=");
11412                    msg.append(userId);
11413    
11414                    msg.append(", status=");
11415                    msg.append(status);
11416    
11417                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11418    
11419                    throw new NoSuchMessageException(msg.toString());
11420            }
11421    
11422            /**
11423             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11424             *
11425             * @param groupId the group ID
11426             * @param userId the user ID
11427             * @param status the status
11428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11429             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11430             */
11431            @Override
11432            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11433                    OrderByComparator<MBMessage> orderByComparator) {
11434                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11435                                    orderByComparator);
11436    
11437                    if (!list.isEmpty()) {
11438                            return list.get(0);
11439                    }
11440    
11441                    return null;
11442            }
11443    
11444            /**
11445             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11446             *
11447             * @param groupId the group ID
11448             * @param userId the user ID
11449             * @param status the status
11450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11451             * @return the last matching message-boards message
11452             * @throws NoSuchMessageException if a matching message-boards message could not be found
11453             */
11454            @Override
11455            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11456                    OrderByComparator<MBMessage> orderByComparator)
11457                    throws NoSuchMessageException {
11458                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11459                                    orderByComparator);
11460    
11461                    if (mbMessage != null) {
11462                            return mbMessage;
11463                    }
11464    
11465                    StringBundler msg = new StringBundler(8);
11466    
11467                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11468    
11469                    msg.append("groupId=");
11470                    msg.append(groupId);
11471    
11472                    msg.append(", userId=");
11473                    msg.append(userId);
11474    
11475                    msg.append(", status=");
11476                    msg.append(status);
11477    
11478                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11479    
11480                    throw new NoSuchMessageException(msg.toString());
11481            }
11482    
11483            /**
11484             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11485             *
11486             * @param groupId the group ID
11487             * @param userId the user ID
11488             * @param status the status
11489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11490             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11491             */
11492            @Override
11493            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11494                    OrderByComparator<MBMessage> orderByComparator) {
11495                    int count = countByG_U_S(groupId, userId, status);
11496    
11497                    if (count == 0) {
11498                            return null;
11499                    }
11500    
11501                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11502                                    count, orderByComparator);
11503    
11504                    if (!list.isEmpty()) {
11505                            return list.get(0);
11506                    }
11507    
11508                    return null;
11509            }
11510    
11511            /**
11512             * 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;.
11513             *
11514             * @param messageId the primary key of the current message-boards message
11515             * @param groupId the group ID
11516             * @param userId the user ID
11517             * @param status the status
11518             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11519             * @return the previous, current, and next message-boards message
11520             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11521             */
11522            @Override
11523            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11524                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11525                    throws NoSuchMessageException {
11526                    MBMessage mbMessage = findByPrimaryKey(messageId);
11527    
11528                    Session session = null;
11529    
11530                    try {
11531                            session = openSession();
11532    
11533                            MBMessage[] array = new MBMessageImpl[3];
11534    
11535                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11536                                            userId, status, orderByComparator, true);
11537    
11538                            array[1] = mbMessage;
11539    
11540                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11541                                            userId, status, orderByComparator, false);
11542    
11543                            return array;
11544                    }
11545                    catch (Exception e) {
11546                            throw processException(e);
11547                    }
11548                    finally {
11549                            closeSession(session);
11550                    }
11551            }
11552    
11553            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11554                    MBMessage mbMessage, long groupId, long userId, int status,
11555                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11556                    StringBundler query = null;
11557    
11558                    if (orderByComparator != null) {
11559                            query = new StringBundler(6 +
11560                                            (orderByComparator.getOrderByFields().length * 6));
11561                    }
11562                    else {
11563                            query = new StringBundler(3);
11564                    }
11565    
11566                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11567    
11568                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11569    
11570                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11571    
11572                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11573    
11574                    if (orderByComparator != null) {
11575                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11576    
11577                            if (orderByConditionFields.length > 0) {
11578                                    query.append(WHERE_AND);
11579                            }
11580    
11581                            for (int i = 0; i < orderByConditionFields.length; i++) {
11582                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11583                                    query.append(orderByConditionFields[i]);
11584    
11585                                    if ((i + 1) < orderByConditionFields.length) {
11586                                            if (orderByComparator.isAscending() ^ previous) {
11587                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11588                                            }
11589                                            else {
11590                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11591                                            }
11592                                    }
11593                                    else {
11594                                            if (orderByComparator.isAscending() ^ previous) {
11595                                                    query.append(WHERE_GREATER_THAN);
11596                                            }
11597                                            else {
11598                                                    query.append(WHERE_LESSER_THAN);
11599                                            }
11600                                    }
11601                            }
11602    
11603                            query.append(ORDER_BY_CLAUSE);
11604    
11605                            String[] orderByFields = orderByComparator.getOrderByFields();
11606    
11607                            for (int i = 0; i < orderByFields.length; i++) {
11608                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11609                                    query.append(orderByFields[i]);
11610    
11611                                    if ((i + 1) < orderByFields.length) {
11612                                            if (orderByComparator.isAscending() ^ previous) {
11613                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11614                                            }
11615                                            else {
11616                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11617                                            }
11618                                    }
11619                                    else {
11620                                            if (orderByComparator.isAscending() ^ previous) {
11621                                                    query.append(ORDER_BY_ASC);
11622                                            }
11623                                            else {
11624                                                    query.append(ORDER_BY_DESC);
11625                                            }
11626                                    }
11627                            }
11628                    }
11629                    else {
11630                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11631                    }
11632    
11633                    String sql = query.toString();
11634    
11635                    Query q = session.createQuery(sql);
11636    
11637                    q.setFirstResult(0);
11638                    q.setMaxResults(2);
11639    
11640                    QueryPos qPos = QueryPos.getInstance(q);
11641    
11642                    qPos.add(groupId);
11643    
11644                    qPos.add(userId);
11645    
11646                    qPos.add(status);
11647    
11648                    if (orderByComparator != null) {
11649                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11650    
11651                            for (Object value : values) {
11652                                    qPos.add(value);
11653                            }
11654                    }
11655    
11656                    List<MBMessage> list = q.list();
11657    
11658                    if (list.size() == 2) {
11659                            return list.get(1);
11660                    }
11661                    else {
11662                            return null;
11663                    }
11664            }
11665    
11666            /**
11667             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11668             *
11669             * @param groupId the group ID
11670             * @param userId the user ID
11671             * @param status the status
11672             * @return the matching message-boards messages that the user has permission to view
11673             */
11674            @Override
11675            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11676                    int status) {
11677                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11678                            QueryUtil.ALL_POS, null);
11679            }
11680    
11681            /**
11682             * 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;.
11683             *
11684             * <p>
11685             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11686             * </p>
11687             *
11688             * @param groupId the group ID
11689             * @param userId the user ID
11690             * @param status the status
11691             * @param start the lower bound of the range of message-boards messages
11692             * @param end the upper bound of the range of message-boards messages (not inclusive)
11693             * @return the range of matching message-boards messages that the user has permission to view
11694             */
11695            @Override
11696            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11697                    int status, int start, int end) {
11698                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11699            }
11700    
11701            /**
11702             * 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;.
11703             *
11704             * <p>
11705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11706             * </p>
11707             *
11708             * @param groupId the group ID
11709             * @param userId the user ID
11710             * @param status the status
11711             * @param start the lower bound of the range of message-boards messages
11712             * @param end the upper bound of the range of message-boards messages (not inclusive)
11713             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11714             * @return the ordered range of matching message-boards messages that the user has permission to view
11715             */
11716            @Override
11717            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11718                    int status, int start, int end,
11719                    OrderByComparator<MBMessage> orderByComparator) {
11720                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11721                            return findByG_U_S(groupId, userId, status, start, end,
11722                                    orderByComparator);
11723                    }
11724    
11725                    StringBundler query = null;
11726    
11727                    if (orderByComparator != null) {
11728                            query = new StringBundler(5 +
11729                                            (orderByComparator.getOrderByFields().length * 3));
11730                    }
11731                    else {
11732                            query = new StringBundler(5);
11733                    }
11734    
11735                    if (getDB().isSupportsInlineDistinct()) {
11736                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11737                    }
11738                    else {
11739                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11740                    }
11741    
11742                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11743    
11744                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11745    
11746                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11747    
11748                    if (!getDB().isSupportsInlineDistinct()) {
11749                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11750                    }
11751    
11752                    if (orderByComparator != null) {
11753                            if (getDB().isSupportsInlineDistinct()) {
11754                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11755                                            orderByComparator, true);
11756                            }
11757                            else {
11758                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11759                                            orderByComparator, true);
11760                            }
11761                    }
11762                    else {
11763                            if (getDB().isSupportsInlineDistinct()) {
11764                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11765                            }
11766                            else {
11767                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11768                            }
11769                    }
11770    
11771                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11772                                    MBMessage.class.getName(),
11773                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11774    
11775                    Session session = null;
11776    
11777                    try {
11778                            session = openSession();
11779    
11780                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11781    
11782                            if (getDB().isSupportsInlineDistinct()) {
11783                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11784                            }
11785                            else {
11786                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11787                            }
11788    
11789                            QueryPos qPos = QueryPos.getInstance(q);
11790    
11791                            qPos.add(groupId);
11792    
11793                            qPos.add(userId);
11794    
11795                            qPos.add(status);
11796    
11797                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11798                    }
11799                    catch (Exception e) {
11800                            throw processException(e);
11801                    }
11802                    finally {
11803                            closeSession(session);
11804                    }
11805            }
11806    
11807            /**
11808             * 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;.
11809             *
11810             * @param messageId the primary key of the current message-boards message
11811             * @param groupId the group ID
11812             * @param userId the user ID
11813             * @param status the status
11814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11815             * @return the previous, current, and next message-boards message
11816             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11817             */
11818            @Override
11819            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11820                    long groupId, long userId, int status,
11821                    OrderByComparator<MBMessage> orderByComparator)
11822                    throws NoSuchMessageException {
11823                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11824                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11825                                    orderByComparator);
11826                    }
11827    
11828                    MBMessage mbMessage = findByPrimaryKey(messageId);
11829    
11830                    Session session = null;
11831    
11832                    try {
11833                            session = openSession();
11834    
11835                            MBMessage[] array = new MBMessageImpl[3];
11836    
11837                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11838                                            groupId, userId, status, orderByComparator, true);
11839    
11840                            array[1] = mbMessage;
11841    
11842                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11843                                            groupId, userId, status, orderByComparator, false);
11844    
11845                            return array;
11846                    }
11847                    catch (Exception e) {
11848                            throw processException(e);
11849                    }
11850                    finally {
11851                            closeSession(session);
11852                    }
11853            }
11854    
11855            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11856                    MBMessage mbMessage, long groupId, long userId, int status,
11857                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11858                    StringBundler query = null;
11859    
11860                    if (orderByComparator != null) {
11861                            query = new StringBundler(6 +
11862                                            (orderByComparator.getOrderByFields().length * 6));
11863                    }
11864                    else {
11865                            query = new StringBundler(3);
11866                    }
11867    
11868                    if (getDB().isSupportsInlineDistinct()) {
11869                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11870                    }
11871                    else {
11872                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11873                    }
11874    
11875                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11876    
11877                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11878    
11879                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11880    
11881                    if (!getDB().isSupportsInlineDistinct()) {
11882                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11883                    }
11884    
11885                    if (orderByComparator != null) {
11886                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11887    
11888                            if (orderByConditionFields.length > 0) {
11889                                    query.append(WHERE_AND);
11890                            }
11891    
11892                            for (int i = 0; i < orderByConditionFields.length; i++) {
11893                                    if (getDB().isSupportsInlineDistinct()) {
11894                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11895                                    }
11896                                    else {
11897                                            query.append(_ORDER_BY_ENTITY_TABLE);
11898                                    }
11899    
11900                                    query.append(orderByConditionFields[i]);
11901    
11902                                    if ((i + 1) < orderByConditionFields.length) {
11903                                            if (orderByComparator.isAscending() ^ previous) {
11904                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11905                                            }
11906                                            else {
11907                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11908                                            }
11909                                    }
11910                                    else {
11911                                            if (orderByComparator.isAscending() ^ previous) {
11912                                                    query.append(WHERE_GREATER_THAN);
11913                                            }
11914                                            else {
11915                                                    query.append(WHERE_LESSER_THAN);
11916                                            }
11917                                    }
11918                            }
11919    
11920                            query.append(ORDER_BY_CLAUSE);
11921    
11922                            String[] orderByFields = orderByComparator.getOrderByFields();
11923    
11924                            for (int i = 0; i < orderByFields.length; i++) {
11925                                    if (getDB().isSupportsInlineDistinct()) {
11926                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11927                                    }
11928                                    else {
11929                                            query.append(_ORDER_BY_ENTITY_TABLE);
11930                                    }
11931    
11932                                    query.append(orderByFields[i]);
11933    
11934                                    if ((i + 1) < orderByFields.length) {
11935                                            if (orderByComparator.isAscending() ^ previous) {
11936                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11937                                            }
11938                                            else {
11939                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11940                                            }
11941                                    }
11942                                    else {
11943                                            if (orderByComparator.isAscending() ^ previous) {
11944                                                    query.append(ORDER_BY_ASC);
11945                                            }
11946                                            else {
11947                                                    query.append(ORDER_BY_DESC);
11948                                            }
11949                                    }
11950                            }
11951                    }
11952                    else {
11953                            if (getDB().isSupportsInlineDistinct()) {
11954                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11955                            }
11956                            else {
11957                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11958                            }
11959                    }
11960    
11961                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11962                                    MBMessage.class.getName(),
11963                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11964    
11965                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11966    
11967                    q.setFirstResult(0);
11968                    q.setMaxResults(2);
11969    
11970                    if (getDB().isSupportsInlineDistinct()) {
11971                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11972                    }
11973                    else {
11974                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11975                    }
11976    
11977                    QueryPos qPos = QueryPos.getInstance(q);
11978    
11979                    qPos.add(groupId);
11980    
11981                    qPos.add(userId);
11982    
11983                    qPos.add(status);
11984    
11985                    if (orderByComparator != null) {
11986                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11987    
11988                            for (Object value : values) {
11989                                    qPos.add(value);
11990                            }
11991                    }
11992    
11993                    List<MBMessage> list = q.list();
11994    
11995                    if (list.size() == 2) {
11996                            return list.get(1);
11997                    }
11998                    else {
11999                            return null;
12000                    }
12001            }
12002    
12003            /**
12004             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
12005             *
12006             * @param groupId the group ID
12007             * @param userId the user ID
12008             * @param status the status
12009             */
12010            @Override
12011            public void removeByG_U_S(long groupId, long userId, int status) {
12012                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
12013                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12014                            remove(mbMessage);
12015                    }
12016            }
12017    
12018            /**
12019             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
12020             *
12021             * @param groupId the group ID
12022             * @param userId the user ID
12023             * @param status the status
12024             * @return the number of matching message-boards messages
12025             */
12026            @Override
12027            public int countByG_U_S(long groupId, long userId, int status) {
12028                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
12029    
12030                    Object[] finderArgs = new Object[] { groupId, userId, status };
12031    
12032                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12033    
12034                    if (count == null) {
12035                            StringBundler query = new StringBundler(4);
12036    
12037                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12038    
12039                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12040    
12041                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12042    
12043                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12044    
12045                            String sql = query.toString();
12046    
12047                            Session session = null;
12048    
12049                            try {
12050                                    session = openSession();
12051    
12052                                    Query q = session.createQuery(sql);
12053    
12054                                    QueryPos qPos = QueryPos.getInstance(q);
12055    
12056                                    qPos.add(groupId);
12057    
12058                                    qPos.add(userId);
12059    
12060                                    qPos.add(status);
12061    
12062                                    count = (Long)q.uniqueResult();
12063    
12064                                    finderCache.putResult(finderPath, finderArgs, count);
12065                            }
12066                            catch (Exception e) {
12067                                    finderCache.removeResult(finderPath, finderArgs);
12068    
12069                                    throw processException(e);
12070                            }
12071                            finally {
12072                                    closeSession(session);
12073                            }
12074                    }
12075    
12076                    return count.intValue();
12077            }
12078    
12079            /**
12080             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
12081             *
12082             * @param groupId the group ID
12083             * @param userId the user ID
12084             * @param status the status
12085             * @return the number of matching message-boards messages that the user has permission to view
12086             */
12087            @Override
12088            public int filterCountByG_U_S(long groupId, long userId, int status) {
12089                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12090                            return countByG_U_S(groupId, userId, status);
12091                    }
12092    
12093                    StringBundler query = new StringBundler(4);
12094    
12095                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12096    
12097                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12098    
12099                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12100    
12101                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12102    
12103                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12104                                    MBMessage.class.getName(),
12105                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12106    
12107                    Session session = null;
12108    
12109                    try {
12110                            session = openSession();
12111    
12112                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12113    
12114                            q.addScalar(COUNT_COLUMN_NAME,
12115                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12116    
12117                            QueryPos qPos = QueryPos.getInstance(q);
12118    
12119                            qPos.add(groupId);
12120    
12121                            qPos.add(userId);
12122    
12123                            qPos.add(status);
12124    
12125                            Long count = (Long)q.uniqueResult();
12126    
12127                            return count.intValue();
12128                    }
12129                    catch (Exception e) {
12130                            throw processException(e);
12131                    }
12132                    finally {
12133                            closeSession(session);
12134                    }
12135            }
12136    
12137            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
12138            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
12139            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
12140            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12141                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12142                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
12143                            new String[] {
12144                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12145                                    
12146                            Integer.class.getName(), Integer.class.getName(),
12147                                    OrderByComparator.class.getName()
12148                            });
12149            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12150                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
12152                            new String[] {
12153                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12154                            },
12155                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12156                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12157                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
12158                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12159            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12160                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
12162                            new String[] {
12163                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12164                            });
12165    
12166            /**
12167             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12168             *
12169             * @param groupId the group ID
12170             * @param categoryId the category ID
12171             * @param threadId the thread ID
12172             * @return the matching message-boards messages
12173             */
12174            @Override
12175            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12176                    long threadId) {
12177                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
12178                            QueryUtil.ALL_POS, null);
12179            }
12180    
12181            /**
12182             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12183             *
12184             * <p>
12185             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12186             * </p>
12187             *
12188             * @param groupId the group ID
12189             * @param categoryId the category ID
12190             * @param threadId the thread ID
12191             * @param start the lower bound of the range of message-boards messages
12192             * @param end the upper bound of the range of message-boards messages (not inclusive)
12193             * @return the range of matching message-boards messages
12194             */
12195            @Override
12196            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12197                    long threadId, int start, int end) {
12198                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
12199            }
12200    
12201            /**
12202             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12203             *
12204             * <p>
12205             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12206             * </p>
12207             *
12208             * @param groupId the group ID
12209             * @param categoryId the category ID
12210             * @param threadId the thread ID
12211             * @param start the lower bound of the range of message-boards messages
12212             * @param end the upper bound of the range of message-boards messages (not inclusive)
12213             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12214             * @return the ordered range of matching message-boards messages
12215             */
12216            @Override
12217            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12218                    long threadId, int start, int end,
12219                    OrderByComparator<MBMessage> orderByComparator) {
12220                    return findByG_C_T(groupId, categoryId, threadId, start, end,
12221                            orderByComparator, true);
12222            }
12223    
12224            /**
12225             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12226             *
12227             * <p>
12228             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12229             * </p>
12230             *
12231             * @param groupId the group ID
12232             * @param categoryId the category ID
12233             * @param threadId the thread ID
12234             * @param start the lower bound of the range of message-boards messages
12235             * @param end the upper bound of the range of message-boards messages (not inclusive)
12236             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12237             * @param retrieveFromCache whether to retrieve from the finder cache
12238             * @return the ordered range of matching message-boards messages
12239             */
12240            @Override
12241            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12242                    long threadId, int start, int end,
12243                    OrderByComparator<MBMessage> orderByComparator,
12244                    boolean retrieveFromCache) {
12245                    boolean pagination = true;
12246                    FinderPath finderPath = null;
12247                    Object[] finderArgs = null;
12248    
12249                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12250                                    (orderByComparator == null)) {
12251                            pagination = false;
12252                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12253                            finderArgs = new Object[] { groupId, categoryId, threadId };
12254                    }
12255                    else {
12256                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12257                            finderArgs = new Object[] {
12258                                            groupId, categoryId, threadId,
12259                                            
12260                                            start, end, orderByComparator
12261                                    };
12262                    }
12263    
12264                    List<MBMessage> list = null;
12265    
12266                    if (retrieveFromCache) {
12267                            list = (List<MBMessage>)finderCache.getResult(finderPath,
12268                                            finderArgs, this);
12269    
12270                            if ((list != null) && !list.isEmpty()) {
12271                                    for (MBMessage mbMessage : list) {
12272                                            if ((groupId != mbMessage.getGroupId()) ||
12273                                                            (categoryId != mbMessage.getCategoryId()) ||
12274                                                            (threadId != mbMessage.getThreadId())) {
12275                                                    list = null;
12276    
12277                                                    break;
12278                                            }
12279                                    }
12280                            }
12281                    }
12282    
12283                    if (list == null) {
12284                            StringBundler query = null;
12285    
12286                            if (orderByComparator != null) {
12287                                    query = new StringBundler(5 +
12288                                                    (orderByComparator.getOrderByFields().length * 3));
12289                            }
12290                            else {
12291                                    query = new StringBundler(5);
12292                            }
12293    
12294                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12295    
12296                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12297    
12298                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12299    
12300                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12301    
12302                            if (orderByComparator != null) {
12303                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12304                                            orderByComparator);
12305                            }
12306                            else
12307                             if (pagination) {
12308                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12309                            }
12310    
12311                            String sql = query.toString();
12312    
12313                            Session session = null;
12314    
12315                            try {
12316                                    session = openSession();
12317    
12318                                    Query q = session.createQuery(sql);
12319    
12320                                    QueryPos qPos = QueryPos.getInstance(q);
12321    
12322                                    qPos.add(groupId);
12323    
12324                                    qPos.add(categoryId);
12325    
12326                                    qPos.add(threadId);
12327    
12328                                    if (!pagination) {
12329                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12330                                                            start, end, false);
12331    
12332                                            Collections.sort(list);
12333    
12334                                            list = Collections.unmodifiableList(list);
12335                                    }
12336                                    else {
12337                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12338                                                            start, end);
12339                                    }
12340    
12341                                    cacheResult(list);
12342    
12343                                    finderCache.putResult(finderPath, finderArgs, list);
12344                            }
12345                            catch (Exception e) {
12346                                    finderCache.removeResult(finderPath, finderArgs);
12347    
12348                                    throw processException(e);
12349                            }
12350                            finally {
12351                                    closeSession(session);
12352                            }
12353                    }
12354    
12355                    return list;
12356            }
12357    
12358            /**
12359             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12360             *
12361             * @param groupId the group ID
12362             * @param categoryId the category ID
12363             * @param threadId the thread ID
12364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12365             * @return the first matching message-boards message
12366             * @throws NoSuchMessageException if a matching message-boards message could not be found
12367             */
12368            @Override
12369            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12370                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12371                    throws NoSuchMessageException {
12372                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12373                                    orderByComparator);
12374    
12375                    if (mbMessage != null) {
12376                            return mbMessage;
12377                    }
12378    
12379                    StringBundler msg = new StringBundler(8);
12380    
12381                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12382    
12383                    msg.append("groupId=");
12384                    msg.append(groupId);
12385    
12386                    msg.append(", categoryId=");
12387                    msg.append(categoryId);
12388    
12389                    msg.append(", threadId=");
12390                    msg.append(threadId);
12391    
12392                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12393    
12394                    throw new NoSuchMessageException(msg.toString());
12395            }
12396    
12397            /**
12398             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12399             *
12400             * @param groupId the group ID
12401             * @param categoryId the category ID
12402             * @param threadId the thread ID
12403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12404             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12405             */
12406            @Override
12407            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12408                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12409                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12410                                    orderByComparator);
12411    
12412                    if (!list.isEmpty()) {
12413                            return list.get(0);
12414                    }
12415    
12416                    return null;
12417            }
12418    
12419            /**
12420             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12421             *
12422             * @param groupId the group ID
12423             * @param categoryId the category ID
12424             * @param threadId the thread ID
12425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12426             * @return the last matching message-boards message
12427             * @throws NoSuchMessageException if a matching message-boards message could not be found
12428             */
12429            @Override
12430            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12431                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12432                    throws NoSuchMessageException {
12433                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12434                                    orderByComparator);
12435    
12436                    if (mbMessage != null) {
12437                            return mbMessage;
12438                    }
12439    
12440                    StringBundler msg = new StringBundler(8);
12441    
12442                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12443    
12444                    msg.append("groupId=");
12445                    msg.append(groupId);
12446    
12447                    msg.append(", categoryId=");
12448                    msg.append(categoryId);
12449    
12450                    msg.append(", threadId=");
12451                    msg.append(threadId);
12452    
12453                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12454    
12455                    throw new NoSuchMessageException(msg.toString());
12456            }
12457    
12458            /**
12459             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12460             *
12461             * @param groupId the group ID
12462             * @param categoryId the category ID
12463             * @param threadId the thread ID
12464             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12465             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12466             */
12467            @Override
12468            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12469                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12470                    int count = countByG_C_T(groupId, categoryId, threadId);
12471    
12472                    if (count == 0) {
12473                            return null;
12474                    }
12475    
12476                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12477                                    count - 1, count, orderByComparator);
12478    
12479                    if (!list.isEmpty()) {
12480                            return list.get(0);
12481                    }
12482    
12483                    return null;
12484            }
12485    
12486            /**
12487             * 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;.
12488             *
12489             * @param messageId the primary key of the current message-boards message
12490             * @param groupId the group ID
12491             * @param categoryId the category ID
12492             * @param threadId the thread ID
12493             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12494             * @return the previous, current, and next message-boards message
12495             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12496             */
12497            @Override
12498            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12499                    long categoryId, long threadId,
12500                    OrderByComparator<MBMessage> orderByComparator)
12501                    throws NoSuchMessageException {
12502                    MBMessage mbMessage = findByPrimaryKey(messageId);
12503    
12504                    Session session = null;
12505    
12506                    try {
12507                            session = openSession();
12508    
12509                            MBMessage[] array = new MBMessageImpl[3];
12510    
12511                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12512                                            categoryId, threadId, orderByComparator, true);
12513    
12514                            array[1] = mbMessage;
12515    
12516                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12517                                            categoryId, threadId, orderByComparator, false);
12518    
12519                            return array;
12520                    }
12521                    catch (Exception e) {
12522                            throw processException(e);
12523                    }
12524                    finally {
12525                            closeSession(session);
12526                    }
12527            }
12528    
12529            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12530                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12531                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12532                    StringBundler query = null;
12533    
12534                    if (orderByComparator != null) {
12535                            query = new StringBundler(6 +
12536                                            (orderByComparator.getOrderByFields().length * 6));
12537                    }
12538                    else {
12539                            query = new StringBundler(3);
12540                    }
12541    
12542                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12543    
12544                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12545    
12546                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12547    
12548                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12549    
12550                    if (orderByComparator != null) {
12551                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12552    
12553                            if (orderByConditionFields.length > 0) {
12554                                    query.append(WHERE_AND);
12555                            }
12556    
12557                            for (int i = 0; i < orderByConditionFields.length; i++) {
12558                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12559                                    query.append(orderByConditionFields[i]);
12560    
12561                                    if ((i + 1) < orderByConditionFields.length) {
12562                                            if (orderByComparator.isAscending() ^ previous) {
12563                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12564                                            }
12565                                            else {
12566                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12567                                            }
12568                                    }
12569                                    else {
12570                                            if (orderByComparator.isAscending() ^ previous) {
12571                                                    query.append(WHERE_GREATER_THAN);
12572                                            }
12573                                            else {
12574                                                    query.append(WHERE_LESSER_THAN);
12575                                            }
12576                                    }
12577                            }
12578    
12579                            query.append(ORDER_BY_CLAUSE);
12580    
12581                            String[] orderByFields = orderByComparator.getOrderByFields();
12582    
12583                            for (int i = 0; i < orderByFields.length; i++) {
12584                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12585                                    query.append(orderByFields[i]);
12586    
12587                                    if ((i + 1) < orderByFields.length) {
12588                                            if (orderByComparator.isAscending() ^ previous) {
12589                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12590                                            }
12591                                            else {
12592                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12593                                            }
12594                                    }
12595                                    else {
12596                                            if (orderByComparator.isAscending() ^ previous) {
12597                                                    query.append(ORDER_BY_ASC);
12598                                            }
12599                                            else {
12600                                                    query.append(ORDER_BY_DESC);
12601                                            }
12602                                    }
12603                            }
12604                    }
12605                    else {
12606                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12607                    }
12608    
12609                    String sql = query.toString();
12610    
12611                    Query q = session.createQuery(sql);
12612    
12613                    q.setFirstResult(0);
12614                    q.setMaxResults(2);
12615    
12616                    QueryPos qPos = QueryPos.getInstance(q);
12617    
12618                    qPos.add(groupId);
12619    
12620                    qPos.add(categoryId);
12621    
12622                    qPos.add(threadId);
12623    
12624                    if (orderByComparator != null) {
12625                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12626    
12627                            for (Object value : values) {
12628                                    qPos.add(value);
12629                            }
12630                    }
12631    
12632                    List<MBMessage> list = q.list();
12633    
12634                    if (list.size() == 2) {
12635                            return list.get(1);
12636                    }
12637                    else {
12638                            return null;
12639                    }
12640            }
12641    
12642            /**
12643             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12644             *
12645             * @param groupId the group ID
12646             * @param categoryId the category ID
12647             * @param threadId the thread ID
12648             * @return the matching message-boards messages that the user has permission to view
12649             */
12650            @Override
12651            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12652                    long threadId) {
12653                    return filterFindByG_C_T(groupId, categoryId, threadId,
12654                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12655            }
12656    
12657            /**
12658             * 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;.
12659             *
12660             * <p>
12661             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12662             * </p>
12663             *
12664             * @param groupId the group ID
12665             * @param categoryId the category ID
12666             * @param threadId the thread ID
12667             * @param start the lower bound of the range of message-boards messages
12668             * @param end the upper bound of the range of message-boards messages (not inclusive)
12669             * @return the range of matching message-boards messages that the user has permission to view
12670             */
12671            @Override
12672            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12673                    long threadId, int start, int end) {
12674                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12675            }
12676    
12677            /**
12678             * 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;.
12679             *
12680             * <p>
12681             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12682             * </p>
12683             *
12684             * @param groupId the group ID
12685             * @param categoryId the category ID
12686             * @param threadId the thread ID
12687             * @param start the lower bound of the range of message-boards messages
12688             * @param end the upper bound of the range of message-boards messages (not inclusive)
12689             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12690             * @return the ordered range of matching message-boards messages that the user has permission to view
12691             */
12692            @Override
12693            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12694                    long threadId, int start, int end,
12695                    OrderByComparator<MBMessage> orderByComparator) {
12696                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12697                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12698                                    orderByComparator);
12699                    }
12700    
12701                    StringBundler query = null;
12702    
12703                    if (orderByComparator != null) {
12704                            query = new StringBundler(5 +
12705                                            (orderByComparator.getOrderByFields().length * 3));
12706                    }
12707                    else {
12708                            query = new StringBundler(5);
12709                    }
12710    
12711                    if (getDB().isSupportsInlineDistinct()) {
12712                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12713                    }
12714                    else {
12715                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12716                    }
12717    
12718                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12719    
12720                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12721    
12722                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12723    
12724                    if (!getDB().isSupportsInlineDistinct()) {
12725                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12726                    }
12727    
12728                    if (orderByComparator != null) {
12729                            if (getDB().isSupportsInlineDistinct()) {
12730                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12731                                            orderByComparator, true);
12732                            }
12733                            else {
12734                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12735                                            orderByComparator, true);
12736                            }
12737                    }
12738                    else {
12739                            if (getDB().isSupportsInlineDistinct()) {
12740                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12741                            }
12742                            else {
12743                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12744                            }
12745                    }
12746    
12747                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12748                                    MBMessage.class.getName(),
12749                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12750    
12751                    Session session = null;
12752    
12753                    try {
12754                            session = openSession();
12755    
12756                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12757    
12758                            if (getDB().isSupportsInlineDistinct()) {
12759                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12760                            }
12761                            else {
12762                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12763                            }
12764    
12765                            QueryPos qPos = QueryPos.getInstance(q);
12766    
12767                            qPos.add(groupId);
12768    
12769                            qPos.add(categoryId);
12770    
12771                            qPos.add(threadId);
12772    
12773                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12774                    }
12775                    catch (Exception e) {
12776                            throw processException(e);
12777                    }
12778                    finally {
12779                            closeSession(session);
12780                    }
12781            }
12782    
12783            /**
12784             * 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;.
12785             *
12786             * @param messageId the primary key of the current message-boards message
12787             * @param groupId the group ID
12788             * @param categoryId the category ID
12789             * @param threadId the thread ID
12790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12791             * @return the previous, current, and next message-boards message
12792             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12793             */
12794            @Override
12795            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12796                    long groupId, long categoryId, long threadId,
12797                    OrderByComparator<MBMessage> orderByComparator)
12798                    throws NoSuchMessageException {
12799                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12800                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12801                                    threadId, orderByComparator);
12802                    }
12803    
12804                    MBMessage mbMessage = findByPrimaryKey(messageId);
12805    
12806                    Session session = null;
12807    
12808                    try {
12809                            session = openSession();
12810    
12811                            MBMessage[] array = new MBMessageImpl[3];
12812    
12813                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12814                                            groupId, categoryId, threadId, orderByComparator, true);
12815    
12816                            array[1] = mbMessage;
12817    
12818                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12819                                            groupId, categoryId, threadId, orderByComparator, false);
12820    
12821                            return array;
12822                    }
12823                    catch (Exception e) {
12824                            throw processException(e);
12825                    }
12826                    finally {
12827                            closeSession(session);
12828                    }
12829            }
12830    
12831            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12832                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12833                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12834                    StringBundler query = null;
12835    
12836                    if (orderByComparator != null) {
12837                            query = new StringBundler(6 +
12838                                            (orderByComparator.getOrderByFields().length * 6));
12839                    }
12840                    else {
12841                            query = new StringBundler(3);
12842                    }
12843    
12844                    if (getDB().isSupportsInlineDistinct()) {
12845                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12846                    }
12847                    else {
12848                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12849                    }
12850    
12851                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12852    
12853                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12854    
12855                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12856    
12857                    if (!getDB().isSupportsInlineDistinct()) {
12858                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12859                    }
12860    
12861                    if (orderByComparator != null) {
12862                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12863    
12864                            if (orderByConditionFields.length > 0) {
12865                                    query.append(WHERE_AND);
12866                            }
12867    
12868                            for (int i = 0; i < orderByConditionFields.length; i++) {
12869                                    if (getDB().isSupportsInlineDistinct()) {
12870                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12871                                    }
12872                                    else {
12873                                            query.append(_ORDER_BY_ENTITY_TABLE);
12874                                    }
12875    
12876                                    query.append(orderByConditionFields[i]);
12877    
12878                                    if ((i + 1) < orderByConditionFields.length) {
12879                                            if (orderByComparator.isAscending() ^ previous) {
12880                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12881                                            }
12882                                            else {
12883                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12884                                            }
12885                                    }
12886                                    else {
12887                                            if (orderByComparator.isAscending() ^ previous) {
12888                                                    query.append(WHERE_GREATER_THAN);
12889                                            }
12890                                            else {
12891                                                    query.append(WHERE_LESSER_THAN);
12892                                            }
12893                                    }
12894                            }
12895    
12896                            query.append(ORDER_BY_CLAUSE);
12897    
12898                            String[] orderByFields = orderByComparator.getOrderByFields();
12899    
12900                            for (int i = 0; i < orderByFields.length; i++) {
12901                                    if (getDB().isSupportsInlineDistinct()) {
12902                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12903                                    }
12904                                    else {
12905                                            query.append(_ORDER_BY_ENTITY_TABLE);
12906                                    }
12907    
12908                                    query.append(orderByFields[i]);
12909    
12910                                    if ((i + 1) < orderByFields.length) {
12911                                            if (orderByComparator.isAscending() ^ previous) {
12912                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12913                                            }
12914                                            else {
12915                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12916                                            }
12917                                    }
12918                                    else {
12919                                            if (orderByComparator.isAscending() ^ previous) {
12920                                                    query.append(ORDER_BY_ASC);
12921                                            }
12922                                            else {
12923                                                    query.append(ORDER_BY_DESC);
12924                                            }
12925                                    }
12926                            }
12927                    }
12928                    else {
12929                            if (getDB().isSupportsInlineDistinct()) {
12930                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12931                            }
12932                            else {
12933                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12934                            }
12935                    }
12936    
12937                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12938                                    MBMessage.class.getName(),
12939                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12940    
12941                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12942    
12943                    q.setFirstResult(0);
12944                    q.setMaxResults(2);
12945    
12946                    if (getDB().isSupportsInlineDistinct()) {
12947                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12948                    }
12949                    else {
12950                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12951                    }
12952    
12953                    QueryPos qPos = QueryPos.getInstance(q);
12954    
12955                    qPos.add(groupId);
12956    
12957                    qPos.add(categoryId);
12958    
12959                    qPos.add(threadId);
12960    
12961                    if (orderByComparator != null) {
12962                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12963    
12964                            for (Object value : values) {
12965                                    qPos.add(value);
12966                            }
12967                    }
12968    
12969                    List<MBMessage> list = q.list();
12970    
12971                    if (list.size() == 2) {
12972                            return list.get(1);
12973                    }
12974                    else {
12975                            return null;
12976                    }
12977            }
12978    
12979            /**
12980             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12981             *
12982             * @param groupId the group ID
12983             * @param categoryId the category ID
12984             * @param threadId the thread ID
12985             */
12986            @Override
12987            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
12988                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12989                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12990                            remove(mbMessage);
12991                    }
12992            }
12993    
12994            /**
12995             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12996             *
12997             * @param groupId the group ID
12998             * @param categoryId the category ID
12999             * @param threadId the thread ID
13000             * @return the number of matching message-boards messages
13001             */
13002            @Override
13003            public int countByG_C_T(long groupId, long categoryId, long threadId) {
13004                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
13005    
13006                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
13007    
13008                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13009    
13010                    if (count == null) {
13011                            StringBundler query = new StringBundler(4);
13012    
13013                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13014    
13015                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13016    
13017                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13018    
13019                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13020    
13021                            String sql = query.toString();
13022    
13023                            Session session = null;
13024    
13025                            try {
13026                                    session = openSession();
13027    
13028                                    Query q = session.createQuery(sql);
13029    
13030                                    QueryPos qPos = QueryPos.getInstance(q);
13031    
13032                                    qPos.add(groupId);
13033    
13034                                    qPos.add(categoryId);
13035    
13036                                    qPos.add(threadId);
13037    
13038                                    count = (Long)q.uniqueResult();
13039    
13040                                    finderCache.putResult(finderPath, finderArgs, count);
13041                            }
13042                            catch (Exception e) {
13043                                    finderCache.removeResult(finderPath, finderArgs);
13044    
13045                                    throw processException(e);
13046                            }
13047                            finally {
13048                                    closeSession(session);
13049                            }
13050                    }
13051    
13052                    return count.intValue();
13053            }
13054    
13055            /**
13056             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13057             *
13058             * @param groupId the group ID
13059             * @param categoryId the category ID
13060             * @param threadId the thread ID
13061             * @return the number of matching message-boards messages that the user has permission to view
13062             */
13063            @Override
13064            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
13065                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13066                            return countByG_C_T(groupId, categoryId, threadId);
13067                    }
13068    
13069                    StringBundler query = new StringBundler(4);
13070    
13071                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13072    
13073                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13074    
13075                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13076    
13077                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13078    
13079                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13080                                    MBMessage.class.getName(),
13081                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13082    
13083                    Session session = null;
13084    
13085                    try {
13086                            session = openSession();
13087    
13088                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13089    
13090                            q.addScalar(COUNT_COLUMN_NAME,
13091                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13092    
13093                            QueryPos qPos = QueryPos.getInstance(q);
13094    
13095                            qPos.add(groupId);
13096    
13097                            qPos.add(categoryId);
13098    
13099                            qPos.add(threadId);
13100    
13101                            Long count = (Long)q.uniqueResult();
13102    
13103                            return count.intValue();
13104                    }
13105                    catch (Exception e) {
13106                            throw processException(e);
13107                    }
13108                    finally {
13109                            closeSession(session);
13110                    }
13111            }
13112    
13113            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
13114            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13115            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
13116            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13118                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
13119                            new String[] {
13120                                    Long.class.getName(), Long.class.getName(),
13121                                    Integer.class.getName(),
13122                                    
13123                            Integer.class.getName(), Integer.class.getName(),
13124                                    OrderByComparator.class.getName()
13125                            });
13126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13127                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
13129                            new String[] {
13130                                    Long.class.getName(), Long.class.getName(),
13131                                    Integer.class.getName()
13132                            },
13133                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
13134                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
13135                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
13136                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13137            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13138                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13139                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
13140                            new String[] {
13141                                    Long.class.getName(), Long.class.getName(),
13142                                    Integer.class.getName()
13143                            });
13144    
13145            /**
13146             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13147             *
13148             * @param groupId the group ID
13149             * @param categoryId the category ID
13150             * @param status the status
13151             * @return the matching message-boards messages
13152             */
13153            @Override
13154            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
13155                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
13156                            QueryUtil.ALL_POS, null);
13157            }
13158    
13159            /**
13160             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13161             *
13162             * <p>
13163             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13164             * </p>
13165             *
13166             * @param groupId the group ID
13167             * @param categoryId the category ID
13168             * @param status the status
13169             * @param start the lower bound of the range of message-boards messages
13170             * @param end the upper bound of the range of message-boards messages (not inclusive)
13171             * @return the range of matching message-boards messages
13172             */
13173            @Override
13174            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13175                    int status, int start, int end) {
13176                    return findByG_C_S(groupId, categoryId, status, start, end, null);
13177            }
13178    
13179            /**
13180             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13181             *
13182             * <p>
13183             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13184             * </p>
13185             *
13186             * @param groupId the group ID
13187             * @param categoryId the category ID
13188             * @param status the status
13189             * @param start the lower bound of the range of message-boards messages
13190             * @param end the upper bound of the range of message-boards messages (not inclusive)
13191             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13192             * @return the ordered range of matching message-boards messages
13193             */
13194            @Override
13195            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13196                    int status, int start, int end,
13197                    OrderByComparator<MBMessage> orderByComparator) {
13198                    return findByG_C_S(groupId, categoryId, status, start, end,
13199                            orderByComparator, true);
13200            }
13201    
13202            /**
13203             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13204             *
13205             * <p>
13206             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13207             * </p>
13208             *
13209             * @param groupId the group ID
13210             * @param categoryId the category ID
13211             * @param status the status
13212             * @param start the lower bound of the range of message-boards messages
13213             * @param end the upper bound of the range of message-boards messages (not inclusive)
13214             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13215             * @param retrieveFromCache whether to retrieve from the finder cache
13216             * @return the ordered range of matching message-boards messages
13217             */
13218            @Override
13219            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13220                    int status, int start, int end,
13221                    OrderByComparator<MBMessage> orderByComparator,
13222                    boolean retrieveFromCache) {
13223                    boolean pagination = true;
13224                    FinderPath finderPath = null;
13225                    Object[] finderArgs = null;
13226    
13227                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13228                                    (orderByComparator == null)) {
13229                            pagination = false;
13230                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13231                            finderArgs = new Object[] { groupId, categoryId, status };
13232                    }
13233                    else {
13234                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13235                            finderArgs = new Object[] {
13236                                            groupId, categoryId, status,
13237                                            
13238                                            start, end, orderByComparator
13239                                    };
13240                    }
13241    
13242                    List<MBMessage> list = null;
13243    
13244                    if (retrieveFromCache) {
13245                            list = (List<MBMessage>)finderCache.getResult(finderPath,
13246                                            finderArgs, this);
13247    
13248                            if ((list != null) && !list.isEmpty()) {
13249                                    for (MBMessage mbMessage : list) {
13250                                            if ((groupId != mbMessage.getGroupId()) ||
13251                                                            (categoryId != mbMessage.getCategoryId()) ||
13252                                                            (status != mbMessage.getStatus())) {
13253                                                    list = null;
13254    
13255                                                    break;
13256                                            }
13257                                    }
13258                            }
13259                    }
13260    
13261                    if (list == null) {
13262                            StringBundler query = null;
13263    
13264                            if (orderByComparator != null) {
13265                                    query = new StringBundler(5 +
13266                                                    (orderByComparator.getOrderByFields().length * 3));
13267                            }
13268                            else {
13269                                    query = new StringBundler(5);
13270                            }
13271    
13272                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13273    
13274                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13275    
13276                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13277    
13278                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13279    
13280                            if (orderByComparator != null) {
13281                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13282                                            orderByComparator);
13283                            }
13284                            else
13285                             if (pagination) {
13286                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13287                            }
13288    
13289                            String sql = query.toString();
13290    
13291                            Session session = null;
13292    
13293                            try {
13294                                    session = openSession();
13295    
13296                                    Query q = session.createQuery(sql);
13297    
13298                                    QueryPos qPos = QueryPos.getInstance(q);
13299    
13300                                    qPos.add(groupId);
13301    
13302                                    qPos.add(categoryId);
13303    
13304                                    qPos.add(status);
13305    
13306                                    if (!pagination) {
13307                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13308                                                            start, end, false);
13309    
13310                                            Collections.sort(list);
13311    
13312                                            list = Collections.unmodifiableList(list);
13313                                    }
13314                                    else {
13315                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13316                                                            start, end);
13317                                    }
13318    
13319                                    cacheResult(list);
13320    
13321                                    finderCache.putResult(finderPath, finderArgs, list);
13322                            }
13323                            catch (Exception e) {
13324                                    finderCache.removeResult(finderPath, finderArgs);
13325    
13326                                    throw processException(e);
13327                            }
13328                            finally {
13329                                    closeSession(session);
13330                            }
13331                    }
13332    
13333                    return list;
13334            }
13335    
13336            /**
13337             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13338             *
13339             * @param groupId the group ID
13340             * @param categoryId the category ID
13341             * @param status the status
13342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13343             * @return the first matching message-boards message
13344             * @throws NoSuchMessageException if a matching message-boards message could not be found
13345             */
13346            @Override
13347            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13348                    int status, OrderByComparator<MBMessage> orderByComparator)
13349                    throws NoSuchMessageException {
13350                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13351                                    orderByComparator);
13352    
13353                    if (mbMessage != null) {
13354                            return mbMessage;
13355                    }
13356    
13357                    StringBundler msg = new StringBundler(8);
13358    
13359                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13360    
13361                    msg.append("groupId=");
13362                    msg.append(groupId);
13363    
13364                    msg.append(", categoryId=");
13365                    msg.append(categoryId);
13366    
13367                    msg.append(", status=");
13368                    msg.append(status);
13369    
13370                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13371    
13372                    throw new NoSuchMessageException(msg.toString());
13373            }
13374    
13375            /**
13376             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13377             *
13378             * @param groupId the group ID
13379             * @param categoryId the category ID
13380             * @param status the status
13381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13382             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13383             */
13384            @Override
13385            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13386                    int status, OrderByComparator<MBMessage> orderByComparator) {
13387                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13388                                    orderByComparator);
13389    
13390                    if (!list.isEmpty()) {
13391                            return list.get(0);
13392                    }
13393    
13394                    return null;
13395            }
13396    
13397            /**
13398             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13399             *
13400             * @param groupId the group ID
13401             * @param categoryId the category ID
13402             * @param status the status
13403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13404             * @return the last matching message-boards message
13405             * @throws NoSuchMessageException if a matching message-boards message could not be found
13406             */
13407            @Override
13408            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13409                    int status, OrderByComparator<MBMessage> orderByComparator)
13410                    throws NoSuchMessageException {
13411                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13412                                    orderByComparator);
13413    
13414                    if (mbMessage != null) {
13415                            return mbMessage;
13416                    }
13417    
13418                    StringBundler msg = new StringBundler(8);
13419    
13420                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13421    
13422                    msg.append("groupId=");
13423                    msg.append(groupId);
13424    
13425                    msg.append(", categoryId=");
13426                    msg.append(categoryId);
13427    
13428                    msg.append(", status=");
13429                    msg.append(status);
13430    
13431                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13432    
13433                    throw new NoSuchMessageException(msg.toString());
13434            }
13435    
13436            /**
13437             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13438             *
13439             * @param groupId the group ID
13440             * @param categoryId the category ID
13441             * @param status the status
13442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13443             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13444             */
13445            @Override
13446            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13447                    int status, OrderByComparator<MBMessage> orderByComparator) {
13448                    int count = countByG_C_S(groupId, categoryId, status);
13449    
13450                    if (count == 0) {
13451                            return null;
13452                    }
13453    
13454                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13455                                    count - 1, count, orderByComparator);
13456    
13457                    if (!list.isEmpty()) {
13458                            return list.get(0);
13459                    }
13460    
13461                    return null;
13462            }
13463    
13464            /**
13465             * 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;.
13466             *
13467             * @param messageId the primary key of the current message-boards message
13468             * @param groupId the group ID
13469             * @param categoryId the category ID
13470             * @param status the status
13471             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13472             * @return the previous, current, and next message-boards message
13473             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13474             */
13475            @Override
13476            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13477                    long categoryId, int status,
13478                    OrderByComparator<MBMessage> orderByComparator)
13479                    throws NoSuchMessageException {
13480                    MBMessage mbMessage = findByPrimaryKey(messageId);
13481    
13482                    Session session = null;
13483    
13484                    try {
13485                            session = openSession();
13486    
13487                            MBMessage[] array = new MBMessageImpl[3];
13488    
13489                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13490                                            categoryId, status, orderByComparator, true);
13491    
13492                            array[1] = mbMessage;
13493    
13494                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13495                                            categoryId, status, orderByComparator, false);
13496    
13497                            return array;
13498                    }
13499                    catch (Exception e) {
13500                            throw processException(e);
13501                    }
13502                    finally {
13503                            closeSession(session);
13504                    }
13505            }
13506    
13507            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13508                    MBMessage mbMessage, long groupId, long categoryId, int status,
13509                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13510                    StringBundler query = null;
13511    
13512                    if (orderByComparator != null) {
13513                            query = new StringBundler(6 +
13514                                            (orderByComparator.getOrderByFields().length * 6));
13515                    }
13516                    else {
13517                            query = new StringBundler(3);
13518                    }
13519    
13520                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13521    
13522                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13523    
13524                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13525    
13526                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13527    
13528                    if (orderByComparator != null) {
13529                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13530    
13531                            if (orderByConditionFields.length > 0) {
13532                                    query.append(WHERE_AND);
13533                            }
13534    
13535                            for (int i = 0; i < orderByConditionFields.length; i++) {
13536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13537                                    query.append(orderByConditionFields[i]);
13538    
13539                                    if ((i + 1) < orderByConditionFields.length) {
13540                                            if (orderByComparator.isAscending() ^ previous) {
13541                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13542                                            }
13543                                            else {
13544                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13545                                            }
13546                                    }
13547                                    else {
13548                                            if (orderByComparator.isAscending() ^ previous) {
13549                                                    query.append(WHERE_GREATER_THAN);
13550                                            }
13551                                            else {
13552                                                    query.append(WHERE_LESSER_THAN);
13553                                            }
13554                                    }
13555                            }
13556    
13557                            query.append(ORDER_BY_CLAUSE);
13558    
13559                            String[] orderByFields = orderByComparator.getOrderByFields();
13560    
13561                            for (int i = 0; i < orderByFields.length; i++) {
13562                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13563                                    query.append(orderByFields[i]);
13564    
13565                                    if ((i + 1) < orderByFields.length) {
13566                                            if (orderByComparator.isAscending() ^ previous) {
13567                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13568                                            }
13569                                            else {
13570                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13571                                            }
13572                                    }
13573                                    else {
13574                                            if (orderByComparator.isAscending() ^ previous) {
13575                                                    query.append(ORDER_BY_ASC);
13576                                            }
13577                                            else {
13578                                                    query.append(ORDER_BY_DESC);
13579                                            }
13580                                    }
13581                            }
13582                    }
13583                    else {
13584                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13585                    }
13586    
13587                    String sql = query.toString();
13588    
13589                    Query q = session.createQuery(sql);
13590    
13591                    q.setFirstResult(0);
13592                    q.setMaxResults(2);
13593    
13594                    QueryPos qPos = QueryPos.getInstance(q);
13595    
13596                    qPos.add(groupId);
13597    
13598                    qPos.add(categoryId);
13599    
13600                    qPos.add(status);
13601    
13602                    if (orderByComparator != null) {
13603                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13604    
13605                            for (Object value : values) {
13606                                    qPos.add(value);
13607                            }
13608                    }
13609    
13610                    List<MBMessage> list = q.list();
13611    
13612                    if (list.size() == 2) {
13613                            return list.get(1);
13614                    }
13615                    else {
13616                            return null;
13617                    }
13618            }
13619    
13620            /**
13621             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13622             *
13623             * @param groupId the group ID
13624             * @param categoryId the category ID
13625             * @param status the status
13626             * @return the matching message-boards messages that the user has permission to view
13627             */
13628            @Override
13629            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13630                    int status) {
13631                    return filterFindByG_C_S(groupId, categoryId, status,
13632                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13633            }
13634    
13635            /**
13636             * 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;.
13637             *
13638             * <p>
13639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13640             * </p>
13641             *
13642             * @param groupId the group ID
13643             * @param categoryId the category ID
13644             * @param status the status
13645             * @param start the lower bound of the range of message-boards messages
13646             * @param end the upper bound of the range of message-boards messages (not inclusive)
13647             * @return the range of matching message-boards messages that the user has permission to view
13648             */
13649            @Override
13650            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13651                    int status, int start, int end) {
13652                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13653            }
13654    
13655            /**
13656             * 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;.
13657             *
13658             * <p>
13659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13660             * </p>
13661             *
13662             * @param groupId the group ID
13663             * @param categoryId the category ID
13664             * @param status the status
13665             * @param start the lower bound of the range of message-boards messages
13666             * @param end the upper bound of the range of message-boards messages (not inclusive)
13667             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13668             * @return the ordered range of matching message-boards messages that the user has permission to view
13669             */
13670            @Override
13671            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13672                    int status, int start, int end,
13673                    OrderByComparator<MBMessage> orderByComparator) {
13674                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13675                            return findByG_C_S(groupId, categoryId, status, start, end,
13676                                    orderByComparator);
13677                    }
13678    
13679                    StringBundler query = null;
13680    
13681                    if (orderByComparator != null) {
13682                            query = new StringBundler(5 +
13683                                            (orderByComparator.getOrderByFields().length * 3));
13684                    }
13685                    else {
13686                            query = new StringBundler(5);
13687                    }
13688    
13689                    if (getDB().isSupportsInlineDistinct()) {
13690                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13691                    }
13692                    else {
13693                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13694                    }
13695    
13696                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13697    
13698                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13699    
13700                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13701    
13702                    if (!getDB().isSupportsInlineDistinct()) {
13703                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13704                    }
13705    
13706                    if (orderByComparator != null) {
13707                            if (getDB().isSupportsInlineDistinct()) {
13708                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13709                                            orderByComparator, true);
13710                            }
13711                            else {
13712                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13713                                            orderByComparator, true);
13714                            }
13715                    }
13716                    else {
13717                            if (getDB().isSupportsInlineDistinct()) {
13718                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13719                            }
13720                            else {
13721                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13722                            }
13723                    }
13724    
13725                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13726                                    MBMessage.class.getName(),
13727                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13728    
13729                    Session session = null;
13730    
13731                    try {
13732                            session = openSession();
13733    
13734                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13735    
13736                            if (getDB().isSupportsInlineDistinct()) {
13737                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13738                            }
13739                            else {
13740                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13741                            }
13742    
13743                            QueryPos qPos = QueryPos.getInstance(q);
13744    
13745                            qPos.add(groupId);
13746    
13747                            qPos.add(categoryId);
13748    
13749                            qPos.add(status);
13750    
13751                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13752                    }
13753                    catch (Exception e) {
13754                            throw processException(e);
13755                    }
13756                    finally {
13757                            closeSession(session);
13758                    }
13759            }
13760    
13761            /**
13762             * 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;.
13763             *
13764             * @param messageId the primary key of the current message-boards message
13765             * @param groupId the group ID
13766             * @param categoryId the category ID
13767             * @param status the status
13768             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13769             * @return the previous, current, and next message-boards message
13770             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13771             */
13772            @Override
13773            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13774                    long groupId, long categoryId, int status,
13775                    OrderByComparator<MBMessage> orderByComparator)
13776                    throws NoSuchMessageException {
13777                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13778                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13779                                    status, orderByComparator);
13780                    }
13781    
13782                    MBMessage mbMessage = findByPrimaryKey(messageId);
13783    
13784                    Session session = null;
13785    
13786                    try {
13787                            session = openSession();
13788    
13789                            MBMessage[] array = new MBMessageImpl[3];
13790    
13791                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13792                                            groupId, categoryId, status, orderByComparator, true);
13793    
13794                            array[1] = mbMessage;
13795    
13796                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13797                                            groupId, categoryId, status, orderByComparator, false);
13798    
13799                            return array;
13800                    }
13801                    catch (Exception e) {
13802                            throw processException(e);
13803                    }
13804                    finally {
13805                            closeSession(session);
13806                    }
13807            }
13808    
13809            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13810                    MBMessage mbMessage, long groupId, long categoryId, int status,
13811                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13812                    StringBundler query = null;
13813    
13814                    if (orderByComparator != null) {
13815                            query = new StringBundler(6 +
13816                                            (orderByComparator.getOrderByFields().length * 6));
13817                    }
13818                    else {
13819                            query = new StringBundler(3);
13820                    }
13821    
13822                    if (getDB().isSupportsInlineDistinct()) {
13823                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13824                    }
13825                    else {
13826                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13827                    }
13828    
13829                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13830    
13831                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13832    
13833                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13834    
13835                    if (!getDB().isSupportsInlineDistinct()) {
13836                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13837                    }
13838    
13839                    if (orderByComparator != null) {
13840                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13841    
13842                            if (orderByConditionFields.length > 0) {
13843                                    query.append(WHERE_AND);
13844                            }
13845    
13846                            for (int i = 0; i < orderByConditionFields.length; i++) {
13847                                    if (getDB().isSupportsInlineDistinct()) {
13848                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13849                                    }
13850                                    else {
13851                                            query.append(_ORDER_BY_ENTITY_TABLE);
13852                                    }
13853    
13854                                    query.append(orderByConditionFields[i]);
13855    
13856                                    if ((i + 1) < orderByConditionFields.length) {
13857                                            if (orderByComparator.isAscending() ^ previous) {
13858                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13859                                            }
13860                                            else {
13861                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13862                                            }
13863                                    }
13864                                    else {
13865                                            if (orderByComparator.isAscending() ^ previous) {
13866                                                    query.append(WHERE_GREATER_THAN);
13867                                            }
13868                                            else {
13869                                                    query.append(WHERE_LESSER_THAN);
13870                                            }
13871                                    }
13872                            }
13873    
13874                            query.append(ORDER_BY_CLAUSE);
13875    
13876                            String[] orderByFields = orderByComparator.getOrderByFields();
13877    
13878                            for (int i = 0; i < orderByFields.length; i++) {
13879                                    if (getDB().isSupportsInlineDistinct()) {
13880                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13881                                    }
13882                                    else {
13883                                            query.append(_ORDER_BY_ENTITY_TABLE);
13884                                    }
13885    
13886                                    query.append(orderByFields[i]);
13887    
13888                                    if ((i + 1) < orderByFields.length) {
13889                                            if (orderByComparator.isAscending() ^ previous) {
13890                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13891                                            }
13892                                            else {
13893                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13894                                            }
13895                                    }
13896                                    else {
13897                                            if (orderByComparator.isAscending() ^ previous) {
13898                                                    query.append(ORDER_BY_ASC);
13899                                            }
13900                                            else {
13901                                                    query.append(ORDER_BY_DESC);
13902                                            }
13903                                    }
13904                            }
13905                    }
13906                    else {
13907                            if (getDB().isSupportsInlineDistinct()) {
13908                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13909                            }
13910                            else {
13911                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13912                            }
13913                    }
13914    
13915                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13916                                    MBMessage.class.getName(),
13917                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13918    
13919                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13920    
13921                    q.setFirstResult(0);
13922                    q.setMaxResults(2);
13923    
13924                    if (getDB().isSupportsInlineDistinct()) {
13925                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13926                    }
13927                    else {
13928                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13929                    }
13930    
13931                    QueryPos qPos = QueryPos.getInstance(q);
13932    
13933                    qPos.add(groupId);
13934    
13935                    qPos.add(categoryId);
13936    
13937                    qPos.add(status);
13938    
13939                    if (orderByComparator != null) {
13940                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13941    
13942                            for (Object value : values) {
13943                                    qPos.add(value);
13944                            }
13945                    }
13946    
13947                    List<MBMessage> list = q.list();
13948    
13949                    if (list.size() == 2) {
13950                            return list.get(1);
13951                    }
13952                    else {
13953                            return null;
13954                    }
13955            }
13956    
13957            /**
13958             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13959             *
13960             * @param groupId the group ID
13961             * @param categoryId the category ID
13962             * @param status the status
13963             */
13964            @Override
13965            public void removeByG_C_S(long groupId, long categoryId, int status) {
13966                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13967                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13968                            remove(mbMessage);
13969                    }
13970            }
13971    
13972            /**
13973             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13974             *
13975             * @param groupId the group ID
13976             * @param categoryId the category ID
13977             * @param status the status
13978             * @return the number of matching message-boards messages
13979             */
13980            @Override
13981            public int countByG_C_S(long groupId, long categoryId, int status) {
13982                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13983    
13984                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13985    
13986                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13987    
13988                    if (count == null) {
13989                            StringBundler query = new StringBundler(4);
13990    
13991                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13992    
13993                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13994    
13995                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13996    
13997                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13998    
13999                            String sql = query.toString();
14000    
14001                            Session session = null;
14002    
14003                            try {
14004                                    session = openSession();
14005    
14006                                    Query q = session.createQuery(sql);
14007    
14008                                    QueryPos qPos = QueryPos.getInstance(q);
14009    
14010                                    qPos.add(groupId);
14011    
14012                                    qPos.add(categoryId);
14013    
14014                                    qPos.add(status);
14015    
14016                                    count = (Long)q.uniqueResult();
14017    
14018                                    finderCache.putResult(finderPath, finderArgs, count);
14019                            }
14020                            catch (Exception e) {
14021                                    finderCache.removeResult(finderPath, finderArgs);
14022    
14023                                    throw processException(e);
14024                            }
14025                            finally {
14026                                    closeSession(session);
14027                            }
14028                    }
14029    
14030                    return count.intValue();
14031            }
14032    
14033            /**
14034             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
14035             *
14036             * @param groupId the group ID
14037             * @param categoryId the category ID
14038             * @param status the status
14039             * @return the number of matching message-boards messages that the user has permission to view
14040             */
14041            @Override
14042            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
14043                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14044                            return countByG_C_S(groupId, categoryId, status);
14045                    }
14046    
14047                    StringBundler query = new StringBundler(4);
14048    
14049                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
14050    
14051                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14052    
14053                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14054    
14055                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14056    
14057                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14058                                    MBMessage.class.getName(),
14059                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14060    
14061                    Session session = null;
14062    
14063                    try {
14064                            session = openSession();
14065    
14066                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
14067    
14068                            q.addScalar(COUNT_COLUMN_NAME,
14069                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14070    
14071                            QueryPos qPos = QueryPos.getInstance(q);
14072    
14073                            qPos.add(groupId);
14074    
14075                            qPos.add(categoryId);
14076    
14077                            qPos.add(status);
14078    
14079                            Long count = (Long)q.uniqueResult();
14080    
14081                            return count.intValue();
14082                    }
14083                    catch (Exception e) {
14084                            throw processException(e);
14085                    }
14086                    finally {
14087                            closeSession(session);
14088                    }
14089            }
14090    
14091            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
14092            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
14093            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
14094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14095                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
14097                            new String[] {
14098                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14099                                    
14100                            Integer.class.getName(), Integer.class.getName(),
14101                                    OrderByComparator.class.getName()
14102                            });
14103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14104                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
14106                            new String[] {
14107                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14108                            },
14109                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14110                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14111                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14112                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14113            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14114                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
14116                            new String[] {
14117                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14118                            });
14119    
14120            /**
14121             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14122             *
14123             * @param userId the user ID
14124             * @param classNameId the class name ID
14125             * @param classPK the class p k
14126             * @return the matching message-boards messages
14127             */
14128            @Override
14129            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14130                    long classPK) {
14131                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
14132                            QueryUtil.ALL_POS, null);
14133            }
14134    
14135            /**
14136             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14137             *
14138             * <p>
14139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14140             * </p>
14141             *
14142             * @param userId the user ID
14143             * @param classNameId the class name ID
14144             * @param classPK the class p k
14145             * @param start the lower bound of the range of message-boards messages
14146             * @param end the upper bound of the range of message-boards messages (not inclusive)
14147             * @return the range of matching message-boards messages
14148             */
14149            @Override
14150            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14151                    long classPK, int start, int end) {
14152                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
14153            }
14154    
14155            /**
14156             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14157             *
14158             * <p>
14159             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14160             * </p>
14161             *
14162             * @param userId the user ID
14163             * @param classNameId the class name ID
14164             * @param classPK the class p k
14165             * @param start the lower bound of the range of message-boards messages
14166             * @param end the upper bound of the range of message-boards messages (not inclusive)
14167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14168             * @return the ordered range of matching message-boards messages
14169             */
14170            @Override
14171            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14172                    long classPK, int start, int end,
14173                    OrderByComparator<MBMessage> orderByComparator) {
14174                    return findByU_C_C(userId, classNameId, classPK, start, end,
14175                            orderByComparator, true);
14176            }
14177    
14178            /**
14179             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14180             *
14181             * <p>
14182             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14183             * </p>
14184             *
14185             * @param userId the user ID
14186             * @param classNameId the class name ID
14187             * @param classPK the class p k
14188             * @param start the lower bound of the range of message-boards messages
14189             * @param end the upper bound of the range of message-boards messages (not inclusive)
14190             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14191             * @param retrieveFromCache whether to retrieve from the finder cache
14192             * @return the ordered range of matching message-boards messages
14193             */
14194            @Override
14195            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14196                    long classPK, int start, int end,
14197                    OrderByComparator<MBMessage> orderByComparator,
14198                    boolean retrieveFromCache) {
14199                    boolean pagination = true;
14200                    FinderPath finderPath = null;
14201                    Object[] finderArgs = null;
14202    
14203                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14204                                    (orderByComparator == null)) {
14205                            pagination = false;
14206                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
14207                            finderArgs = new Object[] { userId, classNameId, classPK };
14208                    }
14209                    else {
14210                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
14211                            finderArgs = new Object[] {
14212                                            userId, classNameId, classPK,
14213                                            
14214                                            start, end, orderByComparator
14215                                    };
14216                    }
14217    
14218                    List<MBMessage> list = null;
14219    
14220                    if (retrieveFromCache) {
14221                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14222                                            finderArgs, this);
14223    
14224                            if ((list != null) && !list.isEmpty()) {
14225                                    for (MBMessage mbMessage : list) {
14226                                            if ((userId != mbMessage.getUserId()) ||
14227                                                            (classNameId != mbMessage.getClassNameId()) ||
14228                                                            (classPK != mbMessage.getClassPK())) {
14229                                                    list = null;
14230    
14231                                                    break;
14232                                            }
14233                                    }
14234                            }
14235                    }
14236    
14237                    if (list == null) {
14238                            StringBundler query = null;
14239    
14240                            if (orderByComparator != null) {
14241                                    query = new StringBundler(5 +
14242                                                    (orderByComparator.getOrderByFields().length * 3));
14243                            }
14244                            else {
14245                                    query = new StringBundler(5);
14246                            }
14247    
14248                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14249    
14250                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14251    
14252                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14253    
14254                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14255    
14256                            if (orderByComparator != null) {
14257                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14258                                            orderByComparator);
14259                            }
14260                            else
14261                             if (pagination) {
14262                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14263                            }
14264    
14265                            String sql = query.toString();
14266    
14267                            Session session = null;
14268    
14269                            try {
14270                                    session = openSession();
14271    
14272                                    Query q = session.createQuery(sql);
14273    
14274                                    QueryPos qPos = QueryPos.getInstance(q);
14275    
14276                                    qPos.add(userId);
14277    
14278                                    qPos.add(classNameId);
14279    
14280                                    qPos.add(classPK);
14281    
14282                                    if (!pagination) {
14283                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14284                                                            start, end, false);
14285    
14286                                            Collections.sort(list);
14287    
14288                                            list = Collections.unmodifiableList(list);
14289                                    }
14290                                    else {
14291                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14292                                                            start, end);
14293                                    }
14294    
14295                                    cacheResult(list);
14296    
14297                                    finderCache.putResult(finderPath, finderArgs, list);
14298                            }
14299                            catch (Exception e) {
14300                                    finderCache.removeResult(finderPath, finderArgs);
14301    
14302                                    throw processException(e);
14303                            }
14304                            finally {
14305                                    closeSession(session);
14306                            }
14307                    }
14308    
14309                    return list;
14310            }
14311    
14312            /**
14313             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14314             *
14315             * @param userId the user ID
14316             * @param classNameId the class name ID
14317             * @param classPK the class p k
14318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14319             * @return the first matching message-boards message
14320             * @throws NoSuchMessageException if a matching message-boards message could not be found
14321             */
14322            @Override
14323            public MBMessage findByU_C_C_First(long userId, long classNameId,
14324                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14325                    throws NoSuchMessageException {
14326                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14327                                    orderByComparator);
14328    
14329                    if (mbMessage != null) {
14330                            return mbMessage;
14331                    }
14332    
14333                    StringBundler msg = new StringBundler(8);
14334    
14335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14336    
14337                    msg.append("userId=");
14338                    msg.append(userId);
14339    
14340                    msg.append(", classNameId=");
14341                    msg.append(classNameId);
14342    
14343                    msg.append(", classPK=");
14344                    msg.append(classPK);
14345    
14346                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14347    
14348                    throw new NoSuchMessageException(msg.toString());
14349            }
14350    
14351            /**
14352             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14353             *
14354             * @param userId the user ID
14355             * @param classNameId the class name ID
14356             * @param classPK the class p k
14357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14358             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14359             */
14360            @Override
14361            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14362                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14363                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14364                                    orderByComparator);
14365    
14366                    if (!list.isEmpty()) {
14367                            return list.get(0);
14368                    }
14369    
14370                    return null;
14371            }
14372    
14373            /**
14374             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14375             *
14376             * @param userId the user ID
14377             * @param classNameId the class name ID
14378             * @param classPK the class p k
14379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14380             * @return the last matching message-boards message
14381             * @throws NoSuchMessageException if a matching message-boards message could not be found
14382             */
14383            @Override
14384            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14385                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14386                    throws NoSuchMessageException {
14387                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14388                                    orderByComparator);
14389    
14390                    if (mbMessage != null) {
14391                            return mbMessage;
14392                    }
14393    
14394                    StringBundler msg = new StringBundler(8);
14395    
14396                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14397    
14398                    msg.append("userId=");
14399                    msg.append(userId);
14400    
14401                    msg.append(", classNameId=");
14402                    msg.append(classNameId);
14403    
14404                    msg.append(", classPK=");
14405                    msg.append(classPK);
14406    
14407                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14408    
14409                    throw new NoSuchMessageException(msg.toString());
14410            }
14411    
14412            /**
14413             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14414             *
14415             * @param userId the user ID
14416             * @param classNameId the class name ID
14417             * @param classPK the class p k
14418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14419             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14420             */
14421            @Override
14422            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14423                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14424                    int count = countByU_C_C(userId, classNameId, classPK);
14425    
14426                    if (count == 0) {
14427                            return null;
14428                    }
14429    
14430                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14431                                    count - 1, count, orderByComparator);
14432    
14433                    if (!list.isEmpty()) {
14434                            return list.get(0);
14435                    }
14436    
14437                    return null;
14438            }
14439    
14440            /**
14441             * 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;.
14442             *
14443             * @param messageId the primary key of the current message-boards message
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 previous, current, and next message-boards message
14449             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14450             */
14451            @Override
14452            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14453                    long classNameId, long classPK,
14454                    OrderByComparator<MBMessage> orderByComparator)
14455                    throws NoSuchMessageException {
14456                    MBMessage mbMessage = findByPrimaryKey(messageId);
14457    
14458                    Session session = null;
14459    
14460                    try {
14461                            session = openSession();
14462    
14463                            MBMessage[] array = new MBMessageImpl[3];
14464    
14465                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14466                                            classNameId, classPK, orderByComparator, true);
14467    
14468                            array[1] = mbMessage;
14469    
14470                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14471                                            classNameId, classPK, orderByComparator, false);
14472    
14473                            return array;
14474                    }
14475                    catch (Exception e) {
14476                            throw processException(e);
14477                    }
14478                    finally {
14479                            closeSession(session);
14480                    }
14481            }
14482    
14483            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14484                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14485                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14486                    StringBundler query = null;
14487    
14488                    if (orderByComparator != null) {
14489                            query = new StringBundler(6 +
14490                                            (orderByComparator.getOrderByFields().length * 6));
14491                    }
14492                    else {
14493                            query = new StringBundler(3);
14494                    }
14495    
14496                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14497    
14498                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14499    
14500                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14501    
14502                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14503    
14504                    if (orderByComparator != null) {
14505                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14506    
14507                            if (orderByConditionFields.length > 0) {
14508                                    query.append(WHERE_AND);
14509                            }
14510    
14511                            for (int i = 0; i < orderByConditionFields.length; i++) {
14512                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14513                                    query.append(orderByConditionFields[i]);
14514    
14515                                    if ((i + 1) < orderByConditionFields.length) {
14516                                            if (orderByComparator.isAscending() ^ previous) {
14517                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14518                                            }
14519                                            else {
14520                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14521                                            }
14522                                    }
14523                                    else {
14524                                            if (orderByComparator.isAscending() ^ previous) {
14525                                                    query.append(WHERE_GREATER_THAN);
14526                                            }
14527                                            else {
14528                                                    query.append(WHERE_LESSER_THAN);
14529                                            }
14530                                    }
14531                            }
14532    
14533                            query.append(ORDER_BY_CLAUSE);
14534    
14535                            String[] orderByFields = orderByComparator.getOrderByFields();
14536    
14537                            for (int i = 0; i < orderByFields.length; i++) {
14538                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14539                                    query.append(orderByFields[i]);
14540    
14541                                    if ((i + 1) < orderByFields.length) {
14542                                            if (orderByComparator.isAscending() ^ previous) {
14543                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14544                                            }
14545                                            else {
14546                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14547                                            }
14548                                    }
14549                                    else {
14550                                            if (orderByComparator.isAscending() ^ previous) {
14551                                                    query.append(ORDER_BY_ASC);
14552                                            }
14553                                            else {
14554                                                    query.append(ORDER_BY_DESC);
14555                                            }
14556                                    }
14557                            }
14558                    }
14559                    else {
14560                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14561                    }
14562    
14563                    String sql = query.toString();
14564    
14565                    Query q = session.createQuery(sql);
14566    
14567                    q.setFirstResult(0);
14568                    q.setMaxResults(2);
14569    
14570                    QueryPos qPos = QueryPos.getInstance(q);
14571    
14572                    qPos.add(userId);
14573    
14574                    qPos.add(classNameId);
14575    
14576                    qPos.add(classPK);
14577    
14578                    if (orderByComparator != null) {
14579                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14580    
14581                            for (Object value : values) {
14582                                    qPos.add(value);
14583                            }
14584                    }
14585    
14586                    List<MBMessage> list = q.list();
14587    
14588                    if (list.size() == 2) {
14589                            return list.get(1);
14590                    }
14591                    else {
14592                            return null;
14593                    }
14594            }
14595    
14596            /**
14597             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14598             *
14599             * @param userId the user ID
14600             * @param classNameId the class name ID
14601             * @param classPK the class p k
14602             */
14603            @Override
14604            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14605                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14606                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14607                            remove(mbMessage);
14608                    }
14609            }
14610    
14611            /**
14612             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14613             *
14614             * @param userId the user ID
14615             * @param classNameId the class name ID
14616             * @param classPK the class p k
14617             * @return the number of matching message-boards messages
14618             */
14619            @Override
14620            public int countByU_C_C(long userId, long classNameId, long classPK) {
14621                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14622    
14623                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14624    
14625                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14626    
14627                    if (count == null) {
14628                            StringBundler query = new StringBundler(4);
14629    
14630                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14631    
14632                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14633    
14634                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14635    
14636                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14637    
14638                            String sql = query.toString();
14639    
14640                            Session session = null;
14641    
14642                            try {
14643                                    session = openSession();
14644    
14645                                    Query q = session.createQuery(sql);
14646    
14647                                    QueryPos qPos = QueryPos.getInstance(q);
14648    
14649                                    qPos.add(userId);
14650    
14651                                    qPos.add(classNameId);
14652    
14653                                    qPos.add(classPK);
14654    
14655                                    count = (Long)q.uniqueResult();
14656    
14657                                    finderCache.putResult(finderPath, finderArgs, count);
14658                            }
14659                            catch (Exception e) {
14660                                    finderCache.removeResult(finderPath, finderArgs);
14661    
14662                                    throw processException(e);
14663                            }
14664                            finally {
14665                                    closeSession(session);
14666                            }
14667                    }
14668    
14669                    return count.intValue();
14670            }
14671    
14672            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14673            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14674            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14675            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14676                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14677                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14678                            new String[] {
14679                                    Long.class.getName(), Long.class.getName(),
14680                                    Integer.class.getName(),
14681                                    
14682                            Integer.class.getName(), Integer.class.getName(),
14683                                    OrderByComparator.class.getName()
14684                            });
14685            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14686                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14687                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14688                            new String[] {
14689                                    Long.class.getName(), Long.class.getName(),
14690                                    Integer.class.getName()
14691                            },
14692                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14693                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14694                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14695                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14696            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14697                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14698                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14699                            new String[] {
14700                                    Long.class.getName(), Long.class.getName(),
14701                                    Integer.class.getName()
14702                            });
14703            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14704                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14705                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14706                            new String[] {
14707                                    Long.class.getName(), Long.class.getName(),
14708                                    Integer.class.getName()
14709                            });
14710    
14711            /**
14712             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14713             *
14714             * @param userId the user ID
14715             * @param classNameId the class name ID
14716             * @param status the status
14717             * @return the matching message-boards messages
14718             */
14719            @Override
14720            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14721                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14722                            QueryUtil.ALL_POS, null);
14723            }
14724    
14725            /**
14726             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14727             *
14728             * <p>
14729             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14730             * </p>
14731             *
14732             * @param userId the user ID
14733             * @param classNameId the class name ID
14734             * @param status the status
14735             * @param start the lower bound of the range of message-boards messages
14736             * @param end the upper bound of the range of message-boards messages (not inclusive)
14737             * @return the range of matching message-boards messages
14738             */
14739            @Override
14740            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14741                    int status, int start, int end) {
14742                    return findByU_C_S(userId, classNameId, status, start, end, null);
14743            }
14744    
14745            /**
14746             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14747             *
14748             * <p>
14749             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14750             * </p>
14751             *
14752             * @param userId the user ID
14753             * @param classNameId the class name ID
14754             * @param status the status
14755             * @param start the lower bound of the range of message-boards messages
14756             * @param end the upper bound of the range of message-boards messages (not inclusive)
14757             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14758             * @return the ordered range of matching message-boards messages
14759             */
14760            @Override
14761            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14762                    int status, int start, int end,
14763                    OrderByComparator<MBMessage> orderByComparator) {
14764                    return findByU_C_S(userId, classNameId, status, start, end,
14765                            orderByComparator, true);
14766            }
14767    
14768            /**
14769             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14770             *
14771             * <p>
14772             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14773             * </p>
14774             *
14775             * @param userId the user ID
14776             * @param classNameId the class name ID
14777             * @param status the status
14778             * @param start the lower bound of the range of message-boards messages
14779             * @param end the upper bound of the range of message-boards messages (not inclusive)
14780             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14781             * @param retrieveFromCache whether to retrieve from the finder cache
14782             * @return the ordered range of matching message-boards messages
14783             */
14784            @Override
14785            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14786                    int status, int start, int end,
14787                    OrderByComparator<MBMessage> orderByComparator,
14788                    boolean retrieveFromCache) {
14789                    boolean pagination = true;
14790                    FinderPath finderPath = null;
14791                    Object[] finderArgs = null;
14792    
14793                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14794                                    (orderByComparator == null)) {
14795                            pagination = false;
14796                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14797                            finderArgs = new Object[] { userId, classNameId, status };
14798                    }
14799                    else {
14800                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14801                            finderArgs = new Object[] {
14802                                            userId, classNameId, status,
14803                                            
14804                                            start, end, orderByComparator
14805                                    };
14806                    }
14807    
14808                    List<MBMessage> list = null;
14809    
14810                    if (retrieveFromCache) {
14811                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14812                                            finderArgs, this);
14813    
14814                            if ((list != null) && !list.isEmpty()) {
14815                                    for (MBMessage mbMessage : list) {
14816                                            if ((userId != mbMessage.getUserId()) ||
14817                                                            (classNameId != mbMessage.getClassNameId()) ||
14818                                                            (status != mbMessage.getStatus())) {
14819                                                    list = null;
14820    
14821                                                    break;
14822                                            }
14823                                    }
14824                            }
14825                    }
14826    
14827                    if (list == null) {
14828                            StringBundler query = null;
14829    
14830                            if (orderByComparator != null) {
14831                                    query = new StringBundler(5 +
14832                                                    (orderByComparator.getOrderByFields().length * 3));
14833                            }
14834                            else {
14835                                    query = new StringBundler(5);
14836                            }
14837    
14838                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14839    
14840                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14841    
14842                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14843    
14844                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14845    
14846                            if (orderByComparator != null) {
14847                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14848                                            orderByComparator);
14849                            }
14850                            else
14851                             if (pagination) {
14852                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14853                            }
14854    
14855                            String sql = query.toString();
14856    
14857                            Session session = null;
14858    
14859                            try {
14860                                    session = openSession();
14861    
14862                                    Query q = session.createQuery(sql);
14863    
14864                                    QueryPos qPos = QueryPos.getInstance(q);
14865    
14866                                    qPos.add(userId);
14867    
14868                                    qPos.add(classNameId);
14869    
14870                                    qPos.add(status);
14871    
14872                                    if (!pagination) {
14873                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14874                                                            start, end, false);
14875    
14876                                            Collections.sort(list);
14877    
14878                                            list = Collections.unmodifiableList(list);
14879                                    }
14880                                    else {
14881                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14882                                                            start, end);
14883                                    }
14884    
14885                                    cacheResult(list);
14886    
14887                                    finderCache.putResult(finderPath, finderArgs, list);
14888                            }
14889                            catch (Exception e) {
14890                                    finderCache.removeResult(finderPath, finderArgs);
14891    
14892                                    throw processException(e);
14893                            }
14894                            finally {
14895                                    closeSession(session);
14896                            }
14897                    }
14898    
14899                    return list;
14900            }
14901    
14902            /**
14903             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14904             *
14905             * @param userId the user ID
14906             * @param classNameId the class name ID
14907             * @param status the status
14908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14909             * @return the first matching message-boards message
14910             * @throws NoSuchMessageException if a matching message-boards message could not be found
14911             */
14912            @Override
14913            public MBMessage findByU_C_S_First(long userId, long classNameId,
14914                    int status, OrderByComparator<MBMessage> orderByComparator)
14915                    throws NoSuchMessageException {
14916                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14917                                    orderByComparator);
14918    
14919                    if (mbMessage != null) {
14920                            return mbMessage;
14921                    }
14922    
14923                    StringBundler msg = new StringBundler(8);
14924    
14925                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14926    
14927                    msg.append("userId=");
14928                    msg.append(userId);
14929    
14930                    msg.append(", classNameId=");
14931                    msg.append(classNameId);
14932    
14933                    msg.append(", status=");
14934                    msg.append(status);
14935    
14936                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14937    
14938                    throw new NoSuchMessageException(msg.toString());
14939            }
14940    
14941            /**
14942             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14943             *
14944             * @param userId the user ID
14945             * @param classNameId the class name ID
14946             * @param status the status
14947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14948             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14949             */
14950            @Override
14951            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14952                    int status, OrderByComparator<MBMessage> orderByComparator) {
14953                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14954                                    orderByComparator);
14955    
14956                    if (!list.isEmpty()) {
14957                            return list.get(0);
14958                    }
14959    
14960                    return null;
14961            }
14962    
14963            /**
14964             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14965             *
14966             * @param userId the user ID
14967             * @param classNameId the class name ID
14968             * @param status the status
14969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14970             * @return the last matching message-boards message
14971             * @throws NoSuchMessageException if a matching message-boards message could not be found
14972             */
14973            @Override
14974            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14975                    int status, OrderByComparator<MBMessage> orderByComparator)
14976                    throws NoSuchMessageException {
14977                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14978                                    orderByComparator);
14979    
14980                    if (mbMessage != null) {
14981                            return mbMessage;
14982                    }
14983    
14984                    StringBundler msg = new StringBundler(8);
14985    
14986                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14987    
14988                    msg.append("userId=");
14989                    msg.append(userId);
14990    
14991                    msg.append(", classNameId=");
14992                    msg.append(classNameId);
14993    
14994                    msg.append(", status=");
14995                    msg.append(status);
14996    
14997                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14998    
14999                    throw new NoSuchMessageException(msg.toString());
15000            }
15001    
15002            /**
15003             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
15004             *
15005             * @param userId the user ID
15006             * @param classNameId the class name ID
15007             * @param status the status
15008             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15009             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15010             */
15011            @Override
15012            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
15013                    int status, OrderByComparator<MBMessage> orderByComparator) {
15014                    int count = countByU_C_S(userId, classNameId, status);
15015    
15016                    if (count == 0) {
15017                            return null;
15018                    }
15019    
15020                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
15021                                    count - 1, count, orderByComparator);
15022    
15023                    if (!list.isEmpty()) {
15024                            return list.get(0);
15025                    }
15026    
15027                    return null;
15028            }
15029    
15030            /**
15031             * 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;.
15032             *
15033             * @param messageId the primary key of the current message-boards message
15034             * @param userId the user ID
15035             * @param classNameId the class name ID
15036             * @param status the status
15037             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15038             * @return the previous, current, and next message-boards message
15039             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15040             */
15041            @Override
15042            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
15043                    long classNameId, int status,
15044                    OrderByComparator<MBMessage> orderByComparator)
15045                    throws NoSuchMessageException {
15046                    MBMessage mbMessage = findByPrimaryKey(messageId);
15047    
15048                    Session session = null;
15049    
15050                    try {
15051                            session = openSession();
15052    
15053                            MBMessage[] array = new MBMessageImpl[3];
15054    
15055                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15056                                            classNameId, status, orderByComparator, true);
15057    
15058                            array[1] = mbMessage;
15059    
15060                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15061                                            classNameId, status, orderByComparator, false);
15062    
15063                            return array;
15064                    }
15065                    catch (Exception e) {
15066                            throw processException(e);
15067                    }
15068                    finally {
15069                            closeSession(session);
15070                    }
15071            }
15072    
15073            protected MBMessage getByU_C_S_PrevAndNext(Session session,
15074                    MBMessage mbMessage, long userId, long classNameId, int status,
15075                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15076                    StringBundler query = null;
15077    
15078                    if (orderByComparator != null) {
15079                            query = new StringBundler(6 +
15080                                            (orderByComparator.getOrderByFields().length * 6));
15081                    }
15082                    else {
15083                            query = new StringBundler(3);
15084                    }
15085    
15086                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15087    
15088                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15089    
15090                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15091    
15092                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15093    
15094                    if (orderByComparator != null) {
15095                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15096    
15097                            if (orderByConditionFields.length > 0) {
15098                                    query.append(WHERE_AND);
15099                            }
15100    
15101                            for (int i = 0; i < orderByConditionFields.length; i++) {
15102                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15103                                    query.append(orderByConditionFields[i]);
15104    
15105                                    if ((i + 1) < orderByConditionFields.length) {
15106                                            if (orderByComparator.isAscending() ^ previous) {
15107                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15108                                            }
15109                                            else {
15110                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15111                                            }
15112                                    }
15113                                    else {
15114                                            if (orderByComparator.isAscending() ^ previous) {
15115                                                    query.append(WHERE_GREATER_THAN);
15116                                            }
15117                                            else {
15118                                                    query.append(WHERE_LESSER_THAN);
15119                                            }
15120                                    }
15121                            }
15122    
15123                            query.append(ORDER_BY_CLAUSE);
15124    
15125                            String[] orderByFields = orderByComparator.getOrderByFields();
15126    
15127                            for (int i = 0; i < orderByFields.length; i++) {
15128                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15129                                    query.append(orderByFields[i]);
15130    
15131                                    if ((i + 1) < orderByFields.length) {
15132                                            if (orderByComparator.isAscending() ^ previous) {
15133                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15134                                            }
15135                                            else {
15136                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15137                                            }
15138                                    }
15139                                    else {
15140                                            if (orderByComparator.isAscending() ^ previous) {
15141                                                    query.append(ORDER_BY_ASC);
15142                                            }
15143                                            else {
15144                                                    query.append(ORDER_BY_DESC);
15145                                            }
15146                                    }
15147                            }
15148                    }
15149                    else {
15150                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15151                    }
15152    
15153                    String sql = query.toString();
15154    
15155                    Query q = session.createQuery(sql);
15156    
15157                    q.setFirstResult(0);
15158                    q.setMaxResults(2);
15159    
15160                    QueryPos qPos = QueryPos.getInstance(q);
15161    
15162                    qPos.add(userId);
15163    
15164                    qPos.add(classNameId);
15165    
15166                    qPos.add(status);
15167    
15168                    if (orderByComparator != null) {
15169                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15170    
15171                            for (Object value : values) {
15172                                    qPos.add(value);
15173                            }
15174                    }
15175    
15176                    List<MBMessage> list = q.list();
15177    
15178                    if (list.size() == 2) {
15179                            return list.get(1);
15180                    }
15181                    else {
15182                            return null;
15183                    }
15184            }
15185    
15186            /**
15187             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15188             *
15189             * <p>
15190             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15191             * </p>
15192             *
15193             * @param userId the user ID
15194             * @param classNameIds the class name IDs
15195             * @param status the status
15196             * @return the matching message-boards messages
15197             */
15198            @Override
15199            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15200                    int status) {
15201                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
15202                            QueryUtil.ALL_POS, null);
15203            }
15204    
15205            /**
15206             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15207             *
15208             * <p>
15209             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15210             * </p>
15211             *
15212             * @param userId the user ID
15213             * @param classNameIds the class name IDs
15214             * @param status the status
15215             * @param start the lower bound of the range of message-boards messages
15216             * @param end the upper bound of the range of message-boards messages (not inclusive)
15217             * @return the range of matching message-boards messages
15218             */
15219            @Override
15220            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15221                    int status, int start, int end) {
15222                    return findByU_C_S(userId, classNameIds, status, start, end, null);
15223            }
15224    
15225            /**
15226             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15227             *
15228             * <p>
15229             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15230             * </p>
15231             *
15232             * @param userId the user ID
15233             * @param classNameIds the class name IDs
15234             * @param status the status
15235             * @param start the lower bound of the range of message-boards messages
15236             * @param end the upper bound of the range of message-boards messages (not inclusive)
15237             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15238             * @return the ordered range of matching message-boards messages
15239             */
15240            @Override
15241            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15242                    int status, int start, int end,
15243                    OrderByComparator<MBMessage> orderByComparator) {
15244                    return findByU_C_S(userId, classNameIds, status, start, end,
15245                            orderByComparator, true);
15246            }
15247    
15248            /**
15249             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;, optionally using the finder cache.
15250             *
15251             * <p>
15252             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15253             * </p>
15254             *
15255             * @param userId the user ID
15256             * @param classNameId the class name ID
15257             * @param status the status
15258             * @param start the lower bound of the range of message-boards messages
15259             * @param end the upper bound of the range of message-boards messages (not inclusive)
15260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15261             * @param retrieveFromCache whether to retrieve from the finder cache
15262             * @return the ordered range of matching message-boards messages
15263             */
15264            @Override
15265            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15266                    int status, int start, int end,
15267                    OrderByComparator<MBMessage> orderByComparator,
15268                    boolean retrieveFromCache) {
15269                    if (classNameIds == null) {
15270                            classNameIds = new long[0];
15271                    }
15272                    else if (classNameIds.length > 1) {
15273                            classNameIds = ArrayUtil.unique(classNameIds);
15274    
15275                            Arrays.sort(classNameIds);
15276                    }
15277    
15278                    if (classNameIds.length == 1) {
15279                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15280                                    orderByComparator);
15281                    }
15282    
15283                    boolean pagination = true;
15284                    Object[] finderArgs = null;
15285    
15286                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15287                                    (orderByComparator == null)) {
15288                            pagination = false;
15289                            finderArgs = new Object[] {
15290                                            userId, StringUtil.merge(classNameIds), status
15291                                    };
15292                    }
15293                    else {
15294                            finderArgs = new Object[] {
15295                                            userId, StringUtil.merge(classNameIds), status,
15296                                            
15297                                            start, end, orderByComparator
15298                                    };
15299                    }
15300    
15301                    List<MBMessage> list = null;
15302    
15303                    if (retrieveFromCache) {
15304                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15305                                            finderArgs, this);
15306    
15307                            if ((list != null) && !list.isEmpty()) {
15308                                    for (MBMessage mbMessage : list) {
15309                                            if ((userId != mbMessage.getUserId()) ||
15310                                                            !ArrayUtil.contains(classNameIds,
15311                                                                    mbMessage.getClassNameId()) ||
15312                                                            (status != mbMessage.getStatus())) {
15313                                                    list = null;
15314    
15315                                                    break;
15316                                            }
15317                                    }
15318                            }
15319                    }
15320    
15321                    if (list == null) {
15322                            StringBundler query = new StringBundler();
15323    
15324                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15325    
15326                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15327    
15328                            if (classNameIds.length > 0) {
15329                                    query.append(StringPool.OPEN_PARENTHESIS);
15330    
15331                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15332    
15333                                    query.append(StringUtil.merge(classNameIds));
15334    
15335                                    query.append(StringPool.CLOSE_PARENTHESIS);
15336    
15337                                    query.append(StringPool.CLOSE_PARENTHESIS);
15338    
15339                                    query.append(WHERE_AND);
15340                            }
15341    
15342                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15343    
15344                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15345                                                    1)), query.index() - 1);
15346    
15347                            if (orderByComparator != null) {
15348                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15349                                            orderByComparator);
15350                            }
15351                            else
15352                             if (pagination) {
15353                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15354                            }
15355    
15356                            String sql = query.toString();
15357    
15358                            Session session = null;
15359    
15360                            try {
15361                                    session = openSession();
15362    
15363                                    Query q = session.createQuery(sql);
15364    
15365                                    QueryPos qPos = QueryPos.getInstance(q);
15366    
15367                                    qPos.add(userId);
15368    
15369                                    qPos.add(status);
15370    
15371                                    if (!pagination) {
15372                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15373                                                            start, end, false);
15374    
15375                                            Collections.sort(list);
15376    
15377                                            list = Collections.unmodifiableList(list);
15378                                    }
15379                                    else {
15380                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15381                                                            start, end);
15382                                    }
15383    
15384                                    cacheResult(list);
15385    
15386                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15387                                            finderArgs, list);
15388                            }
15389                            catch (Exception e) {
15390                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15391                                            finderArgs);
15392    
15393                                    throw processException(e);
15394                            }
15395                            finally {
15396                                    closeSession(session);
15397                            }
15398                    }
15399    
15400                    return list;
15401            }
15402    
15403            /**
15404             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15405             *
15406             * @param userId the user ID
15407             * @param classNameId the class name ID
15408             * @param status the status
15409             */
15410            @Override
15411            public void removeByU_C_S(long userId, long classNameId, int status) {
15412                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15413                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15414                            remove(mbMessage);
15415                    }
15416            }
15417    
15418            /**
15419             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15420             *
15421             * @param userId the user ID
15422             * @param classNameId the class name ID
15423             * @param status the status
15424             * @return the number of matching message-boards messages
15425             */
15426            @Override
15427            public int countByU_C_S(long userId, long classNameId, int status) {
15428                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15429    
15430                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15431    
15432                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
15433    
15434                    if (count == null) {
15435                            StringBundler query = new StringBundler(4);
15436    
15437                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15438    
15439                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15440    
15441                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15442    
15443                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15444    
15445                            String sql = query.toString();
15446    
15447                            Session session = null;
15448    
15449                            try {
15450                                    session = openSession();
15451    
15452                                    Query q = session.createQuery(sql);
15453    
15454                                    QueryPos qPos = QueryPos.getInstance(q);
15455    
15456                                    qPos.add(userId);
15457    
15458                                    qPos.add(classNameId);
15459    
15460                                    qPos.add(status);
15461    
15462                                    count = (Long)q.uniqueResult();
15463    
15464                                    finderCache.putResult(finderPath, finderArgs, count);
15465                            }
15466                            catch (Exception e) {
15467                                    finderCache.removeResult(finderPath, finderArgs);
15468    
15469                                    throw processException(e);
15470                            }
15471                            finally {
15472                                    closeSession(session);
15473                            }
15474                    }
15475    
15476                    return count.intValue();
15477            }
15478    
15479            /**
15480             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15481             *
15482             * @param userId the user ID
15483             * @param classNameIds the class name IDs
15484             * @param status the status
15485             * @return the number of matching message-boards messages
15486             */
15487            @Override
15488            public int countByU_C_S(long userId, long[] classNameIds, int status) {
15489                    if (classNameIds == null) {
15490                            classNameIds = new long[0];
15491                    }
15492                    else if (classNameIds.length > 1) {
15493                            classNameIds = ArrayUtil.unique(classNameIds);
15494    
15495                            Arrays.sort(classNameIds);
15496                    }
15497    
15498                    Object[] finderArgs = new Object[] {
15499                                    userId, StringUtil.merge(classNameIds), status
15500                            };
15501    
15502                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15503                                    finderArgs, this);
15504    
15505                    if (count == null) {
15506                            StringBundler query = new StringBundler();
15507    
15508                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15509    
15510                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15511    
15512                            if (classNameIds.length > 0) {
15513                                    query.append(StringPool.OPEN_PARENTHESIS);
15514    
15515                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15516    
15517                                    query.append(StringUtil.merge(classNameIds));
15518    
15519                                    query.append(StringPool.CLOSE_PARENTHESIS);
15520    
15521                                    query.append(StringPool.CLOSE_PARENTHESIS);
15522    
15523                                    query.append(WHERE_AND);
15524                            }
15525    
15526                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15527    
15528                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15529                                                    1)), query.index() - 1);
15530    
15531                            String sql = query.toString();
15532    
15533                            Session session = null;
15534    
15535                            try {
15536                                    session = openSession();
15537    
15538                                    Query q = session.createQuery(sql);
15539    
15540                                    QueryPos qPos = QueryPos.getInstance(q);
15541    
15542                                    qPos.add(userId);
15543    
15544                                    qPos.add(status);
15545    
15546                                    count = (Long)q.uniqueResult();
15547    
15548                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15549                                            finderArgs, count);
15550                            }
15551                            catch (Exception e) {
15552                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15553                                            finderArgs);
15554    
15555                                    throw processException(e);
15556                            }
15557                            finally {
15558                                    closeSession(session);
15559                            }
15560                    }
15561    
15562                    return count.intValue();
15563            }
15564    
15565            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15566            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15567            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
15568            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15569            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15570                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15571                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15572                            new String[] {
15573                                    Long.class.getName(), Long.class.getName(),
15574                                    Integer.class.getName(),
15575                                    
15576                            Integer.class.getName(), Integer.class.getName(),
15577                                    OrderByComparator.class.getName()
15578                            });
15579            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15580                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15581                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15582                            new String[] {
15583                                    Long.class.getName(), Long.class.getName(),
15584                                    Integer.class.getName()
15585                            },
15586                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15587                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15588                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15589                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15590            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15591                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15592                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15593                            new String[] {
15594                                    Long.class.getName(), Long.class.getName(),
15595                                    Integer.class.getName()
15596                            });
15597    
15598            /**
15599             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15600             *
15601             * @param classNameId the class name ID
15602             * @param classPK the class p k
15603             * @param status the status
15604             * @return the matching message-boards messages
15605             */
15606            @Override
15607            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15608                    int status) {
15609                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15610                            QueryUtil.ALL_POS, null);
15611            }
15612    
15613            /**
15614             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15615             *
15616             * <p>
15617             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15618             * </p>
15619             *
15620             * @param classNameId the class name ID
15621             * @param classPK the class p k
15622             * @param status the status
15623             * @param start the lower bound of the range of message-boards messages
15624             * @param end the upper bound of the range of message-boards messages (not inclusive)
15625             * @return the range of matching message-boards messages
15626             */
15627            @Override
15628            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15629                    int status, int start, int end) {
15630                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15631            }
15632    
15633            /**
15634             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15635             *
15636             * <p>
15637             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15638             * </p>
15639             *
15640             * @param classNameId the class name ID
15641             * @param classPK the class p k
15642             * @param status the status
15643             * @param start the lower bound of the range of message-boards messages
15644             * @param end the upper bound of the range of message-boards messages (not inclusive)
15645             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15646             * @return the ordered range of matching message-boards messages
15647             */
15648            @Override
15649            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15650                    int status, int start, int end,
15651                    OrderByComparator<MBMessage> orderByComparator) {
15652                    return findByC_C_S(classNameId, classPK, status, start, end,
15653                            orderByComparator, true);
15654            }
15655    
15656            /**
15657             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15658             *
15659             * <p>
15660             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15661             * </p>
15662             *
15663             * @param classNameId the class name ID
15664             * @param classPK the class p k
15665             * @param status the status
15666             * @param start the lower bound of the range of message-boards messages
15667             * @param end the upper bound of the range of message-boards messages (not inclusive)
15668             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15669             * @param retrieveFromCache whether to retrieve from the finder cache
15670             * @return the ordered range of matching message-boards messages
15671             */
15672            @Override
15673            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15674                    int status, int start, int end,
15675                    OrderByComparator<MBMessage> orderByComparator,
15676                    boolean retrieveFromCache) {
15677                    boolean pagination = true;
15678                    FinderPath finderPath = null;
15679                    Object[] finderArgs = null;
15680    
15681                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15682                                    (orderByComparator == null)) {
15683                            pagination = false;
15684                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15685                            finderArgs = new Object[] { classNameId, classPK, status };
15686                    }
15687                    else {
15688                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15689                            finderArgs = new Object[] {
15690                                            classNameId, classPK, status,
15691                                            
15692                                            start, end, orderByComparator
15693                                    };
15694                    }
15695    
15696                    List<MBMessage> list = null;
15697    
15698                    if (retrieveFromCache) {
15699                            list = (List<MBMessage>)finderCache.getResult(finderPath,
15700                                            finderArgs, this);
15701    
15702                            if ((list != null) && !list.isEmpty()) {
15703                                    for (MBMessage mbMessage : list) {
15704                                            if ((classNameId != mbMessage.getClassNameId()) ||
15705                                                            (classPK != mbMessage.getClassPK()) ||
15706                                                            (status != mbMessage.getStatus())) {
15707                                                    list = null;
15708    
15709                                                    break;
15710                                            }
15711                                    }
15712                            }
15713                    }
15714    
15715                    if (list == null) {
15716                            StringBundler query = null;
15717    
15718                            if (orderByComparator != null) {
15719                                    query = new StringBundler(5 +
15720                                                    (orderByComparator.getOrderByFields().length * 3));
15721                            }
15722                            else {
15723                                    query = new StringBundler(5);
15724                            }
15725    
15726                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15727    
15728                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15729    
15730                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15731    
15732                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15733    
15734                            if (orderByComparator != null) {
15735                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15736                                            orderByComparator);
15737                            }
15738                            else
15739                             if (pagination) {
15740                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15741                            }
15742    
15743                            String sql = query.toString();
15744    
15745                            Session session = null;
15746    
15747                            try {
15748                                    session = openSession();
15749    
15750                                    Query q = session.createQuery(sql);
15751    
15752                                    QueryPos qPos = QueryPos.getInstance(q);
15753    
15754                                    qPos.add(classNameId);
15755    
15756                                    qPos.add(classPK);
15757    
15758                                    qPos.add(status);
15759    
15760                                    if (!pagination) {
15761                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15762                                                            start, end, false);
15763    
15764                                            Collections.sort(list);
15765    
15766                                            list = Collections.unmodifiableList(list);
15767                                    }
15768                                    else {
15769                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15770                                                            start, end);
15771                                    }
15772    
15773                                    cacheResult(list);
15774    
15775                                    finderCache.putResult(finderPath, finderArgs, list);
15776                            }
15777                            catch (Exception e) {
15778                                    finderCache.removeResult(finderPath, finderArgs);
15779    
15780                                    throw processException(e);
15781                            }
15782                            finally {
15783                                    closeSession(session);
15784                            }
15785                    }
15786    
15787                    return list;
15788            }
15789    
15790            /**
15791             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15792             *
15793             * @param classNameId the class name ID
15794             * @param classPK the class p k
15795             * @param status the status
15796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15797             * @return the first matching message-boards message
15798             * @throws NoSuchMessageException if a matching message-boards message could not be found
15799             */
15800            @Override
15801            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15802                    int status, OrderByComparator<MBMessage> orderByComparator)
15803                    throws NoSuchMessageException {
15804                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15805                                    orderByComparator);
15806    
15807                    if (mbMessage != null) {
15808                            return mbMessage;
15809                    }
15810    
15811                    StringBundler msg = new StringBundler(8);
15812    
15813                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15814    
15815                    msg.append("classNameId=");
15816                    msg.append(classNameId);
15817    
15818                    msg.append(", classPK=");
15819                    msg.append(classPK);
15820    
15821                    msg.append(", status=");
15822                    msg.append(status);
15823    
15824                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15825    
15826                    throw new NoSuchMessageException(msg.toString());
15827            }
15828    
15829            /**
15830             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15831             *
15832             * @param classNameId the class name ID
15833             * @param classPK the class p k
15834             * @param status the status
15835             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15836             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15837             */
15838            @Override
15839            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15840                    int status, OrderByComparator<MBMessage> orderByComparator) {
15841                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15842                                    orderByComparator);
15843    
15844                    if (!list.isEmpty()) {
15845                            return list.get(0);
15846                    }
15847    
15848                    return null;
15849            }
15850    
15851            /**
15852             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15853             *
15854             * @param classNameId the class name ID
15855             * @param classPK the class p k
15856             * @param status the status
15857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15858             * @return the last matching message-boards message
15859             * @throws NoSuchMessageException if a matching message-boards message could not be found
15860             */
15861            @Override
15862            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15863                    int status, OrderByComparator<MBMessage> orderByComparator)
15864                    throws NoSuchMessageException {
15865                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15866                                    orderByComparator);
15867    
15868                    if (mbMessage != null) {
15869                            return mbMessage;
15870                    }
15871    
15872                    StringBundler msg = new StringBundler(8);
15873    
15874                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15875    
15876                    msg.append("classNameId=");
15877                    msg.append(classNameId);
15878    
15879                    msg.append(", classPK=");
15880                    msg.append(classPK);
15881    
15882                    msg.append(", status=");
15883                    msg.append(status);
15884    
15885                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15886    
15887                    throw new NoSuchMessageException(msg.toString());
15888            }
15889    
15890            /**
15891             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15892             *
15893             * @param classNameId the class name ID
15894             * @param classPK the class p k
15895             * @param status the status
15896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15897             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15898             */
15899            @Override
15900            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15901                    int status, OrderByComparator<MBMessage> orderByComparator) {
15902                    int count = countByC_C_S(classNameId, classPK, status);
15903    
15904                    if (count == 0) {
15905                            return null;
15906                    }
15907    
15908                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15909                                    count - 1, count, orderByComparator);
15910    
15911                    if (!list.isEmpty()) {
15912                            return list.get(0);
15913                    }
15914    
15915                    return null;
15916            }
15917    
15918            /**
15919             * 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;.
15920             *
15921             * @param messageId the primary key of the current message-boards message
15922             * @param classNameId the class name ID
15923             * @param classPK the class p k
15924             * @param status the status
15925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15926             * @return the previous, current, and next message-boards message
15927             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15928             */
15929            @Override
15930            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15931                    long classNameId, long classPK, int status,
15932                    OrderByComparator<MBMessage> orderByComparator)
15933                    throws NoSuchMessageException {
15934                    MBMessage mbMessage = findByPrimaryKey(messageId);
15935    
15936                    Session session = null;
15937    
15938                    try {
15939                            session = openSession();
15940    
15941                            MBMessage[] array = new MBMessageImpl[3];
15942    
15943                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15944                                            classPK, status, orderByComparator, true);
15945    
15946                            array[1] = mbMessage;
15947    
15948                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15949                                            classPK, status, orderByComparator, false);
15950    
15951                            return array;
15952                    }
15953                    catch (Exception e) {
15954                            throw processException(e);
15955                    }
15956                    finally {
15957                            closeSession(session);
15958                    }
15959            }
15960    
15961            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15962                    MBMessage mbMessage, long classNameId, long classPK, int status,
15963                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15964                    StringBundler query = null;
15965    
15966                    if (orderByComparator != null) {
15967                            query = new StringBundler(6 +
15968                                            (orderByComparator.getOrderByFields().length * 6));
15969                    }
15970                    else {
15971                            query = new StringBundler(3);
15972                    }
15973    
15974                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15975    
15976                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15977    
15978                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15979    
15980                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15981    
15982                    if (orderByComparator != null) {
15983                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15984    
15985                            if (orderByConditionFields.length > 0) {
15986                                    query.append(WHERE_AND);
15987                            }
15988    
15989                            for (int i = 0; i < orderByConditionFields.length; i++) {
15990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15991                                    query.append(orderByConditionFields[i]);
15992    
15993                                    if ((i + 1) < orderByConditionFields.length) {
15994                                            if (orderByComparator.isAscending() ^ previous) {
15995                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15996                                            }
15997                                            else {
15998                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15999                                            }
16000                                    }
16001                                    else {
16002                                            if (orderByComparator.isAscending() ^ previous) {
16003                                                    query.append(WHERE_GREATER_THAN);
16004                                            }
16005                                            else {
16006                                                    query.append(WHERE_LESSER_THAN);
16007                                            }
16008                                    }
16009                            }
16010    
16011                            query.append(ORDER_BY_CLAUSE);
16012    
16013                            String[] orderByFields = orderByComparator.getOrderByFields();
16014    
16015                            for (int i = 0; i < orderByFields.length; i++) {
16016                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16017                                    query.append(orderByFields[i]);
16018    
16019                                    if ((i + 1) < orderByFields.length) {
16020                                            if (orderByComparator.isAscending() ^ previous) {
16021                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16022                                            }
16023                                            else {
16024                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16025                                            }
16026                                    }
16027                                    else {
16028                                            if (orderByComparator.isAscending() ^ previous) {
16029                                                    query.append(ORDER_BY_ASC);
16030                                            }
16031                                            else {
16032                                                    query.append(ORDER_BY_DESC);
16033                                            }
16034                                    }
16035                            }
16036                    }
16037                    else {
16038                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16039                    }
16040    
16041                    String sql = query.toString();
16042    
16043                    Query q = session.createQuery(sql);
16044    
16045                    q.setFirstResult(0);
16046                    q.setMaxResults(2);
16047    
16048                    QueryPos qPos = QueryPos.getInstance(q);
16049    
16050                    qPos.add(classNameId);
16051    
16052                    qPos.add(classPK);
16053    
16054                    qPos.add(status);
16055    
16056                    if (orderByComparator != null) {
16057                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16058    
16059                            for (Object value : values) {
16060                                    qPos.add(value);
16061                            }
16062                    }
16063    
16064                    List<MBMessage> list = q.list();
16065    
16066                    if (list.size() == 2) {
16067                            return list.get(1);
16068                    }
16069                    else {
16070                            return null;
16071                    }
16072            }
16073    
16074            /**
16075             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16076             *
16077             * @param classNameId the class name ID
16078             * @param classPK the class p k
16079             * @param status the status
16080             */
16081            @Override
16082            public void removeByC_C_S(long classNameId, long classPK, int status) {
16083                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
16084                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16085                            remove(mbMessage);
16086                    }
16087            }
16088    
16089            /**
16090             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16091             *
16092             * @param classNameId the class name ID
16093             * @param classPK the class p k
16094             * @param status the status
16095             * @return the number of matching message-boards messages
16096             */
16097            @Override
16098            public int countByC_C_S(long classNameId, long classPK, int status) {
16099                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
16100    
16101                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16102    
16103                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
16104    
16105                    if (count == null) {
16106                            StringBundler query = new StringBundler(4);
16107    
16108                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16109    
16110                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16111    
16112                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16113    
16114                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16115    
16116                            String sql = query.toString();
16117    
16118                            Session session = null;
16119    
16120                            try {
16121                                    session = openSession();
16122    
16123                                    Query q = session.createQuery(sql);
16124    
16125                                    QueryPos qPos = QueryPos.getInstance(q);
16126    
16127                                    qPos.add(classNameId);
16128    
16129                                    qPos.add(classPK);
16130    
16131                                    qPos.add(status);
16132    
16133                                    count = (Long)q.uniqueResult();
16134    
16135                                    finderCache.putResult(finderPath, finderArgs, count);
16136                            }
16137                            catch (Exception e) {
16138                                    finderCache.removeResult(finderPath, finderArgs);
16139    
16140                                    throw processException(e);
16141                            }
16142                            finally {
16143                                    closeSession(session);
16144                            }
16145                    }
16146    
16147                    return count.intValue();
16148            }
16149    
16150            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
16151            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
16152            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
16153            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16154                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16155                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
16156                            new String[] {
16157                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16158                                    Boolean.class.getName(),
16159                                    
16160                            Integer.class.getName(), Integer.class.getName(),
16161                                    OrderByComparator.class.getName()
16162                            });
16163            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
16164                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16165                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
16167                            new String[] {
16168                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16169                                    Boolean.class.getName()
16170                            },
16171                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16172                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16173                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16174                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
16175                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16176            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16177                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16178                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
16179                            new String[] {
16180                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16181                                    Boolean.class.getName()
16182                            });
16183    
16184            /**
16185             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16186             *
16187             * @param groupId the group ID
16188             * @param categoryId the category ID
16189             * @param threadId the thread ID
16190             * @param answer the answer
16191             * @return the matching message-boards messages
16192             */
16193            @Override
16194            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16195                    long threadId, boolean answer) {
16196                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
16197                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16198            }
16199    
16200            /**
16201             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16202             *
16203             * <p>
16204             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16205             * </p>
16206             *
16207             * @param groupId the group ID
16208             * @param categoryId the category ID
16209             * @param threadId the thread ID
16210             * @param answer the answer
16211             * @param start the lower bound of the range of message-boards messages
16212             * @param end the upper bound of the range of message-boards messages (not inclusive)
16213             * @return the range of matching message-boards messages
16214             */
16215            @Override
16216            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16217                    long threadId, boolean answer, int start, int end) {
16218                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16219                            null);
16220            }
16221    
16222            /**
16223             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16224             *
16225             * <p>
16226             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16227             * </p>
16228             *
16229             * @param groupId the group ID
16230             * @param categoryId the category ID
16231             * @param threadId the thread ID
16232             * @param answer the answer
16233             * @param start the lower bound of the range of message-boards messages
16234             * @param end the upper bound of the range of message-boards messages (not inclusive)
16235             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16236             * @return the ordered range of matching message-boards messages
16237             */
16238            @Override
16239            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16240                    long threadId, boolean answer, int start, int end,
16241                    OrderByComparator<MBMessage> orderByComparator) {
16242                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16243                            orderByComparator, true);
16244            }
16245    
16246            /**
16247             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16248             *
16249             * <p>
16250             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16251             * </p>
16252             *
16253             * @param groupId the group ID
16254             * @param categoryId the category ID
16255             * @param threadId the thread ID
16256             * @param answer the answer
16257             * @param start the lower bound of the range of message-boards messages
16258             * @param end the upper bound of the range of message-boards messages (not inclusive)
16259             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16260             * @param retrieveFromCache whether to retrieve from the finder cache
16261             * @return the ordered range of matching message-boards messages
16262             */
16263            @Override
16264            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16265                    long threadId, boolean answer, int start, int end,
16266                    OrderByComparator<MBMessage> orderByComparator,
16267                    boolean retrieveFromCache) {
16268                    boolean pagination = true;
16269                    FinderPath finderPath = null;
16270                    Object[] finderArgs = null;
16271    
16272                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16273                                    (orderByComparator == null)) {
16274                            pagination = false;
16275                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16276                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16277                    }
16278                    else {
16279                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16280                            finderArgs = new Object[] {
16281                                            groupId, categoryId, threadId, answer,
16282                                            
16283                                            start, end, orderByComparator
16284                                    };
16285                    }
16286    
16287                    List<MBMessage> list = null;
16288    
16289                    if (retrieveFromCache) {
16290                            list = (List<MBMessage>)finderCache.getResult(finderPath,
16291                                            finderArgs, this);
16292    
16293                            if ((list != null) && !list.isEmpty()) {
16294                                    for (MBMessage mbMessage : list) {
16295                                            if ((groupId != mbMessage.getGroupId()) ||
16296                                                            (categoryId != mbMessage.getCategoryId()) ||
16297                                                            (threadId != mbMessage.getThreadId()) ||
16298                                                            (answer != mbMessage.getAnswer())) {
16299                                                    list = null;
16300    
16301                                                    break;
16302                                            }
16303                                    }
16304                            }
16305                    }
16306    
16307                    if (list == null) {
16308                            StringBundler query = null;
16309    
16310                            if (orderByComparator != null) {
16311                                    query = new StringBundler(6 +
16312                                                    (orderByComparator.getOrderByFields().length * 3));
16313                            }
16314                            else {
16315                                    query = new StringBundler(6);
16316                            }
16317    
16318                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16319    
16320                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16321    
16322                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16323    
16324                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16325    
16326                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16327    
16328                            if (orderByComparator != null) {
16329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16330                                            orderByComparator);
16331                            }
16332                            else
16333                             if (pagination) {
16334                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16335                            }
16336    
16337                            String sql = query.toString();
16338    
16339                            Session session = null;
16340    
16341                            try {
16342                                    session = openSession();
16343    
16344                                    Query q = session.createQuery(sql);
16345    
16346                                    QueryPos qPos = QueryPos.getInstance(q);
16347    
16348                                    qPos.add(groupId);
16349    
16350                                    qPos.add(categoryId);
16351    
16352                                    qPos.add(threadId);
16353    
16354                                    qPos.add(answer);
16355    
16356                                    if (!pagination) {
16357                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16358                                                            start, end, false);
16359    
16360                                            Collections.sort(list);
16361    
16362                                            list = Collections.unmodifiableList(list);
16363                                    }
16364                                    else {
16365                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16366                                                            start, end);
16367                                    }
16368    
16369                                    cacheResult(list);
16370    
16371                                    finderCache.putResult(finderPath, finderArgs, list);
16372                            }
16373                            catch (Exception e) {
16374                                    finderCache.removeResult(finderPath, finderArgs);
16375    
16376                                    throw processException(e);
16377                            }
16378                            finally {
16379                                    closeSession(session);
16380                            }
16381                    }
16382    
16383                    return list;
16384            }
16385    
16386            /**
16387             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16388             *
16389             * @param groupId the group ID
16390             * @param categoryId the category ID
16391             * @param threadId the thread ID
16392             * @param answer the answer
16393             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16394             * @return the first matching message-boards message
16395             * @throws NoSuchMessageException if a matching message-boards message could not be found
16396             */
16397            @Override
16398            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16399                    long threadId, boolean answer,
16400                    OrderByComparator<MBMessage> orderByComparator)
16401                    throws NoSuchMessageException {
16402                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16403                                    threadId, answer, orderByComparator);
16404    
16405                    if (mbMessage != null) {
16406                            return mbMessage;
16407                    }
16408    
16409                    StringBundler msg = new StringBundler(10);
16410    
16411                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16412    
16413                    msg.append("groupId=");
16414                    msg.append(groupId);
16415    
16416                    msg.append(", categoryId=");
16417                    msg.append(categoryId);
16418    
16419                    msg.append(", threadId=");
16420                    msg.append(threadId);
16421    
16422                    msg.append(", answer=");
16423                    msg.append(answer);
16424    
16425                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16426    
16427                    throw new NoSuchMessageException(msg.toString());
16428            }
16429    
16430            /**
16431             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16432             *
16433             * @param groupId the group ID
16434             * @param categoryId the category ID
16435             * @param threadId the thread ID
16436             * @param answer the answer
16437             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16438             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16439             */
16440            @Override
16441            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16442                    long threadId, boolean answer,
16443                    OrderByComparator<MBMessage> orderByComparator) {
16444                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16445                                    answer, 0, 1, orderByComparator);
16446    
16447                    if (!list.isEmpty()) {
16448                            return list.get(0);
16449                    }
16450    
16451                    return null;
16452            }
16453    
16454            /**
16455             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16456             *
16457             * @param groupId the group ID
16458             * @param categoryId the category ID
16459             * @param threadId the thread ID
16460             * @param answer the answer
16461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16462             * @return the last matching message-boards message
16463             * @throws NoSuchMessageException if a matching message-boards message could not be found
16464             */
16465            @Override
16466            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16467                    long threadId, boolean answer,
16468                    OrderByComparator<MBMessage> orderByComparator)
16469                    throws NoSuchMessageException {
16470                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16471                                    threadId, answer, orderByComparator);
16472    
16473                    if (mbMessage != null) {
16474                            return mbMessage;
16475                    }
16476    
16477                    StringBundler msg = new StringBundler(10);
16478    
16479                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16480    
16481                    msg.append("groupId=");
16482                    msg.append(groupId);
16483    
16484                    msg.append(", categoryId=");
16485                    msg.append(categoryId);
16486    
16487                    msg.append(", threadId=");
16488                    msg.append(threadId);
16489    
16490                    msg.append(", answer=");
16491                    msg.append(answer);
16492    
16493                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16494    
16495                    throw new NoSuchMessageException(msg.toString());
16496            }
16497    
16498            /**
16499             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16500             *
16501             * @param groupId the group ID
16502             * @param categoryId the category ID
16503             * @param threadId the thread ID
16504             * @param answer the answer
16505             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16506             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16507             */
16508            @Override
16509            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16510                    long threadId, boolean answer,
16511                    OrderByComparator<MBMessage> orderByComparator) {
16512                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16513    
16514                    if (count == 0) {
16515                            return null;
16516                    }
16517    
16518                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16519                                    answer, count - 1, count, orderByComparator);
16520    
16521                    if (!list.isEmpty()) {
16522                            return list.get(0);
16523                    }
16524    
16525                    return null;
16526            }
16527    
16528            /**
16529             * 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;.
16530             *
16531             * @param messageId the primary key of the current message-boards message
16532             * @param groupId the group ID
16533             * @param categoryId the category ID
16534             * @param threadId the thread ID
16535             * @param answer the answer
16536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16537             * @return the previous, current, and next message-boards message
16538             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16539             */
16540            @Override
16541            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16542                    long categoryId, long threadId, boolean answer,
16543                    OrderByComparator<MBMessage> orderByComparator)
16544                    throws NoSuchMessageException {
16545                    MBMessage mbMessage = findByPrimaryKey(messageId);
16546    
16547                    Session session = null;
16548    
16549                    try {
16550                            session = openSession();
16551    
16552                            MBMessage[] array = new MBMessageImpl[3];
16553    
16554                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16555                                            categoryId, threadId, answer, orderByComparator, true);
16556    
16557                            array[1] = mbMessage;
16558    
16559                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16560                                            categoryId, threadId, answer, orderByComparator, false);
16561    
16562                            return array;
16563                    }
16564                    catch (Exception e) {
16565                            throw processException(e);
16566                    }
16567                    finally {
16568                            closeSession(session);
16569                    }
16570            }
16571    
16572            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16573                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16574                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16575                    boolean previous) {
16576                    StringBundler query = null;
16577    
16578                    if (orderByComparator != null) {
16579                            query = new StringBundler(6 +
16580                                            (orderByComparator.getOrderByFields().length * 6));
16581                    }
16582                    else {
16583                            query = new StringBundler(3);
16584                    }
16585    
16586                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16587    
16588                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16589    
16590                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16591    
16592                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16593    
16594                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16595    
16596                    if (orderByComparator != null) {
16597                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16598    
16599                            if (orderByConditionFields.length > 0) {
16600                                    query.append(WHERE_AND);
16601                            }
16602    
16603                            for (int i = 0; i < orderByConditionFields.length; i++) {
16604                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16605                                    query.append(orderByConditionFields[i]);
16606    
16607                                    if ((i + 1) < orderByConditionFields.length) {
16608                                            if (orderByComparator.isAscending() ^ previous) {
16609                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16610                                            }
16611                                            else {
16612                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16613                                            }
16614                                    }
16615                                    else {
16616                                            if (orderByComparator.isAscending() ^ previous) {
16617                                                    query.append(WHERE_GREATER_THAN);
16618                                            }
16619                                            else {
16620                                                    query.append(WHERE_LESSER_THAN);
16621                                            }
16622                                    }
16623                            }
16624    
16625                            query.append(ORDER_BY_CLAUSE);
16626    
16627                            String[] orderByFields = orderByComparator.getOrderByFields();
16628    
16629                            for (int i = 0; i < orderByFields.length; i++) {
16630                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16631                                    query.append(orderByFields[i]);
16632    
16633                                    if ((i + 1) < orderByFields.length) {
16634                                            if (orderByComparator.isAscending() ^ previous) {
16635                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16636                                            }
16637                                            else {
16638                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16639                                            }
16640                                    }
16641                                    else {
16642                                            if (orderByComparator.isAscending() ^ previous) {
16643                                                    query.append(ORDER_BY_ASC);
16644                                            }
16645                                            else {
16646                                                    query.append(ORDER_BY_DESC);
16647                                            }
16648                                    }
16649                            }
16650                    }
16651                    else {
16652                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16653                    }
16654    
16655                    String sql = query.toString();
16656    
16657                    Query q = session.createQuery(sql);
16658    
16659                    q.setFirstResult(0);
16660                    q.setMaxResults(2);
16661    
16662                    QueryPos qPos = QueryPos.getInstance(q);
16663    
16664                    qPos.add(groupId);
16665    
16666                    qPos.add(categoryId);
16667    
16668                    qPos.add(threadId);
16669    
16670                    qPos.add(answer);
16671    
16672                    if (orderByComparator != null) {
16673                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16674    
16675                            for (Object value : values) {
16676                                    qPos.add(value);
16677                            }
16678                    }
16679    
16680                    List<MBMessage> list = q.list();
16681    
16682                    if (list.size() == 2) {
16683                            return list.get(1);
16684                    }
16685                    else {
16686                            return null;
16687                    }
16688            }
16689    
16690            /**
16691             * 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;.
16692             *
16693             * @param groupId the group ID
16694             * @param categoryId the category ID
16695             * @param threadId the thread ID
16696             * @param answer the answer
16697             * @return the matching message-boards messages that the user has permission to view
16698             */
16699            @Override
16700            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16701                    long threadId, boolean answer) {
16702                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16703                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16704            }
16705    
16706            /**
16707             * 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;.
16708             *
16709             * <p>
16710             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16711             * </p>
16712             *
16713             * @param groupId the group ID
16714             * @param categoryId the category ID
16715             * @param threadId the thread ID
16716             * @param answer the answer
16717             * @param start the lower bound of the range of message-boards messages
16718             * @param end the upper bound of the range of message-boards messages (not inclusive)
16719             * @return the range of matching message-boards messages that the user has permission to view
16720             */
16721            @Override
16722            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16723                    long threadId, boolean answer, int start, int end) {
16724                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16725                            start, end, null);
16726            }
16727    
16728            /**
16729             * 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;.
16730             *
16731             * <p>
16732             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16733             * </p>
16734             *
16735             * @param groupId the group ID
16736             * @param categoryId the category ID
16737             * @param threadId the thread ID
16738             * @param answer the answer
16739             * @param start the lower bound of the range of message-boards messages
16740             * @param end the upper bound of the range of message-boards messages (not inclusive)
16741             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16742             * @return the ordered range of matching message-boards messages that the user has permission to view
16743             */
16744            @Override
16745            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16746                    long threadId, boolean answer, int start, int end,
16747                    OrderByComparator<MBMessage> orderByComparator) {
16748                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16749                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16750                                    end, orderByComparator);
16751                    }
16752    
16753                    StringBundler query = null;
16754    
16755                    if (orderByComparator != null) {
16756                            query = new StringBundler(6 +
16757                                            (orderByComparator.getOrderByFields().length * 3));
16758                    }
16759                    else {
16760                            query = new StringBundler(6);
16761                    }
16762    
16763                    if (getDB().isSupportsInlineDistinct()) {
16764                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16765                    }
16766                    else {
16767                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16768                    }
16769    
16770                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16771    
16772                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16773    
16774                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16775    
16776                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16777    
16778                    if (!getDB().isSupportsInlineDistinct()) {
16779                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16780                    }
16781    
16782                    if (orderByComparator != null) {
16783                            if (getDB().isSupportsInlineDistinct()) {
16784                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16785                                            orderByComparator, true);
16786                            }
16787                            else {
16788                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16789                                            orderByComparator, true);
16790                            }
16791                    }
16792                    else {
16793                            if (getDB().isSupportsInlineDistinct()) {
16794                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16795                            }
16796                            else {
16797                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16798                            }
16799                    }
16800    
16801                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16802                                    MBMessage.class.getName(),
16803                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16804    
16805                    Session session = null;
16806    
16807                    try {
16808                            session = openSession();
16809    
16810                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16811    
16812                            if (getDB().isSupportsInlineDistinct()) {
16813                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16814                            }
16815                            else {
16816                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16817                            }
16818    
16819                            QueryPos qPos = QueryPos.getInstance(q);
16820    
16821                            qPos.add(groupId);
16822    
16823                            qPos.add(categoryId);
16824    
16825                            qPos.add(threadId);
16826    
16827                            qPos.add(answer);
16828    
16829                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16830                    }
16831                    catch (Exception e) {
16832                            throw processException(e);
16833                    }
16834                    finally {
16835                            closeSession(session);
16836                    }
16837            }
16838    
16839            /**
16840             * 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;.
16841             *
16842             * @param messageId the primary key of the current message-boards message
16843             * @param groupId the group ID
16844             * @param categoryId the category ID
16845             * @param threadId the thread ID
16846             * @param answer the answer
16847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16848             * @return the previous, current, and next message-boards message
16849             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16850             */
16851            @Override
16852            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16853                    long groupId, long categoryId, long threadId, boolean answer,
16854                    OrderByComparator<MBMessage> orderByComparator)
16855                    throws NoSuchMessageException {
16856                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16857                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16858                                    threadId, answer, orderByComparator);
16859                    }
16860    
16861                    MBMessage mbMessage = findByPrimaryKey(messageId);
16862    
16863                    Session session = null;
16864    
16865                    try {
16866                            session = openSession();
16867    
16868                            MBMessage[] array = new MBMessageImpl[3];
16869    
16870                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16871                                            groupId, categoryId, threadId, answer, orderByComparator,
16872                                            true);
16873    
16874                            array[1] = mbMessage;
16875    
16876                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16877                                            groupId, categoryId, threadId, answer, orderByComparator,
16878                                            false);
16879    
16880                            return array;
16881                    }
16882                    catch (Exception e) {
16883                            throw processException(e);
16884                    }
16885                    finally {
16886                            closeSession(session);
16887                    }
16888            }
16889    
16890            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16891                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16892                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16893                    boolean previous) {
16894                    StringBundler query = null;
16895    
16896                    if (orderByComparator != null) {
16897                            query = new StringBundler(6 +
16898                                            (orderByComparator.getOrderByFields().length * 6));
16899                    }
16900                    else {
16901                            query = new StringBundler(3);
16902                    }
16903    
16904                    if (getDB().isSupportsInlineDistinct()) {
16905                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16906                    }
16907                    else {
16908                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16909                    }
16910    
16911                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16912    
16913                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16914    
16915                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16916    
16917                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16918    
16919                    if (!getDB().isSupportsInlineDistinct()) {
16920                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16921                    }
16922    
16923                    if (orderByComparator != null) {
16924                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16925    
16926                            if (orderByConditionFields.length > 0) {
16927                                    query.append(WHERE_AND);
16928                            }
16929    
16930                            for (int i = 0; i < orderByConditionFields.length; i++) {
16931                                    if (getDB().isSupportsInlineDistinct()) {
16932                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16933                                    }
16934                                    else {
16935                                            query.append(_ORDER_BY_ENTITY_TABLE);
16936                                    }
16937    
16938                                    query.append(orderByConditionFields[i]);
16939    
16940                                    if ((i + 1) < orderByConditionFields.length) {
16941                                            if (orderByComparator.isAscending() ^ previous) {
16942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16943                                            }
16944                                            else {
16945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16946                                            }
16947                                    }
16948                                    else {
16949                                            if (orderByComparator.isAscending() ^ previous) {
16950                                                    query.append(WHERE_GREATER_THAN);
16951                                            }
16952                                            else {
16953                                                    query.append(WHERE_LESSER_THAN);
16954                                            }
16955                                    }
16956                            }
16957    
16958                            query.append(ORDER_BY_CLAUSE);
16959    
16960                            String[] orderByFields = orderByComparator.getOrderByFields();
16961    
16962                            for (int i = 0; i < orderByFields.length; i++) {
16963                                    if (getDB().isSupportsInlineDistinct()) {
16964                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16965                                    }
16966                                    else {
16967                                            query.append(_ORDER_BY_ENTITY_TABLE);
16968                                    }
16969    
16970                                    query.append(orderByFields[i]);
16971    
16972                                    if ((i + 1) < orderByFields.length) {
16973                                            if (orderByComparator.isAscending() ^ previous) {
16974                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16975                                            }
16976                                            else {
16977                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16978                                            }
16979                                    }
16980                                    else {
16981                                            if (orderByComparator.isAscending() ^ previous) {
16982                                                    query.append(ORDER_BY_ASC);
16983                                            }
16984                                            else {
16985                                                    query.append(ORDER_BY_DESC);
16986                                            }
16987                                    }
16988                            }
16989                    }
16990                    else {
16991                            if (getDB().isSupportsInlineDistinct()) {
16992                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16993                            }
16994                            else {
16995                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16996                            }
16997                    }
16998    
16999                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17000                                    MBMessage.class.getName(),
17001                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17002    
17003                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17004    
17005                    q.setFirstResult(0);
17006                    q.setMaxResults(2);
17007    
17008                    if (getDB().isSupportsInlineDistinct()) {
17009                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17010                    }
17011                    else {
17012                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17013                    }
17014    
17015                    QueryPos qPos = QueryPos.getInstance(q);
17016    
17017                    qPos.add(groupId);
17018    
17019                    qPos.add(categoryId);
17020    
17021                    qPos.add(threadId);
17022    
17023                    qPos.add(answer);
17024    
17025                    if (orderByComparator != null) {
17026                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17027    
17028                            for (Object value : values) {
17029                                    qPos.add(value);
17030                            }
17031                    }
17032    
17033                    List<MBMessage> list = q.list();
17034    
17035                    if (list.size() == 2) {
17036                            return list.get(1);
17037                    }
17038                    else {
17039                            return null;
17040                    }
17041            }
17042    
17043            /**
17044             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
17045             *
17046             * @param groupId the group ID
17047             * @param categoryId the category ID
17048             * @param threadId the thread ID
17049             * @param answer the answer
17050             */
17051            @Override
17052            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
17053                    boolean answer) {
17054                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
17055                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17056                            remove(mbMessage);
17057                    }
17058            }
17059    
17060            /**
17061             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17062             *
17063             * @param groupId the group ID
17064             * @param categoryId the category ID
17065             * @param threadId the thread ID
17066             * @param answer the answer
17067             * @return the number of matching message-boards messages
17068             */
17069            @Override
17070            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17071                    boolean answer) {
17072                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
17073    
17074                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17075    
17076                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
17077    
17078                    if (count == null) {
17079                            StringBundler query = new StringBundler(5);
17080    
17081                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17082    
17083                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17084    
17085                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17086    
17087                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17088    
17089                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17090    
17091                            String sql = query.toString();
17092    
17093                            Session session = null;
17094    
17095                            try {
17096                                    session = openSession();
17097    
17098                                    Query q = session.createQuery(sql);
17099    
17100                                    QueryPos qPos = QueryPos.getInstance(q);
17101    
17102                                    qPos.add(groupId);
17103    
17104                                    qPos.add(categoryId);
17105    
17106                                    qPos.add(threadId);
17107    
17108                                    qPos.add(answer);
17109    
17110                                    count = (Long)q.uniqueResult();
17111    
17112                                    finderCache.putResult(finderPath, finderArgs, count);
17113                            }
17114                            catch (Exception e) {
17115                                    finderCache.removeResult(finderPath, finderArgs);
17116    
17117                                    throw processException(e);
17118                            }
17119                            finally {
17120                                    closeSession(session);
17121                            }
17122                    }
17123    
17124                    return count.intValue();
17125            }
17126    
17127            /**
17128             * 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;.
17129             *
17130             * @param groupId the group ID
17131             * @param categoryId the category ID
17132             * @param threadId the thread ID
17133             * @param answer the answer
17134             * @return the number of matching message-boards messages that the user has permission to view
17135             */
17136            @Override
17137            public int filterCountByG_C_T_A(long groupId, long categoryId,
17138                    long threadId, boolean answer) {
17139                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17140                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17141                    }
17142    
17143                    StringBundler query = new StringBundler(5);
17144    
17145                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17146    
17147                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17148    
17149                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17150    
17151                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17152    
17153                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17154    
17155                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17156                                    MBMessage.class.getName(),
17157                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17158    
17159                    Session session = null;
17160    
17161                    try {
17162                            session = openSession();
17163    
17164                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17165    
17166                            q.addScalar(COUNT_COLUMN_NAME,
17167                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17168    
17169                            QueryPos qPos = QueryPos.getInstance(q);
17170    
17171                            qPos.add(groupId);
17172    
17173                            qPos.add(categoryId);
17174    
17175                            qPos.add(threadId);
17176    
17177                            qPos.add(answer);
17178    
17179                            Long count = (Long)q.uniqueResult();
17180    
17181                            return count.intValue();
17182                    }
17183                    catch (Exception e) {
17184                            throw processException(e);
17185                    }
17186                    finally {
17187                            closeSession(session);
17188                    }
17189            }
17190    
17191            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17192            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17193            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17194            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17195            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17196                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17197                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
17198                            new String[] {
17199                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17200                                    Integer.class.getName(),
17201                                    
17202                            Integer.class.getName(), Integer.class.getName(),
17203                                    OrderByComparator.class.getName()
17204                            });
17205            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
17206                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17207                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17208                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
17209                            new String[] {
17210                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17211                                    Integer.class.getName()
17212                            },
17213                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17214                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17215                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17216                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17217                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17218            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17219                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17220                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
17221                            new String[] {
17222                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17223                                    Integer.class.getName()
17224                            });
17225    
17226            /**
17227             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17228             *
17229             * @param groupId the group ID
17230             * @param categoryId the category ID
17231             * @param threadId the thread ID
17232             * @param status the status
17233             * @return the matching message-boards messages
17234             */
17235            @Override
17236            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17237                    long threadId, int status) {
17238                    return findByG_C_T_S(groupId, categoryId, threadId, status,
17239                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17240            }
17241    
17242            /**
17243             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17244             *
17245             * <p>
17246             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17247             * </p>
17248             *
17249             * @param groupId the group ID
17250             * @param categoryId the category ID
17251             * @param threadId the thread ID
17252             * @param status the status
17253             * @param start the lower bound of the range of message-boards messages
17254             * @param end the upper bound of the range of message-boards messages (not inclusive)
17255             * @return the range of matching message-boards messages
17256             */
17257            @Override
17258            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17259                    long threadId, int status, int start, int end) {
17260                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17261                            null);
17262            }
17263    
17264            /**
17265             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17266             *
17267             * <p>
17268             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17269             * </p>
17270             *
17271             * @param groupId the group ID
17272             * @param categoryId the category ID
17273             * @param threadId the thread ID
17274             * @param status the status
17275             * @param start the lower bound of the range of message-boards messages
17276             * @param end the upper bound of the range of message-boards messages (not inclusive)
17277             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17278             * @return the ordered range of matching message-boards messages
17279             */
17280            @Override
17281            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17282                    long threadId, int status, int start, int end,
17283                    OrderByComparator<MBMessage> orderByComparator) {
17284                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17285                            orderByComparator, true);
17286            }
17287    
17288            /**
17289             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17290             *
17291             * <p>
17292             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17293             * </p>
17294             *
17295             * @param groupId the group ID
17296             * @param categoryId the category ID
17297             * @param threadId the thread ID
17298             * @param status the status
17299             * @param start the lower bound of the range of message-boards messages
17300             * @param end the upper bound of the range of message-boards messages (not inclusive)
17301             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17302             * @param retrieveFromCache whether to retrieve from the finder cache
17303             * @return the ordered range of matching message-boards messages
17304             */
17305            @Override
17306            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17307                    long threadId, int status, int start, int end,
17308                    OrderByComparator<MBMessage> orderByComparator,
17309                    boolean retrieveFromCache) {
17310                    boolean pagination = true;
17311                    FinderPath finderPath = null;
17312                    Object[] finderArgs = null;
17313    
17314                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17315                                    (orderByComparator == null)) {
17316                            pagination = false;
17317                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17318                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17319                    }
17320                    else {
17321                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17322                            finderArgs = new Object[] {
17323                                            groupId, categoryId, threadId, status,
17324                                            
17325                                            start, end, orderByComparator
17326                                    };
17327                    }
17328    
17329                    List<MBMessage> list = null;
17330    
17331                    if (retrieveFromCache) {
17332                            list = (List<MBMessage>)finderCache.getResult(finderPath,
17333                                            finderArgs, this);
17334    
17335                            if ((list != null) && !list.isEmpty()) {
17336                                    for (MBMessage mbMessage : list) {
17337                                            if ((groupId != mbMessage.getGroupId()) ||
17338                                                            (categoryId != mbMessage.getCategoryId()) ||
17339                                                            (threadId != mbMessage.getThreadId()) ||
17340                                                            (status != mbMessage.getStatus())) {
17341                                                    list = null;
17342    
17343                                                    break;
17344                                            }
17345                                    }
17346                            }
17347                    }
17348    
17349                    if (list == null) {
17350                            StringBundler query = null;
17351    
17352                            if (orderByComparator != null) {
17353                                    query = new StringBundler(6 +
17354                                                    (orderByComparator.getOrderByFields().length * 3));
17355                            }
17356                            else {
17357                                    query = new StringBundler(6);
17358                            }
17359    
17360                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17361    
17362                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17363    
17364                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17365    
17366                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17367    
17368                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17369    
17370                            if (orderByComparator != null) {
17371                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17372                                            orderByComparator);
17373                            }
17374                            else
17375                             if (pagination) {
17376                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17377                            }
17378    
17379                            String sql = query.toString();
17380    
17381                            Session session = null;
17382    
17383                            try {
17384                                    session = openSession();
17385    
17386                                    Query q = session.createQuery(sql);
17387    
17388                                    QueryPos qPos = QueryPos.getInstance(q);
17389    
17390                                    qPos.add(groupId);
17391    
17392                                    qPos.add(categoryId);
17393    
17394                                    qPos.add(threadId);
17395    
17396                                    qPos.add(status);
17397    
17398                                    if (!pagination) {
17399                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17400                                                            start, end, false);
17401    
17402                                            Collections.sort(list);
17403    
17404                                            list = Collections.unmodifiableList(list);
17405                                    }
17406                                    else {
17407                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17408                                                            start, end);
17409                                    }
17410    
17411                                    cacheResult(list);
17412    
17413                                    finderCache.putResult(finderPath, finderArgs, list);
17414                            }
17415                            catch (Exception e) {
17416                                    finderCache.removeResult(finderPath, finderArgs);
17417    
17418                                    throw processException(e);
17419                            }
17420                            finally {
17421                                    closeSession(session);
17422                            }
17423                    }
17424    
17425                    return list;
17426            }
17427    
17428            /**
17429             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17430             *
17431             * @param groupId the group ID
17432             * @param categoryId the category ID
17433             * @param threadId the thread ID
17434             * @param status the status
17435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17436             * @return the first matching message-boards message
17437             * @throws NoSuchMessageException if a matching message-boards message could not be found
17438             */
17439            @Override
17440            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17441                    long threadId, int status,
17442                    OrderByComparator<MBMessage> orderByComparator)
17443                    throws NoSuchMessageException {
17444                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17445                                    threadId, status, orderByComparator);
17446    
17447                    if (mbMessage != null) {
17448                            return mbMessage;
17449                    }
17450    
17451                    StringBundler msg = new StringBundler(10);
17452    
17453                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17454    
17455                    msg.append("groupId=");
17456                    msg.append(groupId);
17457    
17458                    msg.append(", categoryId=");
17459                    msg.append(categoryId);
17460    
17461                    msg.append(", threadId=");
17462                    msg.append(threadId);
17463    
17464                    msg.append(", status=");
17465                    msg.append(status);
17466    
17467                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17468    
17469                    throw new NoSuchMessageException(msg.toString());
17470            }
17471    
17472            /**
17473             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17474             *
17475             * @param groupId the group ID
17476             * @param categoryId the category ID
17477             * @param threadId the thread ID
17478             * @param status the status
17479             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17480             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17481             */
17482            @Override
17483            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17484                    long threadId, int status,
17485                    OrderByComparator<MBMessage> orderByComparator) {
17486                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17487                                    status, 0, 1, orderByComparator);
17488    
17489                    if (!list.isEmpty()) {
17490                            return list.get(0);
17491                    }
17492    
17493                    return null;
17494            }
17495    
17496            /**
17497             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17498             *
17499             * @param groupId the group ID
17500             * @param categoryId the category ID
17501             * @param threadId the thread ID
17502             * @param status the status
17503             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17504             * @return the last matching message-boards message
17505             * @throws NoSuchMessageException if a matching message-boards message could not be found
17506             */
17507            @Override
17508            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17509                    long threadId, int status,
17510                    OrderByComparator<MBMessage> orderByComparator)
17511                    throws NoSuchMessageException {
17512                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17513                                    threadId, status, orderByComparator);
17514    
17515                    if (mbMessage != null) {
17516                            return mbMessage;
17517                    }
17518    
17519                    StringBundler msg = new StringBundler(10);
17520    
17521                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17522    
17523                    msg.append("groupId=");
17524                    msg.append(groupId);
17525    
17526                    msg.append(", categoryId=");
17527                    msg.append(categoryId);
17528    
17529                    msg.append(", threadId=");
17530                    msg.append(threadId);
17531    
17532                    msg.append(", status=");
17533                    msg.append(status);
17534    
17535                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17536    
17537                    throw new NoSuchMessageException(msg.toString());
17538            }
17539    
17540            /**
17541             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17542             *
17543             * @param groupId the group ID
17544             * @param categoryId the category ID
17545             * @param threadId the thread ID
17546             * @param status the status
17547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17548             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17549             */
17550            @Override
17551            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17552                    long threadId, int status,
17553                    OrderByComparator<MBMessage> orderByComparator) {
17554                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17555    
17556                    if (count == 0) {
17557                            return null;
17558                    }
17559    
17560                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17561                                    status, count - 1, count, orderByComparator);
17562    
17563                    if (!list.isEmpty()) {
17564                            return list.get(0);
17565                    }
17566    
17567                    return null;
17568            }
17569    
17570            /**
17571             * 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;.
17572             *
17573             * @param messageId the primary key of the current message-boards message
17574             * @param groupId the group ID
17575             * @param categoryId the category ID
17576             * @param threadId the thread ID
17577             * @param status the status
17578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17579             * @return the previous, current, and next message-boards message
17580             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17581             */
17582            @Override
17583            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17584                    long categoryId, long threadId, int status,
17585                    OrderByComparator<MBMessage> orderByComparator)
17586                    throws NoSuchMessageException {
17587                    MBMessage mbMessage = findByPrimaryKey(messageId);
17588    
17589                    Session session = null;
17590    
17591                    try {
17592                            session = openSession();
17593    
17594                            MBMessage[] array = new MBMessageImpl[3];
17595    
17596                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17597                                            categoryId, threadId, status, orderByComparator, true);
17598    
17599                            array[1] = mbMessage;
17600    
17601                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17602                                            categoryId, threadId, status, orderByComparator, false);
17603    
17604                            return array;
17605                    }
17606                    catch (Exception e) {
17607                            throw processException(e);
17608                    }
17609                    finally {
17610                            closeSession(session);
17611                    }
17612            }
17613    
17614            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17615                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17616                    int status, OrderByComparator<MBMessage> orderByComparator,
17617                    boolean previous) {
17618                    StringBundler query = null;
17619    
17620                    if (orderByComparator != null) {
17621                            query = new StringBundler(6 +
17622                                            (orderByComparator.getOrderByFields().length * 6));
17623                    }
17624                    else {
17625                            query = new StringBundler(3);
17626                    }
17627    
17628                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17629    
17630                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17631    
17632                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17633    
17634                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17635    
17636                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17637    
17638                    if (orderByComparator != null) {
17639                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17640    
17641                            if (orderByConditionFields.length > 0) {
17642                                    query.append(WHERE_AND);
17643                            }
17644    
17645                            for (int i = 0; i < orderByConditionFields.length; i++) {
17646                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17647                                    query.append(orderByConditionFields[i]);
17648    
17649                                    if ((i + 1) < orderByConditionFields.length) {
17650                                            if (orderByComparator.isAscending() ^ previous) {
17651                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17652                                            }
17653                                            else {
17654                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17655                                            }
17656                                    }
17657                                    else {
17658                                            if (orderByComparator.isAscending() ^ previous) {
17659                                                    query.append(WHERE_GREATER_THAN);
17660                                            }
17661                                            else {
17662                                                    query.append(WHERE_LESSER_THAN);
17663                                            }
17664                                    }
17665                            }
17666    
17667                            query.append(ORDER_BY_CLAUSE);
17668    
17669                            String[] orderByFields = orderByComparator.getOrderByFields();
17670    
17671                            for (int i = 0; i < orderByFields.length; i++) {
17672                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17673                                    query.append(orderByFields[i]);
17674    
17675                                    if ((i + 1) < orderByFields.length) {
17676                                            if (orderByComparator.isAscending() ^ previous) {
17677                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17678                                            }
17679                                            else {
17680                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17681                                            }
17682                                    }
17683                                    else {
17684                                            if (orderByComparator.isAscending() ^ previous) {
17685                                                    query.append(ORDER_BY_ASC);
17686                                            }
17687                                            else {
17688                                                    query.append(ORDER_BY_DESC);
17689                                            }
17690                                    }
17691                            }
17692                    }
17693                    else {
17694                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17695                    }
17696    
17697                    String sql = query.toString();
17698    
17699                    Query q = session.createQuery(sql);
17700    
17701                    q.setFirstResult(0);
17702                    q.setMaxResults(2);
17703    
17704                    QueryPos qPos = QueryPos.getInstance(q);
17705    
17706                    qPos.add(groupId);
17707    
17708                    qPos.add(categoryId);
17709    
17710                    qPos.add(threadId);
17711    
17712                    qPos.add(status);
17713    
17714                    if (orderByComparator != null) {
17715                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17716    
17717                            for (Object value : values) {
17718                                    qPos.add(value);
17719                            }
17720                    }
17721    
17722                    List<MBMessage> list = q.list();
17723    
17724                    if (list.size() == 2) {
17725                            return list.get(1);
17726                    }
17727                    else {
17728                            return null;
17729                    }
17730            }
17731    
17732            /**
17733             * 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;.
17734             *
17735             * @param groupId the group ID
17736             * @param categoryId the category ID
17737             * @param threadId the thread ID
17738             * @param status the status
17739             * @return the matching message-boards messages that the user has permission to view
17740             */
17741            @Override
17742            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17743                    long threadId, int status) {
17744                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17745                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17746            }
17747    
17748            /**
17749             * 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;.
17750             *
17751             * <p>
17752             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17753             * </p>
17754             *
17755             * @param groupId the group ID
17756             * @param categoryId the category ID
17757             * @param threadId the thread ID
17758             * @param status the status
17759             * @param start the lower bound of the range of message-boards messages
17760             * @param end the upper bound of the range of message-boards messages (not inclusive)
17761             * @return the range of matching message-boards messages that the user has permission to view
17762             */
17763            @Override
17764            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17765                    long threadId, int status, int start, int end) {
17766                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17767                            start, end, null);
17768            }
17769    
17770            /**
17771             * 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;.
17772             *
17773             * <p>
17774             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17775             * </p>
17776             *
17777             * @param groupId the group ID
17778             * @param categoryId the category ID
17779             * @param threadId the thread ID
17780             * @param status the status
17781             * @param start the lower bound of the range of message-boards messages
17782             * @param end the upper bound of the range of message-boards messages (not inclusive)
17783             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17784             * @return the ordered range of matching message-boards messages that the user has permission to view
17785             */
17786            @Override
17787            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17788                    long threadId, int status, int start, int end,
17789                    OrderByComparator<MBMessage> orderByComparator) {
17790                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17791                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17792                                    end, orderByComparator);
17793                    }
17794    
17795                    StringBundler query = null;
17796    
17797                    if (orderByComparator != null) {
17798                            query = new StringBundler(6 +
17799                                            (orderByComparator.getOrderByFields().length * 3));
17800                    }
17801                    else {
17802                            query = new StringBundler(6);
17803                    }
17804    
17805                    if (getDB().isSupportsInlineDistinct()) {
17806                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17807                    }
17808                    else {
17809                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17810                    }
17811    
17812                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17813    
17814                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17815    
17816                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17817    
17818                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17819    
17820                    if (!getDB().isSupportsInlineDistinct()) {
17821                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17822                    }
17823    
17824                    if (orderByComparator != null) {
17825                            if (getDB().isSupportsInlineDistinct()) {
17826                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17827                                            orderByComparator, true);
17828                            }
17829                            else {
17830                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17831                                            orderByComparator, true);
17832                            }
17833                    }
17834                    else {
17835                            if (getDB().isSupportsInlineDistinct()) {
17836                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17837                            }
17838                            else {
17839                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17840                            }
17841                    }
17842    
17843                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17844                                    MBMessage.class.getName(),
17845                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17846    
17847                    Session session = null;
17848    
17849                    try {
17850                            session = openSession();
17851    
17852                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17853    
17854                            if (getDB().isSupportsInlineDistinct()) {
17855                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17856                            }
17857                            else {
17858                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17859                            }
17860    
17861                            QueryPos qPos = QueryPos.getInstance(q);
17862    
17863                            qPos.add(groupId);
17864    
17865                            qPos.add(categoryId);
17866    
17867                            qPos.add(threadId);
17868    
17869                            qPos.add(status);
17870    
17871                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17872                    }
17873                    catch (Exception e) {
17874                            throw processException(e);
17875                    }
17876                    finally {
17877                            closeSession(session);
17878                    }
17879            }
17880    
17881            /**
17882             * 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;.
17883             *
17884             * @param messageId the primary key of the current message-boards message
17885             * @param groupId the group ID
17886             * @param categoryId the category ID
17887             * @param threadId the thread ID
17888             * @param status the status
17889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17890             * @return the previous, current, and next message-boards message
17891             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17892             */
17893            @Override
17894            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17895                    long groupId, long categoryId, long threadId, int status,
17896                    OrderByComparator<MBMessage> orderByComparator)
17897                    throws NoSuchMessageException {
17898                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17899                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17900                                    threadId, status, orderByComparator);
17901                    }
17902    
17903                    MBMessage mbMessage = findByPrimaryKey(messageId);
17904    
17905                    Session session = null;
17906    
17907                    try {
17908                            session = openSession();
17909    
17910                            MBMessage[] array = new MBMessageImpl[3];
17911    
17912                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17913                                            groupId, categoryId, threadId, status, orderByComparator,
17914                                            true);
17915    
17916                            array[1] = mbMessage;
17917    
17918                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17919                                            groupId, categoryId, threadId, status, orderByComparator,
17920                                            false);
17921    
17922                            return array;
17923                    }
17924                    catch (Exception e) {
17925                            throw processException(e);
17926                    }
17927                    finally {
17928                            closeSession(session);
17929                    }
17930            }
17931    
17932            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17933                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17934                    int status, OrderByComparator<MBMessage> orderByComparator,
17935                    boolean previous) {
17936                    StringBundler query = null;
17937    
17938                    if (orderByComparator != null) {
17939                            query = new StringBundler(6 +
17940                                            (orderByComparator.getOrderByFields().length * 6));
17941                    }
17942                    else {
17943                            query = new StringBundler(3);
17944                    }
17945    
17946                    if (getDB().isSupportsInlineDistinct()) {
17947                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17948                    }
17949                    else {
17950                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17951                    }
17952    
17953                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17954    
17955                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17956    
17957                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17958    
17959                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17960    
17961                    if (!getDB().isSupportsInlineDistinct()) {
17962                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17963                    }
17964    
17965                    if (orderByComparator != null) {
17966                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17967    
17968                            if (orderByConditionFields.length > 0) {
17969                                    query.append(WHERE_AND);
17970                            }
17971    
17972                            for (int i = 0; i < orderByConditionFields.length; i++) {
17973                                    if (getDB().isSupportsInlineDistinct()) {
17974                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17975                                    }
17976                                    else {
17977                                            query.append(_ORDER_BY_ENTITY_TABLE);
17978                                    }
17979    
17980                                    query.append(orderByConditionFields[i]);
17981    
17982                                    if ((i + 1) < orderByConditionFields.length) {
17983                                            if (orderByComparator.isAscending() ^ previous) {
17984                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17985                                            }
17986                                            else {
17987                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17988                                            }
17989                                    }
17990                                    else {
17991                                            if (orderByComparator.isAscending() ^ previous) {
17992                                                    query.append(WHERE_GREATER_THAN);
17993                                            }
17994                                            else {
17995                                                    query.append(WHERE_LESSER_THAN);
17996                                            }
17997                                    }
17998                            }
17999    
18000                            query.append(ORDER_BY_CLAUSE);
18001    
18002                            String[] orderByFields = orderByComparator.getOrderByFields();
18003    
18004                            for (int i = 0; i < orderByFields.length; i++) {
18005                                    if (getDB().isSupportsInlineDistinct()) {
18006                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18007                                    }
18008                                    else {
18009                                            query.append(_ORDER_BY_ENTITY_TABLE);
18010                                    }
18011    
18012                                    query.append(orderByFields[i]);
18013    
18014                                    if ((i + 1) < orderByFields.length) {
18015                                            if (orderByComparator.isAscending() ^ previous) {
18016                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18017                                            }
18018                                            else {
18019                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18020                                            }
18021                                    }
18022                                    else {
18023                                            if (orderByComparator.isAscending() ^ previous) {
18024                                                    query.append(ORDER_BY_ASC);
18025                                            }
18026                                            else {
18027                                                    query.append(ORDER_BY_DESC);
18028                                            }
18029                                    }
18030                            }
18031                    }
18032                    else {
18033                            if (getDB().isSupportsInlineDistinct()) {
18034                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18035                            }
18036                            else {
18037                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18038                            }
18039                    }
18040    
18041                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18042                                    MBMessage.class.getName(),
18043                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18044    
18045                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
18046    
18047                    q.setFirstResult(0);
18048                    q.setMaxResults(2);
18049    
18050                    if (getDB().isSupportsInlineDistinct()) {
18051                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18052                    }
18053                    else {
18054                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18055                    }
18056    
18057                    QueryPos qPos = QueryPos.getInstance(q);
18058    
18059                    qPos.add(groupId);
18060    
18061                    qPos.add(categoryId);
18062    
18063                    qPos.add(threadId);
18064    
18065                    qPos.add(status);
18066    
18067                    if (orderByComparator != null) {
18068                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18069    
18070                            for (Object value : values) {
18071                                    qPos.add(value);
18072                            }
18073                    }
18074    
18075                    List<MBMessage> list = q.list();
18076    
18077                    if (list.size() == 2) {
18078                            return list.get(1);
18079                    }
18080                    else {
18081                            return null;
18082                    }
18083            }
18084    
18085            /**
18086             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
18087             *
18088             * @param groupId the group ID
18089             * @param categoryId the category ID
18090             * @param threadId the thread ID
18091             * @param status the status
18092             */
18093            @Override
18094            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
18095                    int status) {
18096                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
18097                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18098                            remove(mbMessage);
18099                    }
18100            }
18101    
18102            /**
18103             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18104             *
18105             * @param groupId the group ID
18106             * @param categoryId the category ID
18107             * @param threadId the thread ID
18108             * @param status the status
18109             * @return the number of matching message-boards messages
18110             */
18111            @Override
18112            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18113                    int status) {
18114                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
18115    
18116                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18117    
18118                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18119    
18120                    if (count == null) {
18121                            StringBundler query = new StringBundler(5);
18122    
18123                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18124    
18125                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18126    
18127                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18128    
18129                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18130    
18131                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18132    
18133                            String sql = query.toString();
18134    
18135                            Session session = null;
18136    
18137                            try {
18138                                    session = openSession();
18139    
18140                                    Query q = session.createQuery(sql);
18141    
18142                                    QueryPos qPos = QueryPos.getInstance(q);
18143    
18144                                    qPos.add(groupId);
18145    
18146                                    qPos.add(categoryId);
18147    
18148                                    qPos.add(threadId);
18149    
18150                                    qPos.add(status);
18151    
18152                                    count = (Long)q.uniqueResult();
18153    
18154                                    finderCache.putResult(finderPath, finderArgs, count);
18155                            }
18156                            catch (Exception e) {
18157                                    finderCache.removeResult(finderPath, finderArgs);
18158    
18159                                    throw processException(e);
18160                            }
18161                            finally {
18162                                    closeSession(session);
18163                            }
18164                    }
18165    
18166                    return count.intValue();
18167            }
18168    
18169            /**
18170             * 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;.
18171             *
18172             * @param groupId the group ID
18173             * @param categoryId the category ID
18174             * @param threadId the thread ID
18175             * @param status the status
18176             * @return the number of matching message-boards messages that the user has permission to view
18177             */
18178            @Override
18179            public int filterCountByG_C_T_S(long groupId, long categoryId,
18180                    long threadId, int status) {
18181                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18182                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18183                    }
18184    
18185                    StringBundler query = new StringBundler(5);
18186    
18187                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18188    
18189                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18190    
18191                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18192    
18193                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18194    
18195                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18196    
18197                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18198                                    MBMessage.class.getName(),
18199                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18200    
18201                    Session session = null;
18202    
18203                    try {
18204                            session = openSession();
18205    
18206                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
18207    
18208                            q.addScalar(COUNT_COLUMN_NAME,
18209                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18210    
18211                            QueryPos qPos = QueryPos.getInstance(q);
18212    
18213                            qPos.add(groupId);
18214    
18215                            qPos.add(categoryId);
18216    
18217                            qPos.add(threadId);
18218    
18219                            qPos.add(status);
18220    
18221                            Long count = (Long)q.uniqueResult();
18222    
18223                            return count.intValue();
18224                    }
18225                    catch (Exception e) {
18226                            throw processException(e);
18227                    }
18228                    finally {
18229                            closeSession(session);
18230                    }
18231            }
18232    
18233            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18234            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18235            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18236            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18237            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18238                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18239                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
18240                            new String[] {
18241                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18242                                    Integer.class.getName(),
18243                                    
18244                            Integer.class.getName(), Integer.class.getName(),
18245                                    OrderByComparator.class.getName()
18246                            });
18247            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
18248                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18249                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18250                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
18251                            new String[] {
18252                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18253                                    Integer.class.getName()
18254                            },
18255                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
18256                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
18257                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
18258                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18259                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18260            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18261                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
18263                            new String[] {
18264                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18265                                    Integer.class.getName()
18266                            });
18267    
18268            /**
18269             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18270             *
18271             * @param userId the user ID
18272             * @param classNameId the class name ID
18273             * @param classPK the class p k
18274             * @param status the status
18275             * @return the matching message-boards messages
18276             */
18277            @Override
18278            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18279                    long classPK, int status) {
18280                    return findByU_C_C_S(userId, classNameId, classPK, status,
18281                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18282            }
18283    
18284            /**
18285             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18286             *
18287             * <p>
18288             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18289             * </p>
18290             *
18291             * @param userId the user ID
18292             * @param classNameId the class name ID
18293             * @param classPK the class p k
18294             * @param status the status
18295             * @param start the lower bound of the range of message-boards messages
18296             * @param end the upper bound of the range of message-boards messages (not inclusive)
18297             * @return the range of matching message-boards messages
18298             */
18299            @Override
18300            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18301                    long classPK, int status, int start, int end) {
18302                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18303                            null);
18304            }
18305    
18306            /**
18307             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18308             *
18309             * <p>
18310             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18311             * </p>
18312             *
18313             * @param userId the user ID
18314             * @param classNameId the class name ID
18315             * @param classPK the class p k
18316             * @param status the status
18317             * @param start the lower bound of the range of message-boards messages
18318             * @param end the upper bound of the range of message-boards messages (not inclusive)
18319             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18320             * @return the ordered range of matching message-boards messages
18321             */
18322            @Override
18323            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18324                    long classPK, int status, int start, int end,
18325                    OrderByComparator<MBMessage> orderByComparator) {
18326                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18327                            orderByComparator, true);
18328            }
18329    
18330            /**
18331             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18332             *
18333             * <p>
18334             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18335             * </p>
18336             *
18337             * @param userId the user ID
18338             * @param classNameId the class name ID
18339             * @param classPK the class p k
18340             * @param status the status
18341             * @param start the lower bound of the range of message-boards messages
18342             * @param end the upper bound of the range of message-boards messages (not inclusive)
18343             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18344             * @param retrieveFromCache whether to retrieve from the finder cache
18345             * @return the ordered range of matching message-boards messages
18346             */
18347            @Override
18348            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18349                    long classPK, int status, int start, int end,
18350                    OrderByComparator<MBMessage> orderByComparator,
18351                    boolean retrieveFromCache) {
18352                    boolean pagination = true;
18353                    FinderPath finderPath = null;
18354                    Object[] finderArgs = null;
18355    
18356                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18357                                    (orderByComparator == null)) {
18358                            pagination = false;
18359                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18360                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18361                    }
18362                    else {
18363                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18364                            finderArgs = new Object[] {
18365                                            userId, classNameId, classPK, status,
18366                                            
18367                                            start, end, orderByComparator
18368                                    };
18369                    }
18370    
18371                    List<MBMessage> list = null;
18372    
18373                    if (retrieveFromCache) {
18374                            list = (List<MBMessage>)finderCache.getResult(finderPath,
18375                                            finderArgs, this);
18376    
18377                            if ((list != null) && !list.isEmpty()) {
18378                                    for (MBMessage mbMessage : list) {
18379                                            if ((userId != mbMessage.getUserId()) ||
18380                                                            (classNameId != mbMessage.getClassNameId()) ||
18381                                                            (classPK != mbMessage.getClassPK()) ||
18382                                                            (status != mbMessage.getStatus())) {
18383                                                    list = null;
18384    
18385                                                    break;
18386                                            }
18387                                    }
18388                            }
18389                    }
18390    
18391                    if (list == null) {
18392                            StringBundler query = null;
18393    
18394                            if (orderByComparator != null) {
18395                                    query = new StringBundler(6 +
18396                                                    (orderByComparator.getOrderByFields().length * 3));
18397                            }
18398                            else {
18399                                    query = new StringBundler(6);
18400                            }
18401    
18402                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18403    
18404                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18405    
18406                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18407    
18408                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18409    
18410                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18411    
18412                            if (orderByComparator != null) {
18413                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18414                                            orderByComparator);
18415                            }
18416                            else
18417                             if (pagination) {
18418                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18419                            }
18420    
18421                            String sql = query.toString();
18422    
18423                            Session session = null;
18424    
18425                            try {
18426                                    session = openSession();
18427    
18428                                    Query q = session.createQuery(sql);
18429    
18430                                    QueryPos qPos = QueryPos.getInstance(q);
18431    
18432                                    qPos.add(userId);
18433    
18434                                    qPos.add(classNameId);
18435    
18436                                    qPos.add(classPK);
18437    
18438                                    qPos.add(status);
18439    
18440                                    if (!pagination) {
18441                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18442                                                            start, end, false);
18443    
18444                                            Collections.sort(list);
18445    
18446                                            list = Collections.unmodifiableList(list);
18447                                    }
18448                                    else {
18449                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18450                                                            start, end);
18451                                    }
18452    
18453                                    cacheResult(list);
18454    
18455                                    finderCache.putResult(finderPath, finderArgs, list);
18456                            }
18457                            catch (Exception e) {
18458                                    finderCache.removeResult(finderPath, finderArgs);
18459    
18460                                    throw processException(e);
18461                            }
18462                            finally {
18463                                    closeSession(session);
18464                            }
18465                    }
18466    
18467                    return list;
18468            }
18469    
18470            /**
18471             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18472             *
18473             * @param userId the user ID
18474             * @param classNameId the class name ID
18475             * @param classPK the class p k
18476             * @param status the status
18477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18478             * @return the first matching message-boards message
18479             * @throws NoSuchMessageException if a matching message-boards message could not be found
18480             */
18481            @Override
18482            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18483                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18484                    throws NoSuchMessageException {
18485                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18486                                    classPK, status, orderByComparator);
18487    
18488                    if (mbMessage != null) {
18489                            return mbMessage;
18490                    }
18491    
18492                    StringBundler msg = new StringBundler(10);
18493    
18494                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18495    
18496                    msg.append("userId=");
18497                    msg.append(userId);
18498    
18499                    msg.append(", classNameId=");
18500                    msg.append(classNameId);
18501    
18502                    msg.append(", classPK=");
18503                    msg.append(classPK);
18504    
18505                    msg.append(", status=");
18506                    msg.append(status);
18507    
18508                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18509    
18510                    throw new NoSuchMessageException(msg.toString());
18511            }
18512    
18513            /**
18514             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18515             *
18516             * @param userId the user ID
18517             * @param classNameId the class name ID
18518             * @param classPK the class p k
18519             * @param status the status
18520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18521             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18522             */
18523            @Override
18524            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18525                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18526                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18527                                    status, 0, 1, orderByComparator);
18528    
18529                    if (!list.isEmpty()) {
18530                            return list.get(0);
18531                    }
18532    
18533                    return null;
18534            }
18535    
18536            /**
18537             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18538             *
18539             * @param userId the user ID
18540             * @param classNameId the class name ID
18541             * @param classPK the class p k
18542             * @param status the status
18543             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18544             * @return the last matching message-boards message
18545             * @throws NoSuchMessageException if a matching message-boards message could not be found
18546             */
18547            @Override
18548            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18549                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18550                    throws NoSuchMessageException {
18551                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18552                                    status, orderByComparator);
18553    
18554                    if (mbMessage != null) {
18555                            return mbMessage;
18556                    }
18557    
18558                    StringBundler msg = new StringBundler(10);
18559    
18560                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18561    
18562                    msg.append("userId=");
18563                    msg.append(userId);
18564    
18565                    msg.append(", classNameId=");
18566                    msg.append(classNameId);
18567    
18568                    msg.append(", classPK=");
18569                    msg.append(classPK);
18570    
18571                    msg.append(", status=");
18572                    msg.append(status);
18573    
18574                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18575    
18576                    throw new NoSuchMessageException(msg.toString());
18577            }
18578    
18579            /**
18580             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18581             *
18582             * @param userId the user ID
18583             * @param classNameId the class name ID
18584             * @param classPK the class p k
18585             * @param status the status
18586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18587             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18588             */
18589            @Override
18590            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18591                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18592                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18593    
18594                    if (count == 0) {
18595                            return null;
18596                    }
18597    
18598                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18599                                    status, count - 1, count, orderByComparator);
18600    
18601                    if (!list.isEmpty()) {
18602                            return list.get(0);
18603                    }
18604    
18605                    return null;
18606            }
18607    
18608            /**
18609             * 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;.
18610             *
18611             * @param messageId the primary key of the current message-boards message
18612             * @param userId the user ID
18613             * @param classNameId the class name ID
18614             * @param classPK the class p k
18615             * @param status the status
18616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18617             * @return the previous, current, and next message-boards message
18618             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18619             */
18620            @Override
18621            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18622                    long classNameId, long classPK, int status,
18623                    OrderByComparator<MBMessage> orderByComparator)
18624                    throws NoSuchMessageException {
18625                    MBMessage mbMessage = findByPrimaryKey(messageId);
18626    
18627                    Session session = null;
18628    
18629                    try {
18630                            session = openSession();
18631    
18632                            MBMessage[] array = new MBMessageImpl[3];
18633    
18634                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18635                                            classNameId, classPK, status, orderByComparator, true);
18636    
18637                            array[1] = mbMessage;
18638    
18639                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18640                                            classNameId, classPK, status, orderByComparator, false);
18641    
18642                            return array;
18643                    }
18644                    catch (Exception e) {
18645                            throw processException(e);
18646                    }
18647                    finally {
18648                            closeSession(session);
18649                    }
18650            }
18651    
18652            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18653                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18654                    int status, OrderByComparator<MBMessage> orderByComparator,
18655                    boolean previous) {
18656                    StringBundler query = null;
18657    
18658                    if (orderByComparator != null) {
18659                            query = new StringBundler(6 +
18660                                            (orderByComparator.getOrderByFields().length * 6));
18661                    }
18662                    else {
18663                            query = new StringBundler(3);
18664                    }
18665    
18666                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18667    
18668                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18669    
18670                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18671    
18672                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18673    
18674                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18675    
18676                    if (orderByComparator != null) {
18677                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18678    
18679                            if (orderByConditionFields.length > 0) {
18680                                    query.append(WHERE_AND);
18681                            }
18682    
18683                            for (int i = 0; i < orderByConditionFields.length; i++) {
18684                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18685                                    query.append(orderByConditionFields[i]);
18686    
18687                                    if ((i + 1) < orderByConditionFields.length) {
18688                                            if (orderByComparator.isAscending() ^ previous) {
18689                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18690                                            }
18691                                            else {
18692                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18693                                            }
18694                                    }
18695                                    else {
18696                                            if (orderByComparator.isAscending() ^ previous) {
18697                                                    query.append(WHERE_GREATER_THAN);
18698                                            }
18699                                            else {
18700                                                    query.append(WHERE_LESSER_THAN);
18701                                            }
18702                                    }
18703                            }
18704    
18705                            query.append(ORDER_BY_CLAUSE);
18706    
18707                            String[] orderByFields = orderByComparator.getOrderByFields();
18708    
18709                            for (int i = 0; i < orderByFields.length; i++) {
18710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18711                                    query.append(orderByFields[i]);
18712    
18713                                    if ((i + 1) < orderByFields.length) {
18714                                            if (orderByComparator.isAscending() ^ previous) {
18715                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18716                                            }
18717                                            else {
18718                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18719                                            }
18720                                    }
18721                                    else {
18722                                            if (orderByComparator.isAscending() ^ previous) {
18723                                                    query.append(ORDER_BY_ASC);
18724                                            }
18725                                            else {
18726                                                    query.append(ORDER_BY_DESC);
18727                                            }
18728                                    }
18729                            }
18730                    }
18731                    else {
18732                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18733                    }
18734    
18735                    String sql = query.toString();
18736    
18737                    Query q = session.createQuery(sql);
18738    
18739                    q.setFirstResult(0);
18740                    q.setMaxResults(2);
18741    
18742                    QueryPos qPos = QueryPos.getInstance(q);
18743    
18744                    qPos.add(userId);
18745    
18746                    qPos.add(classNameId);
18747    
18748                    qPos.add(classPK);
18749    
18750                    qPos.add(status);
18751    
18752                    if (orderByComparator != null) {
18753                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18754    
18755                            for (Object value : values) {
18756                                    qPos.add(value);
18757                            }
18758                    }
18759    
18760                    List<MBMessage> list = q.list();
18761    
18762                    if (list.size() == 2) {
18763                            return list.get(1);
18764                    }
18765                    else {
18766                            return null;
18767                    }
18768            }
18769    
18770            /**
18771             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18772             *
18773             * @param userId the user ID
18774             * @param classNameId the class name ID
18775             * @param classPK the class p k
18776             * @param status the status
18777             */
18778            @Override
18779            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18780                    int status) {
18781                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18782                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18783                            remove(mbMessage);
18784                    }
18785            }
18786    
18787            /**
18788             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18789             *
18790             * @param userId the user ID
18791             * @param classNameId the class name ID
18792             * @param classPK the class p k
18793             * @param status the status
18794             * @return the number of matching message-boards messages
18795             */
18796            @Override
18797            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18798                    int status) {
18799                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18800    
18801                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18802    
18803                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18804    
18805                    if (count == null) {
18806                            StringBundler query = new StringBundler(5);
18807    
18808                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18809    
18810                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18811    
18812                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18813    
18814                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18815    
18816                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18817    
18818                            String sql = query.toString();
18819    
18820                            Session session = null;
18821    
18822                            try {
18823                                    session = openSession();
18824    
18825                                    Query q = session.createQuery(sql);
18826    
18827                                    QueryPos qPos = QueryPos.getInstance(q);
18828    
18829                                    qPos.add(userId);
18830    
18831                                    qPos.add(classNameId);
18832    
18833                                    qPos.add(classPK);
18834    
18835                                    qPos.add(status);
18836    
18837                                    count = (Long)q.uniqueResult();
18838    
18839                                    finderCache.putResult(finderPath, finderArgs, count);
18840                            }
18841                            catch (Exception e) {
18842                                    finderCache.removeResult(finderPath, finderArgs);
18843    
18844                                    throw processException(e);
18845                            }
18846                            finally {
18847                                    closeSession(session);
18848                            }
18849                    }
18850    
18851                    return count.intValue();
18852            }
18853    
18854            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18855            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18856            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18857            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18858    
18859            public MBMessagePersistenceImpl() {
18860                    setModelClass(MBMessage.class);
18861            }
18862    
18863            /**
18864             * Caches the message-boards message in the entity cache if it is enabled.
18865             *
18866             * @param mbMessage the message-boards message
18867             */
18868            @Override
18869            public void cacheResult(MBMessage mbMessage) {
18870                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18871                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18872    
18873                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18874                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18875                            mbMessage);
18876    
18877                    mbMessage.resetOriginalValues();
18878            }
18879    
18880            /**
18881             * Caches the message-boards messages in the entity cache if it is enabled.
18882             *
18883             * @param mbMessages the message-boards messages
18884             */
18885            @Override
18886            public void cacheResult(List<MBMessage> mbMessages) {
18887                    for (MBMessage mbMessage : mbMessages) {
18888                            if (entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18889                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18890                                    cacheResult(mbMessage);
18891                            }
18892                            else {
18893                                    mbMessage.resetOriginalValues();
18894                            }
18895                    }
18896            }
18897    
18898            /**
18899             * Clears the cache for all message-boards messages.
18900             *
18901             * <p>
18902             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18903             * </p>
18904             */
18905            @Override
18906            public void clearCache() {
18907                    entityCache.clearCache(MBMessageImpl.class);
18908    
18909                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
18910                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18911                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18912            }
18913    
18914            /**
18915             * Clears the cache for the message-boards message.
18916             *
18917             * <p>
18918             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18919             * </p>
18920             */
18921            @Override
18922            public void clearCache(MBMessage mbMessage) {
18923                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18924                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18925    
18926                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18927                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18928    
18929                    clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18930            }
18931    
18932            @Override
18933            public void clearCache(List<MBMessage> mbMessages) {
18934                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18935                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18936    
18937                    for (MBMessage mbMessage : mbMessages) {
18938                            entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18939                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18940    
18941                            clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18942                    }
18943            }
18944    
18945            protected void cacheUniqueFindersCache(
18946                    MBMessageModelImpl mbMessageModelImpl, boolean isNew) {
18947                    if (isNew) {
18948                            Object[] args = new Object[] {
18949                                            mbMessageModelImpl.getUuid(),
18950                                            mbMessageModelImpl.getGroupId()
18951                                    };
18952    
18953                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18954                                    Long.valueOf(1));
18955                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18956                                    mbMessageModelImpl);
18957                    }
18958                    else {
18959                            if ((mbMessageModelImpl.getColumnBitmask() &
18960                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18961                                    Object[] args = new Object[] {
18962                                                    mbMessageModelImpl.getUuid(),
18963                                                    mbMessageModelImpl.getGroupId()
18964                                            };
18965    
18966                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18967                                            Long.valueOf(1));
18968                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18969                                            mbMessageModelImpl);
18970                            }
18971                    }
18972            }
18973    
18974            protected void clearUniqueFindersCache(
18975                    MBMessageModelImpl mbMessageModelImpl) {
18976                    Object[] args = new Object[] {
18977                                    mbMessageModelImpl.getUuid(), mbMessageModelImpl.getGroupId()
18978                            };
18979    
18980                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18981                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18982    
18983                    if ((mbMessageModelImpl.getColumnBitmask() &
18984                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18985                            args = new Object[] {
18986                                            mbMessageModelImpl.getOriginalUuid(),
18987                                            mbMessageModelImpl.getOriginalGroupId()
18988                                    };
18989    
18990                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18991                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18992                    }
18993            }
18994    
18995            /**
18996             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18997             *
18998             * @param messageId the primary key for the new message-boards message
18999             * @return the new message-boards message
19000             */
19001            @Override
19002            public MBMessage create(long messageId) {
19003                    MBMessage mbMessage = new MBMessageImpl();
19004    
19005                    mbMessage.setNew(true);
19006                    mbMessage.setPrimaryKey(messageId);
19007    
19008                    String uuid = PortalUUIDUtil.generate();
19009    
19010                    mbMessage.setUuid(uuid);
19011    
19012                    return mbMessage;
19013            }
19014    
19015            /**
19016             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19017             *
19018             * @param messageId the primary key of the message-boards message
19019             * @return the message-boards message that was removed
19020             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19021             */
19022            @Override
19023            public MBMessage remove(long messageId) throws NoSuchMessageException {
19024                    return remove((Serializable)messageId);
19025            }
19026    
19027            /**
19028             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19029             *
19030             * @param primaryKey the primary key of the message-boards message
19031             * @return the message-boards message that was removed
19032             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19033             */
19034            @Override
19035            public MBMessage remove(Serializable primaryKey)
19036                    throws NoSuchMessageException {
19037                    Session session = null;
19038    
19039                    try {
19040                            session = openSession();
19041    
19042                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19043                                            primaryKey);
19044    
19045                            if (mbMessage == null) {
19046                                    if (_log.isWarnEnabled()) {
19047                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19048                                    }
19049    
19050                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19051                                            primaryKey);
19052                            }
19053    
19054                            return remove(mbMessage);
19055                    }
19056                    catch (NoSuchMessageException nsee) {
19057                            throw nsee;
19058                    }
19059                    catch (Exception e) {
19060                            throw processException(e);
19061                    }
19062                    finally {
19063                            closeSession(session);
19064                    }
19065            }
19066    
19067            @Override
19068            protected MBMessage removeImpl(MBMessage mbMessage) {
19069                    mbMessage = toUnwrappedModel(mbMessage);
19070    
19071                    Session session = null;
19072    
19073                    try {
19074                            session = openSession();
19075    
19076                            if (!session.contains(mbMessage)) {
19077                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19078                                                    mbMessage.getPrimaryKeyObj());
19079                            }
19080    
19081                            if (mbMessage != null) {
19082                                    session.delete(mbMessage);
19083                            }
19084                    }
19085                    catch (Exception e) {
19086                            throw processException(e);
19087                    }
19088                    finally {
19089                            closeSession(session);
19090                    }
19091    
19092                    if (mbMessage != null) {
19093                            clearCache(mbMessage);
19094                    }
19095    
19096                    return mbMessage;
19097            }
19098    
19099            @Override
19100            public MBMessage updateImpl(MBMessage mbMessage) {
19101                    mbMessage = toUnwrappedModel(mbMessage);
19102    
19103                    boolean isNew = mbMessage.isNew();
19104    
19105                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19106    
19107                    if (Validator.isNull(mbMessage.getUuid())) {
19108                            String uuid = PortalUUIDUtil.generate();
19109    
19110                            mbMessage.setUuid(uuid);
19111                    }
19112    
19113                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
19114    
19115                    Date now = new Date();
19116    
19117                    if (isNew && (mbMessage.getCreateDate() == null)) {
19118                            if (serviceContext == null) {
19119                                    mbMessage.setCreateDate(now);
19120                            }
19121                            else {
19122                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
19123                            }
19124                    }
19125    
19126                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
19127                            if (serviceContext == null) {
19128                                    mbMessage.setModifiedDate(now);
19129                            }
19130                            else {
19131                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
19132                            }
19133                    }
19134    
19135                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
19136    
19137                    if (userId > 0) {
19138                            long companyId = mbMessage.getCompanyId();
19139    
19140                            long groupId = mbMessage.getGroupId();
19141    
19142                            long messageId = 0;
19143    
19144                            if (!isNew) {
19145                                    messageId = mbMessage.getPrimaryKey();
19146                            }
19147    
19148                            try {
19149                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
19150                                                    userId,
19151                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
19152                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
19153                                                    mbMessage.getSubject(), null));
19154                            }
19155                            catch (SanitizerException se) {
19156                                    throw new SystemException(se);
19157                            }
19158                    }
19159    
19160                    Session session = null;
19161    
19162                    try {
19163                            session = openSession();
19164    
19165                            if (mbMessage.isNew()) {
19166                                    session.save(mbMessage);
19167    
19168                                    mbMessage.setNew(false);
19169                            }
19170                            else {
19171                                    mbMessage = (MBMessage)session.merge(mbMessage);
19172                            }
19173                    }
19174                    catch (Exception e) {
19175                            throw processException(e);
19176                    }
19177                    finally {
19178                            closeSession(session);
19179                    }
19180    
19181                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19182    
19183                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
19184                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19185                    }
19186    
19187                    else {
19188                            if ((mbMessageModelImpl.getColumnBitmask() &
19189                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
19190                                    Object[] args = new Object[] {
19191                                                    mbMessageModelImpl.getOriginalUuid()
19192                                            };
19193    
19194                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19195                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19196                                            args);
19197    
19198                                    args = new Object[] { mbMessageModelImpl.getUuid() };
19199    
19200                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19201                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19202                                            args);
19203                            }
19204    
19205                            if ((mbMessageModelImpl.getColumnBitmask() &
19206                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
19207                                    Object[] args = new Object[] {
19208                                                    mbMessageModelImpl.getOriginalUuid(),
19209                                                    mbMessageModelImpl.getOriginalCompanyId()
19210                                            };
19211    
19212                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19213                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19214                                            args);
19215    
19216                                    args = new Object[] {
19217                                                    mbMessageModelImpl.getUuid(),
19218                                                    mbMessageModelImpl.getCompanyId()
19219                                            };
19220    
19221                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19222                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19223                                            args);
19224                            }
19225    
19226                            if ((mbMessageModelImpl.getColumnBitmask() &
19227                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
19228                                    Object[] args = new Object[] {
19229                                                    mbMessageModelImpl.getOriginalGroupId()
19230                                            };
19231    
19232                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19233                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19234                                            args);
19235    
19236                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
19237    
19238                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19239                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19240                                            args);
19241                            }
19242    
19243                            if ((mbMessageModelImpl.getColumnBitmask() &
19244                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
19245                                    Object[] args = new Object[] {
19246                                                    mbMessageModelImpl.getOriginalCompanyId()
19247                                            };
19248    
19249                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19250                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19251                                            args);
19252    
19253                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
19254    
19255                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19256                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19257                                            args);
19258                            }
19259    
19260                            if ((mbMessageModelImpl.getColumnBitmask() &
19261                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
19262                                    Object[] args = new Object[] {
19263                                                    mbMessageModelImpl.getOriginalUserId()
19264                                            };
19265    
19266                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19267                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19268                                            args);
19269    
19270                                    args = new Object[] { mbMessageModelImpl.getUserId() };
19271    
19272                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19273                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19274                                            args);
19275                            }
19276    
19277                            if ((mbMessageModelImpl.getColumnBitmask() &
19278                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
19279                                    Object[] args = new Object[] {
19280                                                    mbMessageModelImpl.getOriginalThreadId()
19281                                            };
19282    
19283                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19284                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19285                                            args);
19286    
19287                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19288    
19289                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19290                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19291                                            args);
19292                            }
19293    
19294                            if ((mbMessageModelImpl.getColumnBitmask() &
19295                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
19296                                    Object[] args = new Object[] {
19297                                                    mbMessageModelImpl.getOriginalThreadId()
19298                                            };
19299    
19300                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19301                                            args);
19302                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19303                                            args);
19304    
19305                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19306    
19307                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19308                                            args);
19309                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19310                                            args);
19311                            }
19312    
19313                            if ((mbMessageModelImpl.getColumnBitmask() &
19314                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19315                                    Object[] args = new Object[] {
19316                                                    mbMessageModelImpl.getOriginalGroupId(),
19317                                                    mbMessageModelImpl.getOriginalUserId()
19318                                            };
19319    
19320                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19321                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19322                                            args);
19323    
19324                                    args = new Object[] {
19325                                                    mbMessageModelImpl.getGroupId(),
19326                                                    mbMessageModelImpl.getUserId()
19327                                            };
19328    
19329                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19330                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19331                                            args);
19332                            }
19333    
19334                            if ((mbMessageModelImpl.getColumnBitmask() &
19335                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19336                                    Object[] args = new Object[] {
19337                                                    mbMessageModelImpl.getOriginalGroupId(),
19338                                                    mbMessageModelImpl.getOriginalCategoryId()
19339                                            };
19340    
19341                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19342                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19343                                            args);
19344    
19345                                    args = new Object[] {
19346                                                    mbMessageModelImpl.getGroupId(),
19347                                                    mbMessageModelImpl.getCategoryId()
19348                                            };
19349    
19350                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19351                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19352                                            args);
19353                            }
19354    
19355                            if ((mbMessageModelImpl.getColumnBitmask() &
19356                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19357                                    Object[] args = new Object[] {
19358                                                    mbMessageModelImpl.getOriginalGroupId(),
19359                                                    mbMessageModelImpl.getOriginalStatus()
19360                                            };
19361    
19362                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19363                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19364                                            args);
19365    
19366                                    args = new Object[] {
19367                                                    mbMessageModelImpl.getGroupId(),
19368                                                    mbMessageModelImpl.getStatus()
19369                                            };
19370    
19371                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19372                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19373                                            args);
19374                            }
19375    
19376                            if ((mbMessageModelImpl.getColumnBitmask() &
19377                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19378                                    Object[] args = new Object[] {
19379                                                    mbMessageModelImpl.getOriginalCompanyId(),
19380                                                    mbMessageModelImpl.getOriginalStatus()
19381                                            };
19382    
19383                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19384                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19385                                            args);
19386    
19387                                    args = new Object[] {
19388                                                    mbMessageModelImpl.getCompanyId(),
19389                                                    mbMessageModelImpl.getStatus()
19390                                            };
19391    
19392                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19393                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19394                                            args);
19395                            }
19396    
19397                            if ((mbMessageModelImpl.getColumnBitmask() &
19398                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19399                                    Object[] args = new Object[] {
19400                                                    mbMessageModelImpl.getOriginalUserId(),
19401                                                    mbMessageModelImpl.getOriginalClassNameId()
19402                                            };
19403    
19404                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19405                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19406                                            args);
19407    
19408                                    args = new Object[] {
19409                                                    mbMessageModelImpl.getUserId(),
19410                                                    mbMessageModelImpl.getClassNameId()
19411                                            };
19412    
19413                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19414                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19415                                            args);
19416                            }
19417    
19418                            if ((mbMessageModelImpl.getColumnBitmask() &
19419                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19420                                    Object[] args = new Object[] {
19421                                                    mbMessageModelImpl.getOriginalClassNameId(),
19422                                                    mbMessageModelImpl.getOriginalClassPK()
19423                                            };
19424    
19425                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19426                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19427                                            args);
19428    
19429                                    args = new Object[] {
19430                                                    mbMessageModelImpl.getClassNameId(),
19431                                                    mbMessageModelImpl.getClassPK()
19432                                            };
19433    
19434                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19435                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19436                                            args);
19437                            }
19438    
19439                            if ((mbMessageModelImpl.getColumnBitmask() &
19440                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19441                                    Object[] args = new Object[] {
19442                                                    mbMessageModelImpl.getOriginalThreadId(),
19443                                                    mbMessageModelImpl.getOriginalParentMessageId()
19444                                            };
19445    
19446                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19447                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19448                                            args);
19449    
19450                                    args = new Object[] {
19451                                                    mbMessageModelImpl.getThreadId(),
19452                                                    mbMessageModelImpl.getParentMessageId()
19453                                            };
19454    
19455                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19456                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19457                                            args);
19458                            }
19459    
19460                            if ((mbMessageModelImpl.getColumnBitmask() &
19461                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19462                                    Object[] args = new Object[] {
19463                                                    mbMessageModelImpl.getOriginalThreadId(),
19464                                                    mbMessageModelImpl.getOriginalAnswer()
19465                                            };
19466    
19467                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19468                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19469                                            args);
19470    
19471                                    args = new Object[] {
19472                                                    mbMessageModelImpl.getThreadId(),
19473                                                    mbMessageModelImpl.getAnswer()
19474                                            };
19475    
19476                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19477                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19478                                            args);
19479                            }
19480    
19481                            if ((mbMessageModelImpl.getColumnBitmask() &
19482                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19483                                    Object[] args = new Object[] {
19484                                                    mbMessageModelImpl.getOriginalThreadId(),
19485                                                    mbMessageModelImpl.getOriginalStatus()
19486                                            };
19487    
19488                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19489                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19490                                            args);
19491    
19492                                    args = new Object[] {
19493                                                    mbMessageModelImpl.getThreadId(),
19494                                                    mbMessageModelImpl.getStatus()
19495                                            };
19496    
19497                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19498                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19499                                            args);
19500                            }
19501    
19502                            if ((mbMessageModelImpl.getColumnBitmask() &
19503                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19504                                    Object[] args = new Object[] {
19505                                                    mbMessageModelImpl.getOriginalThreadId(),
19506                                                    mbMessageModelImpl.getOriginalStatus()
19507                                            };
19508    
19509                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19510                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19511                                            args);
19512    
19513                                    args = new Object[] {
19514                                                    mbMessageModelImpl.getThreadId(),
19515                                                    mbMessageModelImpl.getStatus()
19516                                            };
19517    
19518                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19519                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19520                                            args);
19521                            }
19522    
19523                            if ((mbMessageModelImpl.getColumnBitmask() &
19524                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19525                                    Object[] args = new Object[] {
19526                                                    mbMessageModelImpl.getOriginalGroupId(),
19527                                                    mbMessageModelImpl.getOriginalUserId(),
19528                                                    mbMessageModelImpl.getOriginalStatus()
19529                                            };
19530    
19531                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19532                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19533                                            args);
19534    
19535                                    args = new Object[] {
19536                                                    mbMessageModelImpl.getGroupId(),
19537                                                    mbMessageModelImpl.getUserId(),
19538                                                    mbMessageModelImpl.getStatus()
19539                                            };
19540    
19541                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19542                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19543                                            args);
19544                            }
19545    
19546                            if ((mbMessageModelImpl.getColumnBitmask() &
19547                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19548                                    Object[] args = new Object[] {
19549                                                    mbMessageModelImpl.getOriginalGroupId(),
19550                                                    mbMessageModelImpl.getOriginalCategoryId(),
19551                                                    mbMessageModelImpl.getOriginalThreadId()
19552                                            };
19553    
19554                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19555                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19556                                            args);
19557    
19558                                    args = new Object[] {
19559                                                    mbMessageModelImpl.getGroupId(),
19560                                                    mbMessageModelImpl.getCategoryId(),
19561                                                    mbMessageModelImpl.getThreadId()
19562                                            };
19563    
19564                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19565                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19566                                            args);
19567                            }
19568    
19569                            if ((mbMessageModelImpl.getColumnBitmask() &
19570                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19571                                    Object[] args = new Object[] {
19572                                                    mbMessageModelImpl.getOriginalGroupId(),
19573                                                    mbMessageModelImpl.getOriginalCategoryId(),
19574                                                    mbMessageModelImpl.getOriginalStatus()
19575                                            };
19576    
19577                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19578                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19579                                            args);
19580    
19581                                    args = new Object[] {
19582                                                    mbMessageModelImpl.getGroupId(),
19583                                                    mbMessageModelImpl.getCategoryId(),
19584                                                    mbMessageModelImpl.getStatus()
19585                                            };
19586    
19587                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19588                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19589                                            args);
19590                            }
19591    
19592                            if ((mbMessageModelImpl.getColumnBitmask() &
19593                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19594                                    Object[] args = new Object[] {
19595                                                    mbMessageModelImpl.getOriginalUserId(),
19596                                                    mbMessageModelImpl.getOriginalClassNameId(),
19597                                                    mbMessageModelImpl.getOriginalClassPK()
19598                                            };
19599    
19600                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19601                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19602                                            args);
19603    
19604                                    args = new Object[] {
19605                                                    mbMessageModelImpl.getUserId(),
19606                                                    mbMessageModelImpl.getClassNameId(),
19607                                                    mbMessageModelImpl.getClassPK()
19608                                            };
19609    
19610                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19611                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19612                                            args);
19613                            }
19614    
19615                            if ((mbMessageModelImpl.getColumnBitmask() &
19616                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19617                                    Object[] args = new Object[] {
19618                                                    mbMessageModelImpl.getOriginalUserId(),
19619                                                    mbMessageModelImpl.getOriginalClassNameId(),
19620                                                    mbMessageModelImpl.getOriginalStatus()
19621                                            };
19622    
19623                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19624                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19625                                            args);
19626    
19627                                    args = new Object[] {
19628                                                    mbMessageModelImpl.getUserId(),
19629                                                    mbMessageModelImpl.getClassNameId(),
19630                                                    mbMessageModelImpl.getStatus()
19631                                            };
19632    
19633                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19634                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19635                                            args);
19636                            }
19637    
19638                            if ((mbMessageModelImpl.getColumnBitmask() &
19639                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19640                                    Object[] args = new Object[] {
19641                                                    mbMessageModelImpl.getOriginalClassNameId(),
19642                                                    mbMessageModelImpl.getOriginalClassPK(),
19643                                                    mbMessageModelImpl.getOriginalStatus()
19644                                            };
19645    
19646                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19647                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19648                                            args);
19649    
19650                                    args = new Object[] {
19651                                                    mbMessageModelImpl.getClassNameId(),
19652                                                    mbMessageModelImpl.getClassPK(),
19653                                                    mbMessageModelImpl.getStatus()
19654                                            };
19655    
19656                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19657                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19658                                            args);
19659                            }
19660    
19661                            if ((mbMessageModelImpl.getColumnBitmask() &
19662                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19663                                    Object[] args = new Object[] {
19664                                                    mbMessageModelImpl.getOriginalGroupId(),
19665                                                    mbMessageModelImpl.getOriginalCategoryId(),
19666                                                    mbMessageModelImpl.getOriginalThreadId(),
19667                                                    mbMessageModelImpl.getOriginalAnswer()
19668                                            };
19669    
19670                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19671                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19672                                            args);
19673    
19674                                    args = new Object[] {
19675                                                    mbMessageModelImpl.getGroupId(),
19676                                                    mbMessageModelImpl.getCategoryId(),
19677                                                    mbMessageModelImpl.getThreadId(),
19678                                                    mbMessageModelImpl.getAnswer()
19679                                            };
19680    
19681                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19682                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19683                                            args);
19684                            }
19685    
19686                            if ((mbMessageModelImpl.getColumnBitmask() &
19687                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19688                                    Object[] args = new Object[] {
19689                                                    mbMessageModelImpl.getOriginalGroupId(),
19690                                                    mbMessageModelImpl.getOriginalCategoryId(),
19691                                                    mbMessageModelImpl.getOriginalThreadId(),
19692                                                    mbMessageModelImpl.getOriginalStatus()
19693                                            };
19694    
19695                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19696                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19697                                            args);
19698    
19699                                    args = new Object[] {
19700                                                    mbMessageModelImpl.getGroupId(),
19701                                                    mbMessageModelImpl.getCategoryId(),
19702                                                    mbMessageModelImpl.getThreadId(),
19703                                                    mbMessageModelImpl.getStatus()
19704                                            };
19705    
19706                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19707                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19708                                            args);
19709                            }
19710    
19711                            if ((mbMessageModelImpl.getColumnBitmask() &
19712                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19713                                    Object[] args = new Object[] {
19714                                                    mbMessageModelImpl.getOriginalUserId(),
19715                                                    mbMessageModelImpl.getOriginalClassNameId(),
19716                                                    mbMessageModelImpl.getOriginalClassPK(),
19717                                                    mbMessageModelImpl.getOriginalStatus()
19718                                            };
19719    
19720                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19721                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19722                                            args);
19723    
19724                                    args = new Object[] {
19725                                                    mbMessageModelImpl.getUserId(),
19726                                                    mbMessageModelImpl.getClassNameId(),
19727                                                    mbMessageModelImpl.getClassPK(),
19728                                                    mbMessageModelImpl.getStatus()
19729                                            };
19730    
19731                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19732                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19733                                            args);
19734                            }
19735                    }
19736    
19737                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19738                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
19739    
19740                    clearUniqueFindersCache(mbMessageModelImpl);
19741                    cacheUniqueFindersCache(mbMessageModelImpl, isNew);
19742    
19743                    mbMessage.resetOriginalValues();
19744    
19745                    return mbMessage;
19746            }
19747    
19748            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19749                    if (mbMessage instanceof MBMessageImpl) {
19750                            return mbMessage;
19751                    }
19752    
19753                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19754    
19755                    mbMessageImpl.setNew(mbMessage.isNew());
19756                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19757    
19758                    mbMessageImpl.setUuid(mbMessage.getUuid());
19759                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19760                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19761                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19762                    mbMessageImpl.setUserId(mbMessage.getUserId());
19763                    mbMessageImpl.setUserName(mbMessage.getUserName());
19764                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19765                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19766                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19767                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19768                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19769                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19770                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19771                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19772                    mbMessageImpl.setSubject(mbMessage.getSubject());
19773                    mbMessageImpl.setBody(mbMessage.getBody());
19774                    mbMessageImpl.setFormat(mbMessage.getFormat());
19775                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19776                    mbMessageImpl.setPriority(mbMessage.getPriority());
19777                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19778                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19779                    mbMessageImpl.setLastPublishDate(mbMessage.getLastPublishDate());
19780                    mbMessageImpl.setStatus(mbMessage.getStatus());
19781                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19782                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19783                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19784    
19785                    return mbMessageImpl;
19786            }
19787    
19788            /**
19789             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19790             *
19791             * @param primaryKey the primary key of the message-boards message
19792             * @return the message-boards message
19793             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19794             */
19795            @Override
19796            public MBMessage findByPrimaryKey(Serializable primaryKey)
19797                    throws NoSuchMessageException {
19798                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19799    
19800                    if (mbMessage == null) {
19801                            if (_log.isWarnEnabled()) {
19802                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19803                            }
19804    
19805                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19806                                    primaryKey);
19807                    }
19808    
19809                    return mbMessage;
19810            }
19811    
19812            /**
19813             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19814             *
19815             * @param messageId the primary key of the message-boards message
19816             * @return the message-boards message
19817             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19818             */
19819            @Override
19820            public MBMessage findByPrimaryKey(long messageId)
19821                    throws NoSuchMessageException {
19822                    return findByPrimaryKey((Serializable)messageId);
19823            }
19824    
19825            /**
19826             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19827             *
19828             * @param primaryKey the primary key of the message-boards message
19829             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19830             */
19831            @Override
19832            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19833                    MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19834                                    MBMessageImpl.class, primaryKey);
19835    
19836                    if (mbMessage == _nullMBMessage) {
19837                            return null;
19838                    }
19839    
19840                    if (mbMessage == null) {
19841                            Session session = null;
19842    
19843                            try {
19844                                    session = openSession();
19845    
19846                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19847                                                    primaryKey);
19848    
19849                                    if (mbMessage != null) {
19850                                            cacheResult(mbMessage);
19851                                    }
19852                                    else {
19853                                            entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19854                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19855                                    }
19856                            }
19857                            catch (Exception e) {
19858                                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19859                                            MBMessageImpl.class, primaryKey);
19860    
19861                                    throw processException(e);
19862                            }
19863                            finally {
19864                                    closeSession(session);
19865                            }
19866                    }
19867    
19868                    return mbMessage;
19869            }
19870    
19871            /**
19872             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19873             *
19874             * @param messageId the primary key of the message-boards message
19875             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19876             */
19877            @Override
19878            public MBMessage fetchByPrimaryKey(long messageId) {
19879                    return fetchByPrimaryKey((Serializable)messageId);
19880            }
19881    
19882            @Override
19883            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19884                    Set<Serializable> primaryKeys) {
19885                    if (primaryKeys.isEmpty()) {
19886                            return Collections.emptyMap();
19887                    }
19888    
19889                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19890    
19891                    if (primaryKeys.size() == 1) {
19892                            Iterator<Serializable> iterator = primaryKeys.iterator();
19893    
19894                            Serializable primaryKey = iterator.next();
19895    
19896                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19897    
19898                            if (mbMessage != null) {
19899                                    map.put(primaryKey, mbMessage);
19900                            }
19901    
19902                            return map;
19903                    }
19904    
19905                    Set<Serializable> uncachedPrimaryKeys = null;
19906    
19907                    for (Serializable primaryKey : primaryKeys) {
19908                            MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19909                                            MBMessageImpl.class, primaryKey);
19910    
19911                            if (mbMessage == null) {
19912                                    if (uncachedPrimaryKeys == null) {
19913                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19914                                    }
19915    
19916                                    uncachedPrimaryKeys.add(primaryKey);
19917                            }
19918                            else {
19919                                    map.put(primaryKey, mbMessage);
19920                            }
19921                    }
19922    
19923                    if (uncachedPrimaryKeys == null) {
19924                            return map;
19925                    }
19926    
19927                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19928                                    1);
19929    
19930                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19931    
19932                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19933                            query.append(String.valueOf(primaryKey));
19934    
19935                            query.append(StringPool.COMMA);
19936                    }
19937    
19938                    query.setIndex(query.index() - 1);
19939    
19940                    query.append(StringPool.CLOSE_PARENTHESIS);
19941    
19942                    String sql = query.toString();
19943    
19944                    Session session = null;
19945    
19946                    try {
19947                            session = openSession();
19948    
19949                            Query q = session.createQuery(sql);
19950    
19951                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19952                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19953    
19954                                    cacheResult(mbMessage);
19955    
19956                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19957                            }
19958    
19959                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19960                                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19961                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
19962                            }
19963                    }
19964                    catch (Exception e) {
19965                            throw processException(e);
19966                    }
19967                    finally {
19968                            closeSession(session);
19969                    }
19970    
19971                    return map;
19972            }
19973    
19974            /**
19975             * Returns all the message-boards messages.
19976             *
19977             * @return the message-boards messages
19978             */
19979            @Override
19980            public List<MBMessage> findAll() {
19981                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19982            }
19983    
19984            /**
19985             * Returns a range of all the message-boards messages.
19986             *
19987             * <p>
19988             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19989             * </p>
19990             *
19991             * @param start the lower bound of the range of message-boards messages
19992             * @param end the upper bound of the range of message-boards messages (not inclusive)
19993             * @return the range of message-boards messages
19994             */
19995            @Override
19996            public List<MBMessage> findAll(int start, int end) {
19997                    return findAll(start, end, null);
19998            }
19999    
20000            /**
20001             * Returns an ordered range of all the message-boards messages.
20002             *
20003             * <p>
20004             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20005             * </p>
20006             *
20007             * @param start the lower bound of the range of message-boards messages
20008             * @param end the upper bound of the range of message-boards messages (not inclusive)
20009             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20010             * @return the ordered range of message-boards messages
20011             */
20012            @Override
20013            public List<MBMessage> findAll(int start, int end,
20014                    OrderByComparator<MBMessage> orderByComparator) {
20015                    return findAll(start, end, orderByComparator, true);
20016            }
20017    
20018            /**
20019             * Returns an ordered range of all the message-boards messages.
20020             *
20021             * <p>
20022             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20023             * </p>
20024             *
20025             * @param start the lower bound of the range of message-boards messages
20026             * @param end the upper bound of the range of message-boards messages (not inclusive)
20027             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20028             * @param retrieveFromCache whether to retrieve from the finder cache
20029             * @return the ordered range of message-boards messages
20030             */
20031            @Override
20032            public List<MBMessage> findAll(int start, int end,
20033                    OrderByComparator<MBMessage> orderByComparator,
20034                    boolean retrieveFromCache) {
20035                    boolean pagination = true;
20036                    FinderPath finderPath = null;
20037                    Object[] finderArgs = null;
20038    
20039                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20040                                    (orderByComparator == null)) {
20041                            pagination = false;
20042                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20043                            finderArgs = FINDER_ARGS_EMPTY;
20044                    }
20045                    else {
20046                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20047                            finderArgs = new Object[] { start, end, orderByComparator };
20048                    }
20049    
20050                    List<MBMessage> list = null;
20051    
20052                    if (retrieveFromCache) {
20053                            list = (List<MBMessage>)finderCache.getResult(finderPath,
20054                                            finderArgs, this);
20055                    }
20056    
20057                    if (list == null) {
20058                            StringBundler query = null;
20059                            String sql = null;
20060    
20061                            if (orderByComparator != null) {
20062                                    query = new StringBundler(2 +
20063                                                    (orderByComparator.getOrderByFields().length * 3));
20064    
20065                                    query.append(_SQL_SELECT_MBMESSAGE);
20066    
20067                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20068                                            orderByComparator);
20069    
20070                                    sql = query.toString();
20071                            }
20072                            else {
20073                                    sql = _SQL_SELECT_MBMESSAGE;
20074    
20075                                    if (pagination) {
20076                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20077                                    }
20078                            }
20079    
20080                            Session session = null;
20081    
20082                            try {
20083                                    session = openSession();
20084    
20085                                    Query q = session.createQuery(sql);
20086    
20087                                    if (!pagination) {
20088                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20089                                                            start, end, false);
20090    
20091                                            Collections.sort(list);
20092    
20093                                            list = Collections.unmodifiableList(list);
20094                                    }
20095                                    else {
20096                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20097                                                            start, end);
20098                                    }
20099    
20100                                    cacheResult(list);
20101    
20102                                    finderCache.putResult(finderPath, finderArgs, list);
20103                            }
20104                            catch (Exception e) {
20105                                    finderCache.removeResult(finderPath, finderArgs);
20106    
20107                                    throw processException(e);
20108                            }
20109                            finally {
20110                                    closeSession(session);
20111                            }
20112                    }
20113    
20114                    return list;
20115            }
20116    
20117            /**
20118             * Removes all the message-boards messages from the database.
20119             *
20120             */
20121            @Override
20122            public void removeAll() {
20123                    for (MBMessage mbMessage : findAll()) {
20124                            remove(mbMessage);
20125                    }
20126            }
20127    
20128            /**
20129             * Returns the number of message-boards messages.
20130             *
20131             * @return the number of message-boards messages
20132             */
20133            @Override
20134            public int countAll() {
20135                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
20136                                    FINDER_ARGS_EMPTY, this);
20137    
20138                    if (count == null) {
20139                            Session session = null;
20140    
20141                            try {
20142                                    session = openSession();
20143    
20144                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20145    
20146                                    count = (Long)q.uniqueResult();
20147    
20148                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
20149                                            count);
20150                            }
20151                            catch (Exception e) {
20152                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
20153                                            FINDER_ARGS_EMPTY);
20154    
20155                                    throw processException(e);
20156                            }
20157                            finally {
20158                                    closeSession(session);
20159                            }
20160                    }
20161    
20162                    return count.intValue();
20163            }
20164    
20165            @Override
20166            public Set<String> getBadColumnNames() {
20167                    return _badColumnNames;
20168            }
20169    
20170            @Override
20171            protected Map<String, Integer> getTableColumnsMap() {
20172                    return MBMessageModelImpl.TABLE_COLUMNS_MAP;
20173            }
20174    
20175            /**
20176             * Initializes the message-boards message persistence.
20177             */
20178            public void afterPropertiesSet() {
20179            }
20180    
20181            public void destroy() {
20182                    entityCache.removeCache(MBMessageImpl.class.getName());
20183                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
20184                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20185                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20186            }
20187    
20188            @BeanReference(type = CompanyProvider.class)
20189            protected CompanyProvider companyProvider;
20190            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
20191            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
20192            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
20193            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
20194            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
20195            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
20196            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
20197            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
20198            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
20199            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
20200                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
20201            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
20202                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
20203            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
20204            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
20205            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
20206            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
20207            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
20208            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
20209            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
20210            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
20211            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
20212                                    "uuid"
20213                            });
20214            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
20215                            @Override
20216                            public Object clone() {
20217                                    return this;
20218                            }
20219    
20220                            @Override
20221                            public CacheModel<MBMessage> toCacheModel() {
20222                                    return _nullMBMessageCacheModel;
20223                            }
20224                    };
20225    
20226            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
20227                            @Override
20228                            public MBMessage toEntityModel() {
20229                                    return _nullMBMessage;
20230                            }
20231                    };
20232    }