001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.message.boards.kernel.exception.NoSuchMessageException;
020    import com.liferay.message.boards.kernel.model.MBMessage;
021    import com.liferay.message.boards.kernel.service.persistence.MBMessagePersistence;
022    
023    import com.liferay.portal.kernel.bean.BeanReference;
024    import com.liferay.portal.kernel.dao.orm.EntityCache;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCache;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.model.CacheModel;
038    import com.liferay.portal.kernel.sanitizer.Sanitizer;
039    import com.liferay.portal.kernel.sanitizer.SanitizerException;
040    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
041    import com.liferay.portal.kernel.security.auth.PrincipalThreadLocal;
042    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.kernel.service.ServiceContext;
044    import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
045    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
046    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
047    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
048    import com.liferay.portal.kernel.util.ArrayUtil;
049    import com.liferay.portal.kernel.util.ContentTypes;
050    import com.liferay.portal.kernel.util.GetterUtil;
051    import com.liferay.portal.kernel.util.OrderByComparator;
052    import com.liferay.portal.kernel.util.SetUtil;
053    import com.liferay.portal.kernel.util.StringBundler;
054    import com.liferay.portal.kernel.util.StringPool;
055    import com.liferay.portal.kernel.util.StringUtil;
056    import com.liferay.portal.kernel.util.Validator;
057    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
058    
059    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
060    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
061    
062    import java.io.Serializable;
063    
064    import java.util.Arrays;
065    import java.util.Collections;
066    import java.util.Date;
067    import java.util.HashMap;
068    import java.util.HashSet;
069    import java.util.Iterator;
070    import java.util.List;
071    import java.util.Map;
072    import java.util.Objects;
073    import java.util.Set;
074    
075    /**
076     * The persistence implementation for the message-boards message service.
077     *
078     * <p>
079     * Caching information and settings can be found in <code>portal.properties</code>
080     * </p>
081     *
082     * @author Brian Wing Shun Chan
083     * @see MBMessagePersistence
084     * @see com.liferay.message.boards.kernel.service.persistence.MBMessageUtil
085     * @generated
086     */
087    @ProviderType
088    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
089            implements MBMessagePersistence {
090            /*
091             * NOTE FOR DEVELOPERS:
092             *
093             * 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.
094             */
095            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
096            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
097                    ".List1";
098            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
099                    ".List2";
100            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
101                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
106            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
107                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
109            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
110                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
112                            new String[] {
113                                    String.class.getName(),
114                                    
115                            Integer.class.getName(), Integer.class.getName(),
116                                    OrderByComparator.class.getName()
117                            });
118            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
119                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
121                            new String[] { String.class.getName() },
122                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
123                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
124            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
125                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
127                            new String[] { String.class.getName() });
128    
129            /**
130             * Returns all the message-boards messages where uuid = &#63;.
131             *
132             * @param uuid the uuid
133             * @return the matching message-boards messages
134             */
135            @Override
136            public List<MBMessage> findByUuid(String uuid) {
137                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
138            }
139    
140            /**
141             * Returns a range of all the message-boards messages where uuid = &#63;.
142             *
143             * <p>
144             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
145             * </p>
146             *
147             * @param uuid the uuid
148             * @param start the lower bound of the range of message-boards messages
149             * @param end the upper bound of the range of message-boards messages (not inclusive)
150             * @return the range of matching message-boards messages
151             */
152            @Override
153            public List<MBMessage> findByUuid(String uuid, int start, int end) {
154                    return findByUuid(uuid, start, end, null);
155            }
156    
157            /**
158             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
159             *
160             * <p>
161             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
162             * </p>
163             *
164             * @param uuid the uuid
165             * @param start the lower bound of the range of message-boards messages
166             * @param end the upper bound of the range of message-boards messages (not inclusive)
167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
168             * @return the ordered range of matching message-boards messages
169             */
170            @Override
171            public List<MBMessage> findByUuid(String uuid, int start, int end,
172                    OrderByComparator<MBMessage> orderByComparator) {
173                    return findByUuid(uuid, start, end, orderByComparator, true);
174            }
175    
176            /**
177             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
178             *
179             * <p>
180             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
181             * </p>
182             *
183             * @param uuid the uuid
184             * @param start the lower bound of the range of message-boards messages
185             * @param end the upper bound of the range of message-boards messages (not inclusive)
186             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
187             * @param retrieveFromCache whether to retrieve from the finder cache
188             * @return the ordered range of matching message-boards messages
189             */
190            @Override
191            public List<MBMessage> findByUuid(String uuid, int start, int end,
192                    OrderByComparator<MBMessage> orderByComparator,
193                    boolean retrieveFromCache) {
194                    boolean pagination = true;
195                    FinderPath finderPath = null;
196                    Object[] finderArgs = null;
197    
198                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
199                                    (orderByComparator == null)) {
200                            pagination = false;
201                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
202                            finderArgs = new Object[] { uuid };
203                    }
204                    else {
205                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
206                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
207                    }
208    
209                    List<MBMessage> list = null;
210    
211                    if (retrieveFromCache) {
212                            list = (List<MBMessage>)finderCache.getResult(finderPath,
213                                            finderArgs, this);
214    
215                            if ((list != null) && !list.isEmpty()) {
216                                    for (MBMessage mbMessage : list) {
217                                            if (!Objects.equals(uuid, mbMessage.getUuid())) {
218                                                    list = null;
219    
220                                                    break;
221                                            }
222                                    }
223                            }
224                    }
225    
226                    if (list == null) {
227                            StringBundler query = null;
228    
229                            if (orderByComparator != null) {
230                                    query = new StringBundler(3 +
231                                                    (orderByComparator.getOrderByFields().length * 2));
232                            }
233                            else {
234                                    query = new StringBundler(3);
235                            }
236    
237                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
238    
239                            boolean bindUuid = false;
240    
241                            if (uuid == null) {
242                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
243                            }
244                            else if (uuid.equals(StringPool.BLANK)) {
245                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
246                            }
247                            else {
248                                    bindUuid = true;
249    
250                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
251                            }
252    
253                            if (orderByComparator != null) {
254                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
255                                            orderByComparator);
256                            }
257                            else
258                             if (pagination) {
259                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
260                            }
261    
262                            String sql = query.toString();
263    
264                            Session session = null;
265    
266                            try {
267                                    session = openSession();
268    
269                                    Query q = session.createQuery(sql);
270    
271                                    QueryPos qPos = QueryPos.getInstance(q);
272    
273                                    if (bindUuid) {
274                                            qPos.add(uuid);
275                                    }
276    
277                                    if (!pagination) {
278                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
279                                                            start, end, false);
280    
281                                            Collections.sort(list);
282    
283                                            list = Collections.unmodifiableList(list);
284                                    }
285                                    else {
286                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
287                                                            start, end);
288                                    }
289    
290                                    cacheResult(list);
291    
292                                    finderCache.putResult(finderPath, finderArgs, list);
293                            }
294                            catch (Exception e) {
295                                    finderCache.removeResult(finderPath, finderArgs);
296    
297                                    throw processException(e);
298                            }
299                            finally {
300                                    closeSession(session);
301                            }
302                    }
303    
304                    return list;
305            }
306    
307            /**
308             * Returns the first message-boards message in the ordered set where uuid = &#63;.
309             *
310             * @param uuid the uuid
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the first matching message-boards message
313             * @throws NoSuchMessageException if a matching message-boards message could not be found
314             */
315            @Override
316            public MBMessage findByUuid_First(String uuid,
317                    OrderByComparator<MBMessage> orderByComparator)
318                    throws NoSuchMessageException {
319                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
320    
321                    if (mbMessage != null) {
322                            return mbMessage;
323                    }
324    
325                    StringBundler msg = new StringBundler(4);
326    
327                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
328    
329                    msg.append("uuid=");
330                    msg.append(uuid);
331    
332                    msg.append(StringPool.CLOSE_CURLY_BRACE);
333    
334                    throw new NoSuchMessageException(msg.toString());
335            }
336    
337            /**
338             * Returns the first message-boards message in the ordered set where uuid = &#63;.
339             *
340             * @param uuid the uuid
341             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
342             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
343             */
344            @Override
345            public MBMessage fetchByUuid_First(String uuid,
346                    OrderByComparator<MBMessage> orderByComparator) {
347                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
348    
349                    if (!list.isEmpty()) {
350                            return list.get(0);
351                    }
352    
353                    return null;
354            }
355    
356            /**
357             * Returns the last message-boards message in the ordered set where uuid = &#63;.
358             *
359             * @param uuid the uuid
360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
361             * @return the last matching message-boards message
362             * @throws NoSuchMessageException if a matching message-boards message could not be found
363             */
364            @Override
365            public MBMessage findByUuid_Last(String uuid,
366                    OrderByComparator<MBMessage> orderByComparator)
367                    throws NoSuchMessageException {
368                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
369    
370                    if (mbMessage != null) {
371                            return mbMessage;
372                    }
373    
374                    StringBundler msg = new StringBundler(4);
375    
376                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
377    
378                    msg.append("uuid=");
379                    msg.append(uuid);
380    
381                    msg.append(StringPool.CLOSE_CURLY_BRACE);
382    
383                    throw new NoSuchMessageException(msg.toString());
384            }
385    
386            /**
387             * Returns the last message-boards message in the ordered set where uuid = &#63;.
388             *
389             * @param uuid the uuid
390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
391             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
392             */
393            @Override
394            public MBMessage fetchByUuid_Last(String uuid,
395                    OrderByComparator<MBMessage> orderByComparator) {
396                    int count = countByUuid(uuid);
397    
398                    if (count == 0) {
399                            return null;
400                    }
401    
402                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
403                                    orderByComparator);
404    
405                    if (!list.isEmpty()) {
406                            return list.get(0);
407                    }
408    
409                    return null;
410            }
411    
412            /**
413             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
414             *
415             * @param messageId the primary key of the current message-boards message
416             * @param uuid the uuid
417             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
418             * @return the previous, current, and next message-boards message
419             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
420             */
421            @Override
422            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
423                    OrderByComparator<MBMessage> orderByComparator)
424                    throws NoSuchMessageException {
425                    MBMessage mbMessage = findByPrimaryKey(messageId);
426    
427                    Session session = null;
428    
429                    try {
430                            session = openSession();
431    
432                            MBMessage[] array = new MBMessageImpl[3];
433    
434                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
435                                            orderByComparator, true);
436    
437                            array[1] = mbMessage;
438    
439                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
440                                            orderByComparator, false);
441    
442                            return array;
443                    }
444                    catch (Exception e) {
445                            throw processException(e);
446                    }
447                    finally {
448                            closeSession(session);
449                    }
450            }
451    
452            protected MBMessage getByUuid_PrevAndNext(Session session,
453                    MBMessage mbMessage, String uuid,
454                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
455                    StringBundler query = null;
456    
457                    if (orderByComparator != null) {
458                            query = new StringBundler(4 +
459                                            (orderByComparator.getOrderByConditionFields().length * 3) +
460                                            (orderByComparator.getOrderByFields().length * 3));
461                    }
462                    else {
463                            query = new StringBundler(3);
464                    }
465    
466                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
467    
468                    boolean bindUuid = false;
469    
470                    if (uuid == null) {
471                            query.append(_FINDER_COLUMN_UUID_UUID_1);
472                    }
473                    else if (uuid.equals(StringPool.BLANK)) {
474                            query.append(_FINDER_COLUMN_UUID_UUID_3);
475                    }
476                    else {
477                            bindUuid = true;
478    
479                            query.append(_FINDER_COLUMN_UUID_UUID_2);
480                    }
481    
482                    if (orderByComparator != null) {
483                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
484    
485                            if (orderByConditionFields.length > 0) {
486                                    query.append(WHERE_AND);
487                            }
488    
489                            for (int i = 0; i < orderByConditionFields.length; i++) {
490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
491                                    query.append(orderByConditionFields[i]);
492    
493                                    if ((i + 1) < orderByConditionFields.length) {
494                                            if (orderByComparator.isAscending() ^ previous) {
495                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
496                                            }
497                                            else {
498                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
499                                            }
500                                    }
501                                    else {
502                                            if (orderByComparator.isAscending() ^ previous) {
503                                                    query.append(WHERE_GREATER_THAN);
504                                            }
505                                            else {
506                                                    query.append(WHERE_LESSER_THAN);
507                                            }
508                                    }
509                            }
510    
511                            query.append(ORDER_BY_CLAUSE);
512    
513                            String[] orderByFields = orderByComparator.getOrderByFields();
514    
515                            for (int i = 0; i < orderByFields.length; i++) {
516                                    query.append(_ORDER_BY_ENTITY_ALIAS);
517                                    query.append(orderByFields[i]);
518    
519                                    if ((i + 1) < orderByFields.length) {
520                                            if (orderByComparator.isAscending() ^ previous) {
521                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
522                                            }
523                                            else {
524                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
525                                            }
526                                    }
527                                    else {
528                                            if (orderByComparator.isAscending() ^ previous) {
529                                                    query.append(ORDER_BY_ASC);
530                                            }
531                                            else {
532                                                    query.append(ORDER_BY_DESC);
533                                            }
534                                    }
535                            }
536                    }
537                    else {
538                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
539                    }
540    
541                    String sql = query.toString();
542    
543                    Query q = session.createQuery(sql);
544    
545                    q.setFirstResult(0);
546                    q.setMaxResults(2);
547    
548                    QueryPos qPos = QueryPos.getInstance(q);
549    
550                    if (bindUuid) {
551                            qPos.add(uuid);
552                    }
553    
554                    if (orderByComparator != null) {
555                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
556    
557                            for (Object value : values) {
558                                    qPos.add(value);
559                            }
560                    }
561    
562                    List<MBMessage> list = q.list();
563    
564                    if (list.size() == 2) {
565                            return list.get(1);
566                    }
567                    else {
568                            return null;
569                    }
570            }
571    
572            /**
573             * Removes all the message-boards messages where uuid = &#63; from the database.
574             *
575             * @param uuid the uuid
576             */
577            @Override
578            public void removeByUuid(String uuid) {
579                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
580                                    QueryUtil.ALL_POS, null)) {
581                            remove(mbMessage);
582                    }
583            }
584    
585            /**
586             * Returns the number of message-boards messages where uuid = &#63;.
587             *
588             * @param uuid the uuid
589             * @return the number of matching message-boards messages
590             */
591            @Override
592            public int countByUuid(String uuid) {
593                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
594    
595                    Object[] finderArgs = new Object[] { uuid };
596    
597                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
598    
599                    if (count == null) {
600                            StringBundler query = new StringBundler(2);
601    
602                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
603    
604                            boolean bindUuid = false;
605    
606                            if (uuid == null) {
607                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
608                            }
609                            else if (uuid.equals(StringPool.BLANK)) {
610                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
611                            }
612                            else {
613                                    bindUuid = true;
614    
615                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
616                            }
617    
618                            String sql = query.toString();
619    
620                            Session session = null;
621    
622                            try {
623                                    session = openSession();
624    
625                                    Query q = session.createQuery(sql);
626    
627                                    QueryPos qPos = QueryPos.getInstance(q);
628    
629                                    if (bindUuid) {
630                                            qPos.add(uuid);
631                                    }
632    
633                                    count = (Long)q.uniqueResult();
634    
635                                    finderCache.putResult(finderPath, finderArgs, count);
636                            }
637                            catch (Exception e) {
638                                    finderCache.removeResult(finderPath, finderArgs);
639    
640                                    throw processException(e);
641                            }
642                            finally {
643                                    closeSession(session);
644                            }
645                    }
646    
647                    return count.intValue();
648            }
649    
650            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
651            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
652            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
653            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
655                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
656                            new String[] { String.class.getName(), Long.class.getName() },
657                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
658                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
659            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
660                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
661                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
662                            new String[] { String.class.getName(), Long.class.getName() });
663    
664            /**
665             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
666             *
667             * @param uuid the uuid
668             * @param groupId the group ID
669             * @return the matching message-boards message
670             * @throws NoSuchMessageException if a matching message-boards message could not be found
671             */
672            @Override
673            public MBMessage findByUUID_G(String uuid, long groupId)
674                    throws NoSuchMessageException {
675                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
676    
677                    if (mbMessage == null) {
678                            StringBundler msg = new StringBundler(6);
679    
680                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
681    
682                            msg.append("uuid=");
683                            msg.append(uuid);
684    
685                            msg.append(", groupId=");
686                            msg.append(groupId);
687    
688                            msg.append(StringPool.CLOSE_CURLY_BRACE);
689    
690                            if (_log.isDebugEnabled()) {
691                                    _log.debug(msg.toString());
692                            }
693    
694                            throw new NoSuchMessageException(msg.toString());
695                    }
696    
697                    return mbMessage;
698            }
699    
700            /**
701             * 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.
702             *
703             * @param uuid the uuid
704             * @param groupId the group ID
705             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
706             */
707            @Override
708            public MBMessage fetchByUUID_G(String uuid, long groupId) {
709                    return fetchByUUID_G(uuid, groupId, true);
710            }
711    
712            /**
713             * 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.
714             *
715             * @param uuid the uuid
716             * @param groupId the group ID
717             * @param retrieveFromCache whether to retrieve from the finder cache
718             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
719             */
720            @Override
721            public MBMessage fetchByUUID_G(String uuid, long groupId,
722                    boolean retrieveFromCache) {
723                    Object[] finderArgs = new Object[] { uuid, groupId };
724    
725                    Object result = null;
726    
727                    if (retrieveFromCache) {
728                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
729                                            finderArgs, this);
730                    }
731    
732                    if (result instanceof MBMessage) {
733                            MBMessage mbMessage = (MBMessage)result;
734    
735                            if (!Objects.equals(uuid, mbMessage.getUuid()) ||
736                                            (groupId != mbMessage.getGroupId())) {
737                                    result = null;
738                            }
739                    }
740    
741                    if (result == null) {
742                            StringBundler query = new StringBundler(4);
743    
744                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
745    
746                            boolean bindUuid = false;
747    
748                            if (uuid == null) {
749                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
750                            }
751                            else if (uuid.equals(StringPool.BLANK)) {
752                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
753                            }
754                            else {
755                                    bindUuid = true;
756    
757                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
758                            }
759    
760                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
761    
762                            String sql = query.toString();
763    
764                            Session session = null;
765    
766                            try {
767                                    session = openSession();
768    
769                                    Query q = session.createQuery(sql);
770    
771                                    QueryPos qPos = QueryPos.getInstance(q);
772    
773                                    if (bindUuid) {
774                                            qPos.add(uuid);
775                                    }
776    
777                                    qPos.add(groupId);
778    
779                                    List<MBMessage> list = q.list();
780    
781                                    if (list.isEmpty()) {
782                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
783                                                    finderArgs, list);
784                                    }
785                                    else {
786                                            MBMessage mbMessage = list.get(0);
787    
788                                            result = mbMessage;
789    
790                                            cacheResult(mbMessage);
791    
792                                            if ((mbMessage.getUuid() == null) ||
793                                                            !mbMessage.getUuid().equals(uuid) ||
794                                                            (mbMessage.getGroupId() != groupId)) {
795                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
796                                                            finderArgs, mbMessage);
797                                            }
798                                    }
799                            }
800                            catch (Exception e) {
801                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
802    
803                                    throw processException(e);
804                            }
805                            finally {
806                                    closeSession(session);
807                            }
808                    }
809    
810                    if (result instanceof List<?>) {
811                            return null;
812                    }
813                    else {
814                            return (MBMessage)result;
815                    }
816            }
817    
818            /**
819             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
820             *
821             * @param uuid the uuid
822             * @param groupId the group ID
823             * @return the message-boards message that was removed
824             */
825            @Override
826            public MBMessage removeByUUID_G(String uuid, long groupId)
827                    throws NoSuchMessageException {
828                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
829    
830                    return remove(mbMessage);
831            }
832    
833            /**
834             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
835             *
836             * @param uuid the uuid
837             * @param groupId the group ID
838             * @return the number of matching message-boards messages
839             */
840            @Override
841            public int countByUUID_G(String uuid, long groupId) {
842                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
843    
844                    Object[] finderArgs = new Object[] { uuid, groupId };
845    
846                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
847    
848                    if (count == null) {
849                            StringBundler query = new StringBundler(3);
850    
851                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
852    
853                            boolean bindUuid = false;
854    
855                            if (uuid == null) {
856                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
857                            }
858                            else if (uuid.equals(StringPool.BLANK)) {
859                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
860                            }
861                            else {
862                                    bindUuid = true;
863    
864                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
865                            }
866    
867                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
868    
869                            String sql = query.toString();
870    
871                            Session session = null;
872    
873                            try {
874                                    session = openSession();
875    
876                                    Query q = session.createQuery(sql);
877    
878                                    QueryPos qPos = QueryPos.getInstance(q);
879    
880                                    if (bindUuid) {
881                                            qPos.add(uuid);
882                                    }
883    
884                                    qPos.add(groupId);
885    
886                                    count = (Long)q.uniqueResult();
887    
888                                    finderCache.putResult(finderPath, finderArgs, count);
889                            }
890                            catch (Exception e) {
891                                    finderCache.removeResult(finderPath, finderArgs);
892    
893                                    throw processException(e);
894                            }
895                            finally {
896                                    closeSession(session);
897                            }
898                    }
899    
900                    return count.intValue();
901            }
902    
903            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
904            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
905            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
906            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
907            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
908                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
909                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
910                            new String[] {
911                                    String.class.getName(), Long.class.getName(),
912                                    
913                            Integer.class.getName(), Integer.class.getName(),
914                                    OrderByComparator.class.getName()
915                            });
916            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
917                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
918                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
919                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
920                            new String[] { String.class.getName(), Long.class.getName() },
921                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
922                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
923                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
924            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
925                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
926                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
927                            new String[] { String.class.getName(), Long.class.getName() });
928    
929            /**
930             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
931             *
932             * @param uuid the uuid
933             * @param companyId the company ID
934             * @return the matching message-boards messages
935             */
936            @Override
937            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
938                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
939                            QueryUtil.ALL_POS, null);
940            }
941    
942            /**
943             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
944             *
945             * <p>
946             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
947             * </p>
948             *
949             * @param uuid the uuid
950             * @param companyId the company ID
951             * @param start the lower bound of the range of message-boards messages
952             * @param end the upper bound of the range of message-boards messages (not inclusive)
953             * @return the range of matching message-boards messages
954             */
955            @Override
956            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
957                    int end) {
958                    return findByUuid_C(uuid, companyId, start, end, null);
959            }
960    
961            /**
962             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
963             *
964             * <p>
965             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
966             * </p>
967             *
968             * @param uuid the uuid
969             * @param companyId the company ID
970             * @param start the lower bound of the range of message-boards messages
971             * @param end the upper bound of the range of message-boards messages (not inclusive)
972             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
973             * @return the ordered range of matching message-boards messages
974             */
975            @Override
976            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
977                    int end, OrderByComparator<MBMessage> orderByComparator) {
978                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
979            }
980    
981            /**
982             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
983             *
984             * <p>
985             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
986             * </p>
987             *
988             * @param uuid the uuid
989             * @param companyId the company ID
990             * @param start the lower bound of the range of message-boards messages
991             * @param end the upper bound of the range of message-boards messages (not inclusive)
992             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
993             * @param retrieveFromCache whether to retrieve from the finder cache
994             * @return the ordered range of matching message-boards messages
995             */
996            @Override
997            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
998                    int end, OrderByComparator<MBMessage> orderByComparator,
999                    boolean retrieveFromCache) {
1000                    boolean pagination = true;
1001                    FinderPath finderPath = null;
1002                    Object[] finderArgs = null;
1003    
1004                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1005                                    (orderByComparator == null)) {
1006                            pagination = false;
1007                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1008                            finderArgs = new Object[] { uuid, companyId };
1009                    }
1010                    else {
1011                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1012                            finderArgs = new Object[] {
1013                                            uuid, companyId,
1014                                            
1015                                            start, end, orderByComparator
1016                                    };
1017                    }
1018    
1019                    List<MBMessage> list = null;
1020    
1021                    if (retrieveFromCache) {
1022                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1023                                            finderArgs, this);
1024    
1025                            if ((list != null) && !list.isEmpty()) {
1026                                    for (MBMessage mbMessage : list) {
1027                                            if (!Objects.equals(uuid, mbMessage.getUuid()) ||
1028                                                            (companyId != mbMessage.getCompanyId())) {
1029                                                    list = null;
1030    
1031                                                    break;
1032                                            }
1033                                    }
1034                            }
1035                    }
1036    
1037                    if (list == null) {
1038                            StringBundler query = null;
1039    
1040                            if (orderByComparator != null) {
1041                                    query = new StringBundler(4 +
1042                                                    (orderByComparator.getOrderByFields().length * 2));
1043                            }
1044                            else {
1045                                    query = new StringBundler(4);
1046                            }
1047    
1048                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1049    
1050                            boolean bindUuid = false;
1051    
1052                            if (uuid == null) {
1053                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1054                            }
1055                            else if (uuid.equals(StringPool.BLANK)) {
1056                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1057                            }
1058                            else {
1059                                    bindUuid = true;
1060    
1061                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1062                            }
1063    
1064                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1065    
1066                            if (orderByComparator != null) {
1067                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1068                                            orderByComparator);
1069                            }
1070                            else
1071                             if (pagination) {
1072                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1073                            }
1074    
1075                            String sql = query.toString();
1076    
1077                            Session session = null;
1078    
1079                            try {
1080                                    session = openSession();
1081    
1082                                    Query q = session.createQuery(sql);
1083    
1084                                    QueryPos qPos = QueryPos.getInstance(q);
1085    
1086                                    if (bindUuid) {
1087                                            qPos.add(uuid);
1088                                    }
1089    
1090                                    qPos.add(companyId);
1091    
1092                                    if (!pagination) {
1093                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1094                                                            start, end, false);
1095    
1096                                            Collections.sort(list);
1097    
1098                                            list = Collections.unmodifiableList(list);
1099                                    }
1100                                    else {
1101                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1102                                                            start, end);
1103                                    }
1104    
1105                                    cacheResult(list);
1106    
1107                                    finderCache.putResult(finderPath, finderArgs, list);
1108                            }
1109                            catch (Exception e) {
1110                                    finderCache.removeResult(finderPath, finderArgs);
1111    
1112                                    throw processException(e);
1113                            }
1114                            finally {
1115                                    closeSession(session);
1116                            }
1117                    }
1118    
1119                    return list;
1120            }
1121    
1122            /**
1123             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1124             *
1125             * @param uuid the uuid
1126             * @param companyId the company ID
1127             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1128             * @return the first matching message-boards message
1129             * @throws NoSuchMessageException if a matching message-boards message could not be found
1130             */
1131            @Override
1132            public MBMessage findByUuid_C_First(String uuid, long companyId,
1133                    OrderByComparator<MBMessage> orderByComparator)
1134                    throws NoSuchMessageException {
1135                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1136                                    orderByComparator);
1137    
1138                    if (mbMessage != null) {
1139                            return mbMessage;
1140                    }
1141    
1142                    StringBundler msg = new StringBundler(6);
1143    
1144                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1145    
1146                    msg.append("uuid=");
1147                    msg.append(uuid);
1148    
1149                    msg.append(", companyId=");
1150                    msg.append(companyId);
1151    
1152                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1153    
1154                    throw new NoSuchMessageException(msg.toString());
1155            }
1156    
1157            /**
1158             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1159             *
1160             * @param uuid the uuid
1161             * @param companyId the company ID
1162             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1163             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1164             */
1165            @Override
1166            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1167                    OrderByComparator<MBMessage> orderByComparator) {
1168                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1169                                    orderByComparator);
1170    
1171                    if (!list.isEmpty()) {
1172                            return list.get(0);
1173                    }
1174    
1175                    return null;
1176            }
1177    
1178            /**
1179             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1180             *
1181             * @param uuid the uuid
1182             * @param companyId the company ID
1183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1184             * @return the last matching message-boards message
1185             * @throws NoSuchMessageException if a matching message-boards message could not be found
1186             */
1187            @Override
1188            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1189                    OrderByComparator<MBMessage> orderByComparator)
1190                    throws NoSuchMessageException {
1191                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1192                                    orderByComparator);
1193    
1194                    if (mbMessage != null) {
1195                            return mbMessage;
1196                    }
1197    
1198                    StringBundler msg = new StringBundler(6);
1199    
1200                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1201    
1202                    msg.append("uuid=");
1203                    msg.append(uuid);
1204    
1205                    msg.append(", companyId=");
1206                    msg.append(companyId);
1207    
1208                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1209    
1210                    throw new NoSuchMessageException(msg.toString());
1211            }
1212    
1213            /**
1214             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1215             *
1216             * @param uuid the uuid
1217             * @param companyId the company ID
1218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1219             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1220             */
1221            @Override
1222            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1223                    OrderByComparator<MBMessage> orderByComparator) {
1224                    int count = countByUuid_C(uuid, companyId);
1225    
1226                    if (count == 0) {
1227                            return null;
1228                    }
1229    
1230                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1231                                    orderByComparator);
1232    
1233                    if (!list.isEmpty()) {
1234                            return list.get(0);
1235                    }
1236    
1237                    return null;
1238            }
1239    
1240            /**
1241             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1242             *
1243             * @param messageId the primary key of the current message-boards message
1244             * @param uuid the uuid
1245             * @param companyId the company ID
1246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1247             * @return the previous, current, and next message-boards message
1248             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1249             */
1250            @Override
1251            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1252                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1253                    throws NoSuchMessageException {
1254                    MBMessage mbMessage = findByPrimaryKey(messageId);
1255    
1256                    Session session = null;
1257    
1258                    try {
1259                            session = openSession();
1260    
1261                            MBMessage[] array = new MBMessageImpl[3];
1262    
1263                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1264                                            companyId, orderByComparator, true);
1265    
1266                            array[1] = mbMessage;
1267    
1268                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1269                                            companyId, orderByComparator, false);
1270    
1271                            return array;
1272                    }
1273                    catch (Exception e) {
1274                            throw processException(e);
1275                    }
1276                    finally {
1277                            closeSession(session);
1278                    }
1279            }
1280    
1281            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1282                    MBMessage mbMessage, String uuid, long companyId,
1283                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1284                    StringBundler query = null;
1285    
1286                    if (orderByComparator != null) {
1287                            query = new StringBundler(5 +
1288                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1289                                            (orderByComparator.getOrderByFields().length * 3));
1290                    }
1291                    else {
1292                            query = new StringBundler(4);
1293                    }
1294    
1295                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1296    
1297                    boolean bindUuid = false;
1298    
1299                    if (uuid == null) {
1300                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1301                    }
1302                    else if (uuid.equals(StringPool.BLANK)) {
1303                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1304                    }
1305                    else {
1306                            bindUuid = true;
1307    
1308                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1309                    }
1310    
1311                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1312    
1313                    if (orderByComparator != null) {
1314                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1315    
1316                            if (orderByConditionFields.length > 0) {
1317                                    query.append(WHERE_AND);
1318                            }
1319    
1320                            for (int i = 0; i < orderByConditionFields.length; i++) {
1321                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1322                                    query.append(orderByConditionFields[i]);
1323    
1324                                    if ((i + 1) < orderByConditionFields.length) {
1325                                            if (orderByComparator.isAscending() ^ previous) {
1326                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1327                                            }
1328                                            else {
1329                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1330                                            }
1331                                    }
1332                                    else {
1333                                            if (orderByComparator.isAscending() ^ previous) {
1334                                                    query.append(WHERE_GREATER_THAN);
1335                                            }
1336                                            else {
1337                                                    query.append(WHERE_LESSER_THAN);
1338                                            }
1339                                    }
1340                            }
1341    
1342                            query.append(ORDER_BY_CLAUSE);
1343    
1344                            String[] orderByFields = orderByComparator.getOrderByFields();
1345    
1346                            for (int i = 0; i < orderByFields.length; i++) {
1347                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1348                                    query.append(orderByFields[i]);
1349    
1350                                    if ((i + 1) < orderByFields.length) {
1351                                            if (orderByComparator.isAscending() ^ previous) {
1352                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1353                                            }
1354                                            else {
1355                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1356                                            }
1357                                    }
1358                                    else {
1359                                            if (orderByComparator.isAscending() ^ previous) {
1360                                                    query.append(ORDER_BY_ASC);
1361                                            }
1362                                            else {
1363                                                    query.append(ORDER_BY_DESC);
1364                                            }
1365                                    }
1366                            }
1367                    }
1368                    else {
1369                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1370                    }
1371    
1372                    String sql = query.toString();
1373    
1374                    Query q = session.createQuery(sql);
1375    
1376                    q.setFirstResult(0);
1377                    q.setMaxResults(2);
1378    
1379                    QueryPos qPos = QueryPos.getInstance(q);
1380    
1381                    if (bindUuid) {
1382                            qPos.add(uuid);
1383                    }
1384    
1385                    qPos.add(companyId);
1386    
1387                    if (orderByComparator != null) {
1388                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1389    
1390                            for (Object value : values) {
1391                                    qPos.add(value);
1392                            }
1393                    }
1394    
1395                    List<MBMessage> list = q.list();
1396    
1397                    if (list.size() == 2) {
1398                            return list.get(1);
1399                    }
1400                    else {
1401                            return null;
1402                    }
1403            }
1404    
1405            /**
1406             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1407             *
1408             * @param uuid the uuid
1409             * @param companyId the company ID
1410             */
1411            @Override
1412            public void removeByUuid_C(String uuid, long companyId) {
1413                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1414                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1415                            remove(mbMessage);
1416                    }
1417            }
1418    
1419            /**
1420             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1421             *
1422             * @param uuid the uuid
1423             * @param companyId the company ID
1424             * @return the number of matching message-boards messages
1425             */
1426            @Override
1427            public int countByUuid_C(String uuid, long companyId) {
1428                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1429    
1430                    Object[] finderArgs = new Object[] { uuid, companyId };
1431    
1432                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1433    
1434                    if (count == null) {
1435                            StringBundler query = new StringBundler(3);
1436    
1437                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1438    
1439                            boolean bindUuid = false;
1440    
1441                            if (uuid == null) {
1442                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1443                            }
1444                            else if (uuid.equals(StringPool.BLANK)) {
1445                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1446                            }
1447                            else {
1448                                    bindUuid = true;
1449    
1450                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1451                            }
1452    
1453                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1454    
1455                            String sql = query.toString();
1456    
1457                            Session session = null;
1458    
1459                            try {
1460                                    session = openSession();
1461    
1462                                    Query q = session.createQuery(sql);
1463    
1464                                    QueryPos qPos = QueryPos.getInstance(q);
1465    
1466                                    if (bindUuid) {
1467                                            qPos.add(uuid);
1468                                    }
1469    
1470                                    qPos.add(companyId);
1471    
1472                                    count = (Long)q.uniqueResult();
1473    
1474                                    finderCache.putResult(finderPath, finderArgs, count);
1475                            }
1476                            catch (Exception e) {
1477                                    finderCache.removeResult(finderPath, finderArgs);
1478    
1479                                    throw processException(e);
1480                            }
1481                            finally {
1482                                    closeSession(session);
1483                            }
1484                    }
1485    
1486                    return count.intValue();
1487            }
1488    
1489            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1490            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1491            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1492            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1493            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1494                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1495                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1496                            new String[] {
1497                                    Long.class.getName(),
1498                                    
1499                            Integer.class.getName(), Integer.class.getName(),
1500                                    OrderByComparator.class.getName()
1501                            });
1502            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1503                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1504                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1505                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1506                            new String[] { Long.class.getName() },
1507                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1508                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1509            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1510                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1511                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1512                            new String[] { Long.class.getName() });
1513    
1514            /**
1515             * Returns all the message-boards messages where groupId = &#63;.
1516             *
1517             * @param groupId the group ID
1518             * @return the matching message-boards messages
1519             */
1520            @Override
1521            public List<MBMessage> findByGroupId(long groupId) {
1522                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1523            }
1524    
1525            /**
1526             * Returns a range of all the message-boards messages where groupId = &#63;.
1527             *
1528             * <p>
1529             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1530             * </p>
1531             *
1532             * @param groupId the group ID
1533             * @param start the lower bound of the range of message-boards messages
1534             * @param end the upper bound of the range of message-boards messages (not inclusive)
1535             * @return the range of matching message-boards messages
1536             */
1537            @Override
1538            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1539                    return findByGroupId(groupId, start, end, null);
1540            }
1541    
1542            /**
1543             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1544             *
1545             * <p>
1546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1547             * </p>
1548             *
1549             * @param groupId the group ID
1550             * @param start the lower bound of the range of message-boards messages
1551             * @param end the upper bound of the range of message-boards messages (not inclusive)
1552             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1553             * @return the ordered range of matching message-boards messages
1554             */
1555            @Override
1556            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1557                    OrderByComparator<MBMessage> orderByComparator) {
1558                    return findByGroupId(groupId, start, end, orderByComparator, true);
1559            }
1560    
1561            /**
1562             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1563             *
1564             * <p>
1565             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1566             * </p>
1567             *
1568             * @param groupId the group ID
1569             * @param start the lower bound of the range of message-boards messages
1570             * @param end the upper bound of the range of message-boards messages (not inclusive)
1571             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1572             * @param retrieveFromCache whether to retrieve from the finder cache
1573             * @return the ordered range of matching message-boards messages
1574             */
1575            @Override
1576            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1577                    OrderByComparator<MBMessage> orderByComparator,
1578                    boolean retrieveFromCache) {
1579                    boolean pagination = true;
1580                    FinderPath finderPath = null;
1581                    Object[] finderArgs = null;
1582    
1583                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1584                                    (orderByComparator == null)) {
1585                            pagination = false;
1586                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1587                            finderArgs = new Object[] { groupId };
1588                    }
1589                    else {
1590                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1591                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1592                    }
1593    
1594                    List<MBMessage> list = null;
1595    
1596                    if (retrieveFromCache) {
1597                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1598                                            finderArgs, this);
1599    
1600                            if ((list != null) && !list.isEmpty()) {
1601                                    for (MBMessage mbMessage : list) {
1602                                            if ((groupId != mbMessage.getGroupId())) {
1603                                                    list = null;
1604    
1605                                                    break;
1606                                            }
1607                                    }
1608                            }
1609                    }
1610    
1611                    if (list == null) {
1612                            StringBundler query = null;
1613    
1614                            if (orderByComparator != null) {
1615                                    query = new StringBundler(3 +
1616                                                    (orderByComparator.getOrderByFields().length * 2));
1617                            }
1618                            else {
1619                                    query = new StringBundler(3);
1620                            }
1621    
1622                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1623    
1624                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1625    
1626                            if (orderByComparator != null) {
1627                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1628                                            orderByComparator);
1629                            }
1630                            else
1631                             if (pagination) {
1632                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1633                            }
1634    
1635                            String sql = query.toString();
1636    
1637                            Session session = null;
1638    
1639                            try {
1640                                    session = openSession();
1641    
1642                                    Query q = session.createQuery(sql);
1643    
1644                                    QueryPos qPos = QueryPos.getInstance(q);
1645    
1646                                    qPos.add(groupId);
1647    
1648                                    if (!pagination) {
1649                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1650                                                            start, end, false);
1651    
1652                                            Collections.sort(list);
1653    
1654                                            list = Collections.unmodifiableList(list);
1655                                    }
1656                                    else {
1657                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1658                                                            start, end);
1659                                    }
1660    
1661                                    cacheResult(list);
1662    
1663                                    finderCache.putResult(finderPath, finderArgs, list);
1664                            }
1665                            catch (Exception e) {
1666                                    finderCache.removeResult(finderPath, finderArgs);
1667    
1668                                    throw processException(e);
1669                            }
1670                            finally {
1671                                    closeSession(session);
1672                            }
1673                    }
1674    
1675                    return list;
1676            }
1677    
1678            /**
1679             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1680             *
1681             * @param groupId the group ID
1682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1683             * @return the first matching message-boards message
1684             * @throws NoSuchMessageException if a matching message-boards message could not be found
1685             */
1686            @Override
1687            public MBMessage findByGroupId_First(long groupId,
1688                    OrderByComparator<MBMessage> orderByComparator)
1689                    throws NoSuchMessageException {
1690                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1691    
1692                    if (mbMessage != null) {
1693                            return mbMessage;
1694                    }
1695    
1696                    StringBundler msg = new StringBundler(4);
1697    
1698                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1699    
1700                    msg.append("groupId=");
1701                    msg.append(groupId);
1702    
1703                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1704    
1705                    throw new NoSuchMessageException(msg.toString());
1706            }
1707    
1708            /**
1709             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1710             *
1711             * @param groupId the group ID
1712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1713             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1714             */
1715            @Override
1716            public MBMessage fetchByGroupId_First(long groupId,
1717                    OrderByComparator<MBMessage> orderByComparator) {
1718                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1719    
1720                    if (!list.isEmpty()) {
1721                            return list.get(0);
1722                    }
1723    
1724                    return null;
1725            }
1726    
1727            /**
1728             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1729             *
1730             * @param groupId the group ID
1731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1732             * @return the last matching message-boards message
1733             * @throws NoSuchMessageException if a matching message-boards message could not be found
1734             */
1735            @Override
1736            public MBMessage findByGroupId_Last(long groupId,
1737                    OrderByComparator<MBMessage> orderByComparator)
1738                    throws NoSuchMessageException {
1739                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1740    
1741                    if (mbMessage != null) {
1742                            return mbMessage;
1743                    }
1744    
1745                    StringBundler msg = new StringBundler(4);
1746    
1747                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1748    
1749                    msg.append("groupId=");
1750                    msg.append(groupId);
1751    
1752                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1753    
1754                    throw new NoSuchMessageException(msg.toString());
1755            }
1756    
1757            /**
1758             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1759             *
1760             * @param groupId the group ID
1761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1762             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1763             */
1764            @Override
1765            public MBMessage fetchByGroupId_Last(long groupId,
1766                    OrderByComparator<MBMessage> orderByComparator) {
1767                    int count = countByGroupId(groupId);
1768    
1769                    if (count == 0) {
1770                            return null;
1771                    }
1772    
1773                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1774                                    orderByComparator);
1775    
1776                    if (!list.isEmpty()) {
1777                            return list.get(0);
1778                    }
1779    
1780                    return null;
1781            }
1782    
1783            /**
1784             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1785             *
1786             * @param messageId the primary key of the current message-boards message
1787             * @param groupId the group ID
1788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1789             * @return the previous, current, and next message-boards message
1790             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1791             */
1792            @Override
1793            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1794                    OrderByComparator<MBMessage> orderByComparator)
1795                    throws NoSuchMessageException {
1796                    MBMessage mbMessage = findByPrimaryKey(messageId);
1797    
1798                    Session session = null;
1799    
1800                    try {
1801                            session = openSession();
1802    
1803                            MBMessage[] array = new MBMessageImpl[3];
1804    
1805                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1806                                            orderByComparator, true);
1807    
1808                            array[1] = mbMessage;
1809    
1810                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1811                                            orderByComparator, false);
1812    
1813                            return array;
1814                    }
1815                    catch (Exception e) {
1816                            throw processException(e);
1817                    }
1818                    finally {
1819                            closeSession(session);
1820                    }
1821            }
1822    
1823            protected MBMessage getByGroupId_PrevAndNext(Session session,
1824                    MBMessage mbMessage, long groupId,
1825                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1826                    StringBundler query = null;
1827    
1828                    if (orderByComparator != null) {
1829                            query = new StringBundler(4 +
1830                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1831                                            (orderByComparator.getOrderByFields().length * 3));
1832                    }
1833                    else {
1834                            query = new StringBundler(3);
1835                    }
1836    
1837                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1838    
1839                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1840    
1841                    if (orderByComparator != null) {
1842                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1843    
1844                            if (orderByConditionFields.length > 0) {
1845                                    query.append(WHERE_AND);
1846                            }
1847    
1848                            for (int i = 0; i < orderByConditionFields.length; i++) {
1849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1850                                    query.append(orderByConditionFields[i]);
1851    
1852                                    if ((i + 1) < orderByConditionFields.length) {
1853                                            if (orderByComparator.isAscending() ^ previous) {
1854                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1855                                            }
1856                                            else {
1857                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1858                                            }
1859                                    }
1860                                    else {
1861                                            if (orderByComparator.isAscending() ^ previous) {
1862                                                    query.append(WHERE_GREATER_THAN);
1863                                            }
1864                                            else {
1865                                                    query.append(WHERE_LESSER_THAN);
1866                                            }
1867                                    }
1868                            }
1869    
1870                            query.append(ORDER_BY_CLAUSE);
1871    
1872                            String[] orderByFields = orderByComparator.getOrderByFields();
1873    
1874                            for (int i = 0; i < orderByFields.length; i++) {
1875                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1876                                    query.append(orderByFields[i]);
1877    
1878                                    if ((i + 1) < orderByFields.length) {
1879                                            if (orderByComparator.isAscending() ^ previous) {
1880                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1881                                            }
1882                                            else {
1883                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1884                                            }
1885                                    }
1886                                    else {
1887                                            if (orderByComparator.isAscending() ^ previous) {
1888                                                    query.append(ORDER_BY_ASC);
1889                                            }
1890                                            else {
1891                                                    query.append(ORDER_BY_DESC);
1892                                            }
1893                                    }
1894                            }
1895                    }
1896                    else {
1897                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1898                    }
1899    
1900                    String sql = query.toString();
1901    
1902                    Query q = session.createQuery(sql);
1903    
1904                    q.setFirstResult(0);
1905                    q.setMaxResults(2);
1906    
1907                    QueryPos qPos = QueryPos.getInstance(q);
1908    
1909                    qPos.add(groupId);
1910    
1911                    if (orderByComparator != null) {
1912                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1913    
1914                            for (Object value : values) {
1915                                    qPos.add(value);
1916                            }
1917                    }
1918    
1919                    List<MBMessage> list = q.list();
1920    
1921                    if (list.size() == 2) {
1922                            return list.get(1);
1923                    }
1924                    else {
1925                            return null;
1926                    }
1927            }
1928    
1929            /**
1930             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1931             *
1932             * @param groupId the group ID
1933             * @return the matching message-boards messages that the user has permission to view
1934             */
1935            @Override
1936            public List<MBMessage> filterFindByGroupId(long groupId) {
1937                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1938                            QueryUtil.ALL_POS, null);
1939            }
1940    
1941            /**
1942             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1943             *
1944             * <p>
1945             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1946             * </p>
1947             *
1948             * @param groupId the group ID
1949             * @param start the lower bound of the range of message-boards messages
1950             * @param end the upper bound of the range of message-boards messages (not inclusive)
1951             * @return the range of matching message-boards messages that the user has permission to view
1952             */
1953            @Override
1954            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1955                    return filterFindByGroupId(groupId, start, end, null);
1956            }
1957    
1958            /**
1959             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1960             *
1961             * <p>
1962             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1963             * </p>
1964             *
1965             * @param groupId the group ID
1966             * @param start the lower bound of the range of message-boards messages
1967             * @param end the upper bound of the range of message-boards messages (not inclusive)
1968             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1969             * @return the ordered range of matching message-boards messages that the user has permission to view
1970             */
1971            @Override
1972            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1973                    int end, OrderByComparator<MBMessage> orderByComparator) {
1974                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1975                            return findByGroupId(groupId, start, end, orderByComparator);
1976                    }
1977    
1978                    StringBundler query = null;
1979    
1980                    if (orderByComparator != null) {
1981                            query = new StringBundler(3 +
1982                                            (orderByComparator.getOrderByFields().length * 2));
1983                    }
1984                    else {
1985                            query = new StringBundler(4);
1986                    }
1987    
1988                    if (getDB().isSupportsInlineDistinct()) {
1989                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1990                    }
1991                    else {
1992                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1993                    }
1994    
1995                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1996    
1997                    if (!getDB().isSupportsInlineDistinct()) {
1998                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1999                    }
2000    
2001                    if (orderByComparator != null) {
2002                            if (getDB().isSupportsInlineDistinct()) {
2003                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2004                                            orderByComparator, true);
2005                            }
2006                            else {
2007                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2008                                            orderByComparator, true);
2009                            }
2010                    }
2011                    else {
2012                            if (getDB().isSupportsInlineDistinct()) {
2013                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2014                            }
2015                            else {
2016                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2017                            }
2018                    }
2019    
2020                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2021                                    MBMessage.class.getName(),
2022                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2023    
2024                    Session session = null;
2025    
2026                    try {
2027                            session = openSession();
2028    
2029                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2030    
2031                            if (getDB().isSupportsInlineDistinct()) {
2032                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2033                            }
2034                            else {
2035                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2036                            }
2037    
2038                            QueryPos qPos = QueryPos.getInstance(q);
2039    
2040                            qPos.add(groupId);
2041    
2042                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2043                    }
2044                    catch (Exception e) {
2045                            throw processException(e);
2046                    }
2047                    finally {
2048                            closeSession(session);
2049                    }
2050            }
2051    
2052            /**
2053             * 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;.
2054             *
2055             * @param messageId the primary key of the current message-boards message
2056             * @param groupId the group ID
2057             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2058             * @return the previous, current, and next message-boards message
2059             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2060             */
2061            @Override
2062            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2063                    long groupId, OrderByComparator<MBMessage> orderByComparator)
2064                    throws NoSuchMessageException {
2065                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2066                            return findByGroupId_PrevAndNext(messageId, groupId,
2067                                    orderByComparator);
2068                    }
2069    
2070                    MBMessage mbMessage = findByPrimaryKey(messageId);
2071    
2072                    Session session = null;
2073    
2074                    try {
2075                            session = openSession();
2076    
2077                            MBMessage[] array = new MBMessageImpl[3];
2078    
2079                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2080                                            groupId, orderByComparator, true);
2081    
2082                            array[1] = mbMessage;
2083    
2084                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2085                                            groupId, orderByComparator, false);
2086    
2087                            return array;
2088                    }
2089                    catch (Exception e) {
2090                            throw processException(e);
2091                    }
2092                    finally {
2093                            closeSession(session);
2094                    }
2095            }
2096    
2097            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2098                    MBMessage mbMessage, long groupId,
2099                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2100                    StringBundler query = null;
2101    
2102                    if (orderByComparator != null) {
2103                            query = new StringBundler(5 +
2104                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2105                                            (orderByComparator.getOrderByFields().length * 3));
2106                    }
2107                    else {
2108                            query = new StringBundler(4);
2109                    }
2110    
2111                    if (getDB().isSupportsInlineDistinct()) {
2112                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2113                    }
2114                    else {
2115                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2116                    }
2117    
2118                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2119    
2120                    if (!getDB().isSupportsInlineDistinct()) {
2121                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2122                    }
2123    
2124                    if (orderByComparator != null) {
2125                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2126    
2127                            if (orderByConditionFields.length > 0) {
2128                                    query.append(WHERE_AND);
2129                            }
2130    
2131                            for (int i = 0; i < orderByConditionFields.length; i++) {
2132                                    if (getDB().isSupportsInlineDistinct()) {
2133                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2134                                    }
2135                                    else {
2136                                            query.append(_ORDER_BY_ENTITY_TABLE);
2137                                    }
2138    
2139                                    query.append(orderByConditionFields[i]);
2140    
2141                                    if ((i + 1) < orderByConditionFields.length) {
2142                                            if (orderByComparator.isAscending() ^ previous) {
2143                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2144                                            }
2145                                            else {
2146                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2147                                            }
2148                                    }
2149                                    else {
2150                                            if (orderByComparator.isAscending() ^ previous) {
2151                                                    query.append(WHERE_GREATER_THAN);
2152                                            }
2153                                            else {
2154                                                    query.append(WHERE_LESSER_THAN);
2155                                            }
2156                                    }
2157                            }
2158    
2159                            query.append(ORDER_BY_CLAUSE);
2160    
2161                            String[] orderByFields = orderByComparator.getOrderByFields();
2162    
2163                            for (int i = 0; i < orderByFields.length; i++) {
2164                                    if (getDB().isSupportsInlineDistinct()) {
2165                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2166                                    }
2167                                    else {
2168                                            query.append(_ORDER_BY_ENTITY_TABLE);
2169                                    }
2170    
2171                                    query.append(orderByFields[i]);
2172    
2173                                    if ((i + 1) < orderByFields.length) {
2174                                            if (orderByComparator.isAscending() ^ previous) {
2175                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2176                                            }
2177                                            else {
2178                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2179                                            }
2180                                    }
2181                                    else {
2182                                            if (orderByComparator.isAscending() ^ previous) {
2183                                                    query.append(ORDER_BY_ASC);
2184                                            }
2185                                            else {
2186                                                    query.append(ORDER_BY_DESC);
2187                                            }
2188                                    }
2189                            }
2190                    }
2191                    else {
2192                            if (getDB().isSupportsInlineDistinct()) {
2193                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2194                            }
2195                            else {
2196                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2197                            }
2198                    }
2199    
2200                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2201                                    MBMessage.class.getName(),
2202                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2203    
2204                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2205    
2206                    q.setFirstResult(0);
2207                    q.setMaxResults(2);
2208    
2209                    if (getDB().isSupportsInlineDistinct()) {
2210                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2211                    }
2212                    else {
2213                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2214                    }
2215    
2216                    QueryPos qPos = QueryPos.getInstance(q);
2217    
2218                    qPos.add(groupId);
2219    
2220                    if (orderByComparator != null) {
2221                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2222    
2223                            for (Object value : values) {
2224                                    qPos.add(value);
2225                            }
2226                    }
2227    
2228                    List<MBMessage> list = q.list();
2229    
2230                    if (list.size() == 2) {
2231                            return list.get(1);
2232                    }
2233                    else {
2234                            return null;
2235                    }
2236            }
2237    
2238            /**
2239             * Removes all the message-boards messages where groupId = &#63; from the database.
2240             *
2241             * @param groupId the group ID
2242             */
2243            @Override
2244            public void removeByGroupId(long groupId) {
2245                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2246                                    QueryUtil.ALL_POS, null)) {
2247                            remove(mbMessage);
2248                    }
2249            }
2250    
2251            /**
2252             * Returns the number of message-boards messages where groupId = &#63;.
2253             *
2254             * @param groupId the group ID
2255             * @return the number of matching message-boards messages
2256             */
2257            @Override
2258            public int countByGroupId(long groupId) {
2259                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2260    
2261                    Object[] finderArgs = new Object[] { groupId };
2262    
2263                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2264    
2265                    if (count == null) {
2266                            StringBundler query = new StringBundler(2);
2267    
2268                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2269    
2270                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2271    
2272                            String sql = query.toString();
2273    
2274                            Session session = null;
2275    
2276                            try {
2277                                    session = openSession();
2278    
2279                                    Query q = session.createQuery(sql);
2280    
2281                                    QueryPos qPos = QueryPos.getInstance(q);
2282    
2283                                    qPos.add(groupId);
2284    
2285                                    count = (Long)q.uniqueResult();
2286    
2287                                    finderCache.putResult(finderPath, finderArgs, count);
2288                            }
2289                            catch (Exception e) {
2290                                    finderCache.removeResult(finderPath, finderArgs);
2291    
2292                                    throw processException(e);
2293                            }
2294                            finally {
2295                                    closeSession(session);
2296                            }
2297                    }
2298    
2299                    return count.intValue();
2300            }
2301    
2302            /**
2303             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2304             *
2305             * @param groupId the group ID
2306             * @return the number of matching message-boards messages that the user has permission to view
2307             */
2308            @Override
2309            public int filterCountByGroupId(long groupId) {
2310                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2311                            return countByGroupId(groupId);
2312                    }
2313    
2314                    StringBundler query = new StringBundler(2);
2315    
2316                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2317    
2318                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2319    
2320                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2321                                    MBMessage.class.getName(),
2322                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2323    
2324                    Session session = null;
2325    
2326                    try {
2327                            session = openSession();
2328    
2329                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2330    
2331                            q.addScalar(COUNT_COLUMN_NAME,
2332                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2333    
2334                            QueryPos qPos = QueryPos.getInstance(q);
2335    
2336                            qPos.add(groupId);
2337    
2338                            Long count = (Long)q.uniqueResult();
2339    
2340                            return count.intValue();
2341                    }
2342                    catch (Exception e) {
2343                            throw processException(e);
2344                    }
2345                    finally {
2346                            closeSession(session);
2347                    }
2348            }
2349    
2350            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2351            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2352                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2353                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2354                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2355                            new String[] {
2356                                    Long.class.getName(),
2357                                    
2358                            Integer.class.getName(), Integer.class.getName(),
2359                                    OrderByComparator.class.getName()
2360                            });
2361            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2362                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2363                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2364                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2365                            new String[] { Long.class.getName() },
2366                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2367                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2368            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2369                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2370                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2371                            new String[] { Long.class.getName() });
2372    
2373            /**
2374             * Returns all the message-boards messages where companyId = &#63;.
2375             *
2376             * @param companyId the company ID
2377             * @return the matching message-boards messages
2378             */
2379            @Override
2380            public List<MBMessage> findByCompanyId(long companyId) {
2381                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2382                            null);
2383            }
2384    
2385            /**
2386             * Returns a range of all the message-boards messages where companyId = &#63;.
2387             *
2388             * <p>
2389             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2390             * </p>
2391             *
2392             * @param companyId the company ID
2393             * @param start the lower bound of the range of message-boards messages
2394             * @param end the upper bound of the range of message-boards messages (not inclusive)
2395             * @return the range of matching message-boards messages
2396             */
2397            @Override
2398            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2399                    return findByCompanyId(companyId, start, end, null);
2400            }
2401    
2402            /**
2403             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2404             *
2405             * <p>
2406             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2407             * </p>
2408             *
2409             * @param companyId the company ID
2410             * @param start the lower bound of the range of message-boards messages
2411             * @param end the upper bound of the range of message-boards messages (not inclusive)
2412             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2413             * @return the ordered range of matching message-boards messages
2414             */
2415            @Override
2416            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2417                    OrderByComparator<MBMessage> orderByComparator) {
2418                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2419            }
2420    
2421            /**
2422             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2423             *
2424             * <p>
2425             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2426             * </p>
2427             *
2428             * @param companyId the company ID
2429             * @param start the lower bound of the range of message-boards messages
2430             * @param end the upper bound of the range of message-boards messages (not inclusive)
2431             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2432             * @param retrieveFromCache whether to retrieve from the finder cache
2433             * @return the ordered range of matching message-boards messages
2434             */
2435            @Override
2436            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2437                    OrderByComparator<MBMessage> orderByComparator,
2438                    boolean retrieveFromCache) {
2439                    boolean pagination = true;
2440                    FinderPath finderPath = null;
2441                    Object[] finderArgs = null;
2442    
2443                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2444                                    (orderByComparator == null)) {
2445                            pagination = false;
2446                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2447                            finderArgs = new Object[] { companyId };
2448                    }
2449                    else {
2450                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2451                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2452                    }
2453    
2454                    List<MBMessage> list = null;
2455    
2456                    if (retrieveFromCache) {
2457                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2458                                            finderArgs, this);
2459    
2460                            if ((list != null) && !list.isEmpty()) {
2461                                    for (MBMessage mbMessage : list) {
2462                                            if ((companyId != mbMessage.getCompanyId())) {
2463                                                    list = null;
2464    
2465                                                    break;
2466                                            }
2467                                    }
2468                            }
2469                    }
2470    
2471                    if (list == null) {
2472                            StringBundler query = null;
2473    
2474                            if (orderByComparator != null) {
2475                                    query = new StringBundler(3 +
2476                                                    (orderByComparator.getOrderByFields().length * 2));
2477                            }
2478                            else {
2479                                    query = new StringBundler(3);
2480                            }
2481    
2482                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2483    
2484                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2485    
2486                            if (orderByComparator != null) {
2487                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2488                                            orderByComparator);
2489                            }
2490                            else
2491                             if (pagination) {
2492                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2493                            }
2494    
2495                            String sql = query.toString();
2496    
2497                            Session session = null;
2498    
2499                            try {
2500                                    session = openSession();
2501    
2502                                    Query q = session.createQuery(sql);
2503    
2504                                    QueryPos qPos = QueryPos.getInstance(q);
2505    
2506                                    qPos.add(companyId);
2507    
2508                                    if (!pagination) {
2509                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2510                                                            start, end, false);
2511    
2512                                            Collections.sort(list);
2513    
2514                                            list = Collections.unmodifiableList(list);
2515                                    }
2516                                    else {
2517                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2518                                                            start, end);
2519                                    }
2520    
2521                                    cacheResult(list);
2522    
2523                                    finderCache.putResult(finderPath, finderArgs, list);
2524                            }
2525                            catch (Exception e) {
2526                                    finderCache.removeResult(finderPath, finderArgs);
2527    
2528                                    throw processException(e);
2529                            }
2530                            finally {
2531                                    closeSession(session);
2532                            }
2533                    }
2534    
2535                    return list;
2536            }
2537    
2538            /**
2539             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2540             *
2541             * @param companyId the company ID
2542             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2543             * @return the first matching message-boards message
2544             * @throws NoSuchMessageException if a matching message-boards message could not be found
2545             */
2546            @Override
2547            public MBMessage findByCompanyId_First(long companyId,
2548                    OrderByComparator<MBMessage> orderByComparator)
2549                    throws NoSuchMessageException {
2550                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2551                                    orderByComparator);
2552    
2553                    if (mbMessage != null) {
2554                            return mbMessage;
2555                    }
2556    
2557                    StringBundler msg = new StringBundler(4);
2558    
2559                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2560    
2561                    msg.append("companyId=");
2562                    msg.append(companyId);
2563    
2564                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2565    
2566                    throw new NoSuchMessageException(msg.toString());
2567            }
2568    
2569            /**
2570             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2571             *
2572             * @param companyId the company ID
2573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2574             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2575             */
2576            @Override
2577            public MBMessage fetchByCompanyId_First(long companyId,
2578                    OrderByComparator<MBMessage> orderByComparator) {
2579                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2580                                    orderByComparator);
2581    
2582                    if (!list.isEmpty()) {
2583                            return list.get(0);
2584                    }
2585    
2586                    return null;
2587            }
2588    
2589            /**
2590             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2591             *
2592             * @param companyId the company ID
2593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2594             * @return the last matching message-boards message
2595             * @throws NoSuchMessageException if a matching message-boards message could not be found
2596             */
2597            @Override
2598            public MBMessage findByCompanyId_Last(long companyId,
2599                    OrderByComparator<MBMessage> orderByComparator)
2600                    throws NoSuchMessageException {
2601                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2602    
2603                    if (mbMessage != null) {
2604                            return mbMessage;
2605                    }
2606    
2607                    StringBundler msg = new StringBundler(4);
2608    
2609                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2610    
2611                    msg.append("companyId=");
2612                    msg.append(companyId);
2613    
2614                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2615    
2616                    throw new NoSuchMessageException(msg.toString());
2617            }
2618    
2619            /**
2620             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2621             *
2622             * @param companyId the company ID
2623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2624             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2625             */
2626            @Override
2627            public MBMessage fetchByCompanyId_Last(long companyId,
2628                    OrderByComparator<MBMessage> orderByComparator) {
2629                    int count = countByCompanyId(companyId);
2630    
2631                    if (count == 0) {
2632                            return null;
2633                    }
2634    
2635                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2636                                    orderByComparator);
2637    
2638                    if (!list.isEmpty()) {
2639                            return list.get(0);
2640                    }
2641    
2642                    return null;
2643            }
2644    
2645            /**
2646             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2647             *
2648             * @param messageId the primary key of the current message-boards message
2649             * @param companyId the company ID
2650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2651             * @return the previous, current, and next message-boards message
2652             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2653             */
2654            @Override
2655            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2656                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2657                    throws NoSuchMessageException {
2658                    MBMessage mbMessage = findByPrimaryKey(messageId);
2659    
2660                    Session session = null;
2661    
2662                    try {
2663                            session = openSession();
2664    
2665                            MBMessage[] array = new MBMessageImpl[3];
2666    
2667                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2668                                            companyId, orderByComparator, true);
2669    
2670                            array[1] = mbMessage;
2671    
2672                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2673                                            companyId, orderByComparator, false);
2674    
2675                            return array;
2676                    }
2677                    catch (Exception e) {
2678                            throw processException(e);
2679                    }
2680                    finally {
2681                            closeSession(session);
2682                    }
2683            }
2684    
2685            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2686                    MBMessage mbMessage, long companyId,
2687                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2688                    StringBundler query = null;
2689    
2690                    if (orderByComparator != null) {
2691                            query = new StringBundler(4 +
2692                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2693                                            (orderByComparator.getOrderByFields().length * 3));
2694                    }
2695                    else {
2696                            query = new StringBundler(3);
2697                    }
2698    
2699                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2700    
2701                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2702    
2703                    if (orderByComparator != null) {
2704                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2705    
2706                            if (orderByConditionFields.length > 0) {
2707                                    query.append(WHERE_AND);
2708                            }
2709    
2710                            for (int i = 0; i < orderByConditionFields.length; i++) {
2711                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2712                                    query.append(orderByConditionFields[i]);
2713    
2714                                    if ((i + 1) < orderByConditionFields.length) {
2715                                            if (orderByComparator.isAscending() ^ previous) {
2716                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2717                                            }
2718                                            else {
2719                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2720                                            }
2721                                    }
2722                                    else {
2723                                            if (orderByComparator.isAscending() ^ previous) {
2724                                                    query.append(WHERE_GREATER_THAN);
2725                                            }
2726                                            else {
2727                                                    query.append(WHERE_LESSER_THAN);
2728                                            }
2729                                    }
2730                            }
2731    
2732                            query.append(ORDER_BY_CLAUSE);
2733    
2734                            String[] orderByFields = orderByComparator.getOrderByFields();
2735    
2736                            for (int i = 0; i < orderByFields.length; i++) {
2737                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2738                                    query.append(orderByFields[i]);
2739    
2740                                    if ((i + 1) < orderByFields.length) {
2741                                            if (orderByComparator.isAscending() ^ previous) {
2742                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2743                                            }
2744                                            else {
2745                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2746                                            }
2747                                    }
2748                                    else {
2749                                            if (orderByComparator.isAscending() ^ previous) {
2750                                                    query.append(ORDER_BY_ASC);
2751                                            }
2752                                            else {
2753                                                    query.append(ORDER_BY_DESC);
2754                                            }
2755                                    }
2756                            }
2757                    }
2758                    else {
2759                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2760                    }
2761    
2762                    String sql = query.toString();
2763    
2764                    Query q = session.createQuery(sql);
2765    
2766                    q.setFirstResult(0);
2767                    q.setMaxResults(2);
2768    
2769                    QueryPos qPos = QueryPos.getInstance(q);
2770    
2771                    qPos.add(companyId);
2772    
2773                    if (orderByComparator != null) {
2774                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2775    
2776                            for (Object value : values) {
2777                                    qPos.add(value);
2778                            }
2779                    }
2780    
2781                    List<MBMessage> list = q.list();
2782    
2783                    if (list.size() == 2) {
2784                            return list.get(1);
2785                    }
2786                    else {
2787                            return null;
2788                    }
2789            }
2790    
2791            /**
2792             * Removes all the message-boards messages where companyId = &#63; from the database.
2793             *
2794             * @param companyId the company ID
2795             */
2796            @Override
2797            public void removeByCompanyId(long companyId) {
2798                    for (MBMessage mbMessage : findByCompanyId(companyId,
2799                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2800                            remove(mbMessage);
2801                    }
2802            }
2803    
2804            /**
2805             * Returns the number of message-boards messages where companyId = &#63;.
2806             *
2807             * @param companyId the company ID
2808             * @return the number of matching message-boards messages
2809             */
2810            @Override
2811            public int countByCompanyId(long companyId) {
2812                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2813    
2814                    Object[] finderArgs = new Object[] { companyId };
2815    
2816                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2817    
2818                    if (count == null) {
2819                            StringBundler query = new StringBundler(2);
2820    
2821                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2822    
2823                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2824    
2825                            String sql = query.toString();
2826    
2827                            Session session = null;
2828    
2829                            try {
2830                                    session = openSession();
2831    
2832                                    Query q = session.createQuery(sql);
2833    
2834                                    QueryPos qPos = QueryPos.getInstance(q);
2835    
2836                                    qPos.add(companyId);
2837    
2838                                    count = (Long)q.uniqueResult();
2839    
2840                                    finderCache.putResult(finderPath, finderArgs, count);
2841                            }
2842                            catch (Exception e) {
2843                                    finderCache.removeResult(finderPath, finderArgs);
2844    
2845                                    throw processException(e);
2846                            }
2847                            finally {
2848                                    closeSession(session);
2849                            }
2850                    }
2851    
2852                    return count.intValue();
2853            }
2854    
2855            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2856            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2857                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2858                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2859                            new String[] {
2860                                    Long.class.getName(),
2861                                    
2862                            Integer.class.getName(), Integer.class.getName(),
2863                                    OrderByComparator.class.getName()
2864                            });
2865            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2866                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2867                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2868                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2869                            new String[] { Long.class.getName() },
2870                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2871                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2872            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2873                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2874                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2875                            new String[] { Long.class.getName() });
2876    
2877            /**
2878             * Returns all the message-boards messages where userId = &#63;.
2879             *
2880             * @param userId the user ID
2881             * @return the matching message-boards messages
2882             */
2883            @Override
2884            public List<MBMessage> findByUserId(long userId) {
2885                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2886            }
2887    
2888            /**
2889             * Returns a range of all the message-boards messages where userId = &#63;.
2890             *
2891             * <p>
2892             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2893             * </p>
2894             *
2895             * @param userId the user ID
2896             * @param start the lower bound of the range of message-boards messages
2897             * @param end the upper bound of the range of message-boards messages (not inclusive)
2898             * @return the range of matching message-boards messages
2899             */
2900            @Override
2901            public List<MBMessage> findByUserId(long userId, int start, int end) {
2902                    return findByUserId(userId, start, end, null);
2903            }
2904    
2905            /**
2906             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2907             *
2908             * <p>
2909             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2910             * </p>
2911             *
2912             * @param userId the user ID
2913             * @param start the lower bound of the range of message-boards messages
2914             * @param end the upper bound of the range of message-boards messages (not inclusive)
2915             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2916             * @return the ordered range of matching message-boards messages
2917             */
2918            @Override
2919            public List<MBMessage> findByUserId(long userId, int start, int end,
2920                    OrderByComparator<MBMessage> orderByComparator) {
2921                    return findByUserId(userId, start, end, orderByComparator, true);
2922            }
2923    
2924            /**
2925             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2926             *
2927             * <p>
2928             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2929             * </p>
2930             *
2931             * @param userId the user ID
2932             * @param start the lower bound of the range of message-boards messages
2933             * @param end the upper bound of the range of message-boards messages (not inclusive)
2934             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2935             * @param retrieveFromCache whether to retrieve from the finder cache
2936             * @return the ordered range of matching message-boards messages
2937             */
2938            @Override
2939            public List<MBMessage> findByUserId(long userId, int start, int end,
2940                    OrderByComparator<MBMessage> orderByComparator,
2941                    boolean retrieveFromCache) {
2942                    boolean pagination = true;
2943                    FinderPath finderPath = null;
2944                    Object[] finderArgs = null;
2945    
2946                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2947                                    (orderByComparator == null)) {
2948                            pagination = false;
2949                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2950                            finderArgs = new Object[] { userId };
2951                    }
2952                    else {
2953                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2954                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2955                    }
2956    
2957                    List<MBMessage> list = null;
2958    
2959                    if (retrieveFromCache) {
2960                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2961                                            finderArgs, this);
2962    
2963                            if ((list != null) && !list.isEmpty()) {
2964                                    for (MBMessage mbMessage : list) {
2965                                            if ((userId != mbMessage.getUserId())) {
2966                                                    list = null;
2967    
2968                                                    break;
2969                                            }
2970                                    }
2971                            }
2972                    }
2973    
2974                    if (list == null) {
2975                            StringBundler query = null;
2976    
2977                            if (orderByComparator != null) {
2978                                    query = new StringBundler(3 +
2979                                                    (orderByComparator.getOrderByFields().length * 2));
2980                            }
2981                            else {
2982                                    query = new StringBundler(3);
2983                            }
2984    
2985                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2986    
2987                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2988    
2989                            if (orderByComparator != null) {
2990                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2991                                            orderByComparator);
2992                            }
2993                            else
2994                             if (pagination) {
2995                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2996                            }
2997    
2998                            String sql = query.toString();
2999    
3000                            Session session = null;
3001    
3002                            try {
3003                                    session = openSession();
3004    
3005                                    Query q = session.createQuery(sql);
3006    
3007                                    QueryPos qPos = QueryPos.getInstance(q);
3008    
3009                                    qPos.add(userId);
3010    
3011                                    if (!pagination) {
3012                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3013                                                            start, end, false);
3014    
3015                                            Collections.sort(list);
3016    
3017                                            list = Collections.unmodifiableList(list);
3018                                    }
3019                                    else {
3020                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3021                                                            start, end);
3022                                    }
3023    
3024                                    cacheResult(list);
3025    
3026                                    finderCache.putResult(finderPath, finderArgs, list);
3027                            }
3028                            catch (Exception e) {
3029                                    finderCache.removeResult(finderPath, finderArgs);
3030    
3031                                    throw processException(e);
3032                            }
3033                            finally {
3034                                    closeSession(session);
3035                            }
3036                    }
3037    
3038                    return list;
3039            }
3040    
3041            /**
3042             * Returns the first message-boards message in the ordered set where userId = &#63;.
3043             *
3044             * @param userId the user ID
3045             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3046             * @return the first matching message-boards message
3047             * @throws NoSuchMessageException if a matching message-boards message could not be found
3048             */
3049            @Override
3050            public MBMessage findByUserId_First(long userId,
3051                    OrderByComparator<MBMessage> orderByComparator)
3052                    throws NoSuchMessageException {
3053                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3054    
3055                    if (mbMessage != null) {
3056                            return mbMessage;
3057                    }
3058    
3059                    StringBundler msg = new StringBundler(4);
3060    
3061                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3062    
3063                    msg.append("userId=");
3064                    msg.append(userId);
3065    
3066                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3067    
3068                    throw new NoSuchMessageException(msg.toString());
3069            }
3070    
3071            /**
3072             * Returns the first message-boards message in the ordered set where userId = &#63;.
3073             *
3074             * @param userId the user ID
3075             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3076             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3077             */
3078            @Override
3079            public MBMessage fetchByUserId_First(long userId,
3080                    OrderByComparator<MBMessage> orderByComparator) {
3081                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3082    
3083                    if (!list.isEmpty()) {
3084                            return list.get(0);
3085                    }
3086    
3087                    return null;
3088            }
3089    
3090            /**
3091             * Returns the last message-boards message in the ordered set where userId = &#63;.
3092             *
3093             * @param userId the user ID
3094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3095             * @return the last matching message-boards message
3096             * @throws NoSuchMessageException if a matching message-boards message could not be found
3097             */
3098            @Override
3099            public MBMessage findByUserId_Last(long userId,
3100                    OrderByComparator<MBMessage> orderByComparator)
3101                    throws NoSuchMessageException {
3102                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3103    
3104                    if (mbMessage != null) {
3105                            return mbMessage;
3106                    }
3107    
3108                    StringBundler msg = new StringBundler(4);
3109    
3110                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3111    
3112                    msg.append("userId=");
3113                    msg.append(userId);
3114    
3115                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3116    
3117                    throw new NoSuchMessageException(msg.toString());
3118            }
3119    
3120            /**
3121             * Returns the last message-boards message in the ordered set where userId = &#63;.
3122             *
3123             * @param userId the user ID
3124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3125             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3126             */
3127            @Override
3128            public MBMessage fetchByUserId_Last(long userId,
3129                    OrderByComparator<MBMessage> orderByComparator) {
3130                    int count = countByUserId(userId);
3131    
3132                    if (count == 0) {
3133                            return null;
3134                    }
3135    
3136                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3137                                    orderByComparator);
3138    
3139                    if (!list.isEmpty()) {
3140                            return list.get(0);
3141                    }
3142    
3143                    return null;
3144            }
3145    
3146            /**
3147             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3148             *
3149             * @param messageId the primary key of the current message-boards message
3150             * @param userId the user ID
3151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3152             * @return the previous, current, and next message-boards message
3153             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3154             */
3155            @Override
3156            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3157                    OrderByComparator<MBMessage> orderByComparator)
3158                    throws NoSuchMessageException {
3159                    MBMessage mbMessage = findByPrimaryKey(messageId);
3160    
3161                    Session session = null;
3162    
3163                    try {
3164                            session = openSession();
3165    
3166                            MBMessage[] array = new MBMessageImpl[3];
3167    
3168                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3169                                            orderByComparator, true);
3170    
3171                            array[1] = mbMessage;
3172    
3173                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3174                                            orderByComparator, false);
3175    
3176                            return array;
3177                    }
3178                    catch (Exception e) {
3179                            throw processException(e);
3180                    }
3181                    finally {
3182                            closeSession(session);
3183                    }
3184            }
3185    
3186            protected MBMessage getByUserId_PrevAndNext(Session session,
3187                    MBMessage mbMessage, long userId,
3188                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3189                    StringBundler query = null;
3190    
3191                    if (orderByComparator != null) {
3192                            query = new StringBundler(4 +
3193                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3194                                            (orderByComparator.getOrderByFields().length * 3));
3195                    }
3196                    else {
3197                            query = new StringBundler(3);
3198                    }
3199    
3200                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3201    
3202                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3203    
3204                    if (orderByComparator != null) {
3205                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3206    
3207                            if (orderByConditionFields.length > 0) {
3208                                    query.append(WHERE_AND);
3209                            }
3210    
3211                            for (int i = 0; i < orderByConditionFields.length; i++) {
3212                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3213                                    query.append(orderByConditionFields[i]);
3214    
3215                                    if ((i + 1) < orderByConditionFields.length) {
3216                                            if (orderByComparator.isAscending() ^ previous) {
3217                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3218                                            }
3219                                            else {
3220                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3221                                            }
3222                                    }
3223                                    else {
3224                                            if (orderByComparator.isAscending() ^ previous) {
3225                                                    query.append(WHERE_GREATER_THAN);
3226                                            }
3227                                            else {
3228                                                    query.append(WHERE_LESSER_THAN);
3229                                            }
3230                                    }
3231                            }
3232    
3233                            query.append(ORDER_BY_CLAUSE);
3234    
3235                            String[] orderByFields = orderByComparator.getOrderByFields();
3236    
3237                            for (int i = 0; i < orderByFields.length; i++) {
3238                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3239                                    query.append(orderByFields[i]);
3240    
3241                                    if ((i + 1) < orderByFields.length) {
3242                                            if (orderByComparator.isAscending() ^ previous) {
3243                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3244                                            }
3245                                            else {
3246                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3247                                            }
3248                                    }
3249                                    else {
3250                                            if (orderByComparator.isAscending() ^ previous) {
3251                                                    query.append(ORDER_BY_ASC);
3252                                            }
3253                                            else {
3254                                                    query.append(ORDER_BY_DESC);
3255                                            }
3256                                    }
3257                            }
3258                    }
3259                    else {
3260                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3261                    }
3262    
3263                    String sql = query.toString();
3264    
3265                    Query q = session.createQuery(sql);
3266    
3267                    q.setFirstResult(0);
3268                    q.setMaxResults(2);
3269    
3270                    QueryPos qPos = QueryPos.getInstance(q);
3271    
3272                    qPos.add(userId);
3273    
3274                    if (orderByComparator != null) {
3275                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3276    
3277                            for (Object value : values) {
3278                                    qPos.add(value);
3279                            }
3280                    }
3281    
3282                    List<MBMessage> list = q.list();
3283    
3284                    if (list.size() == 2) {
3285                            return list.get(1);
3286                    }
3287                    else {
3288                            return null;
3289                    }
3290            }
3291    
3292            /**
3293             * Removes all the message-boards messages where userId = &#63; from the database.
3294             *
3295             * @param userId the user ID
3296             */
3297            @Override
3298            public void removeByUserId(long userId) {
3299                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3300                                    QueryUtil.ALL_POS, null)) {
3301                            remove(mbMessage);
3302                    }
3303            }
3304    
3305            /**
3306             * Returns the number of message-boards messages where userId = &#63;.
3307             *
3308             * @param userId the user ID
3309             * @return the number of matching message-boards messages
3310             */
3311            @Override
3312            public int countByUserId(long userId) {
3313                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3314    
3315                    Object[] finderArgs = new Object[] { userId };
3316    
3317                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3318    
3319                    if (count == null) {
3320                            StringBundler query = new StringBundler(2);
3321    
3322                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3323    
3324                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3325    
3326                            String sql = query.toString();
3327    
3328                            Session session = null;
3329    
3330                            try {
3331                                    session = openSession();
3332    
3333                                    Query q = session.createQuery(sql);
3334    
3335                                    QueryPos qPos = QueryPos.getInstance(q);
3336    
3337                                    qPos.add(userId);
3338    
3339                                    count = (Long)q.uniqueResult();
3340    
3341                                    finderCache.putResult(finderPath, finderArgs, count);
3342                            }
3343                            catch (Exception e) {
3344                                    finderCache.removeResult(finderPath, finderArgs);
3345    
3346                                    throw processException(e);
3347                            }
3348                            finally {
3349                                    closeSession(session);
3350                            }
3351                    }
3352    
3353                    return count.intValue();
3354            }
3355    
3356            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3357            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3358                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3359                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3360                            new String[] {
3361                                    Long.class.getName(),
3362                                    
3363                            Integer.class.getName(), Integer.class.getName(),
3364                                    OrderByComparator.class.getName()
3365                            });
3366            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3367                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3368                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3369                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3370                            new String[] { Long.class.getName() },
3371                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3372                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3373            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3374                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3375                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3376                            new String[] { Long.class.getName() });
3377    
3378            /**
3379             * Returns all the message-boards messages where threadId = &#63;.
3380             *
3381             * @param threadId the thread ID
3382             * @return the matching message-boards messages
3383             */
3384            @Override
3385            public List<MBMessage> findByThreadId(long threadId) {
3386                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3387                            null);
3388            }
3389    
3390            /**
3391             * Returns a range of all the message-boards messages where threadId = &#63;.
3392             *
3393             * <p>
3394             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3395             * </p>
3396             *
3397             * @param threadId the thread ID
3398             * @param start the lower bound of the range of message-boards messages
3399             * @param end the upper bound of the range of message-boards messages (not inclusive)
3400             * @return the range of matching message-boards messages
3401             */
3402            @Override
3403            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3404                    return findByThreadId(threadId, start, end, null);
3405            }
3406    
3407            /**
3408             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3409             *
3410             * <p>
3411             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3412             * </p>
3413             *
3414             * @param threadId the thread ID
3415             * @param start the lower bound of the range of message-boards messages
3416             * @param end the upper bound of the range of message-boards messages (not inclusive)
3417             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3418             * @return the ordered range of matching message-boards messages
3419             */
3420            @Override
3421            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3422                    OrderByComparator<MBMessage> orderByComparator) {
3423                    return findByThreadId(threadId, start, end, orderByComparator, true);
3424            }
3425    
3426            /**
3427             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3428             *
3429             * <p>
3430             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3431             * </p>
3432             *
3433             * @param threadId the thread ID
3434             * @param start the lower bound of the range of message-boards messages
3435             * @param end the upper bound of the range of message-boards messages (not inclusive)
3436             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3437             * @param retrieveFromCache whether to retrieve from the finder cache
3438             * @return the ordered range of matching message-boards messages
3439             */
3440            @Override
3441            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3442                    OrderByComparator<MBMessage> orderByComparator,
3443                    boolean retrieveFromCache) {
3444                    boolean pagination = true;
3445                    FinderPath finderPath = null;
3446                    Object[] finderArgs = null;
3447    
3448                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3449                                    (orderByComparator == null)) {
3450                            pagination = false;
3451                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3452                            finderArgs = new Object[] { threadId };
3453                    }
3454                    else {
3455                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3456                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3457                    }
3458    
3459                    List<MBMessage> list = null;
3460    
3461                    if (retrieveFromCache) {
3462                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3463                                            finderArgs, this);
3464    
3465                            if ((list != null) && !list.isEmpty()) {
3466                                    for (MBMessage mbMessage : list) {
3467                                            if ((threadId != mbMessage.getThreadId())) {
3468                                                    list = null;
3469    
3470                                                    break;
3471                                            }
3472                                    }
3473                            }
3474                    }
3475    
3476                    if (list == null) {
3477                            StringBundler query = null;
3478    
3479                            if (orderByComparator != null) {
3480                                    query = new StringBundler(3 +
3481                                                    (orderByComparator.getOrderByFields().length * 2));
3482                            }
3483                            else {
3484                                    query = new StringBundler(3);
3485                            }
3486    
3487                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3488    
3489                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3490    
3491                            if (orderByComparator != null) {
3492                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3493                                            orderByComparator);
3494                            }
3495                            else
3496                             if (pagination) {
3497                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3498                            }
3499    
3500                            String sql = query.toString();
3501    
3502                            Session session = null;
3503    
3504                            try {
3505                                    session = openSession();
3506    
3507                                    Query q = session.createQuery(sql);
3508    
3509                                    QueryPos qPos = QueryPos.getInstance(q);
3510    
3511                                    qPos.add(threadId);
3512    
3513                                    if (!pagination) {
3514                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3515                                                            start, end, false);
3516    
3517                                            Collections.sort(list);
3518    
3519                                            list = Collections.unmodifiableList(list);
3520                                    }
3521                                    else {
3522                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3523                                                            start, end);
3524                                    }
3525    
3526                                    cacheResult(list);
3527    
3528                                    finderCache.putResult(finderPath, finderArgs, list);
3529                            }
3530                            catch (Exception e) {
3531                                    finderCache.removeResult(finderPath, finderArgs);
3532    
3533                                    throw processException(e);
3534                            }
3535                            finally {
3536                                    closeSession(session);
3537                            }
3538                    }
3539    
3540                    return list;
3541            }
3542    
3543            /**
3544             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3545             *
3546             * @param threadId the thread ID
3547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3548             * @return the first matching message-boards message
3549             * @throws NoSuchMessageException if a matching message-boards message could not be found
3550             */
3551            @Override
3552            public MBMessage findByThreadId_First(long threadId,
3553                    OrderByComparator<MBMessage> orderByComparator)
3554                    throws NoSuchMessageException {
3555                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3556    
3557                    if (mbMessage != null) {
3558                            return mbMessage;
3559                    }
3560    
3561                    StringBundler msg = new StringBundler(4);
3562    
3563                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3564    
3565                    msg.append("threadId=");
3566                    msg.append(threadId);
3567    
3568                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3569    
3570                    throw new NoSuchMessageException(msg.toString());
3571            }
3572    
3573            /**
3574             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3575             *
3576             * @param threadId the thread ID
3577             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3578             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3579             */
3580            @Override
3581            public MBMessage fetchByThreadId_First(long threadId,
3582                    OrderByComparator<MBMessage> orderByComparator) {
3583                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3584    
3585                    if (!list.isEmpty()) {
3586                            return list.get(0);
3587                    }
3588    
3589                    return null;
3590            }
3591    
3592            /**
3593             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3594             *
3595             * @param threadId the thread ID
3596             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3597             * @return the last matching message-boards message
3598             * @throws NoSuchMessageException if a matching message-boards message could not be found
3599             */
3600            @Override
3601            public MBMessage findByThreadId_Last(long threadId,
3602                    OrderByComparator<MBMessage> orderByComparator)
3603                    throws NoSuchMessageException {
3604                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3605    
3606                    if (mbMessage != null) {
3607                            return mbMessage;
3608                    }
3609    
3610                    StringBundler msg = new StringBundler(4);
3611    
3612                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3613    
3614                    msg.append("threadId=");
3615                    msg.append(threadId);
3616    
3617                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3618    
3619                    throw new NoSuchMessageException(msg.toString());
3620            }
3621    
3622            /**
3623             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3624             *
3625             * @param threadId the thread ID
3626             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3627             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3628             */
3629            @Override
3630            public MBMessage fetchByThreadId_Last(long threadId,
3631                    OrderByComparator<MBMessage> orderByComparator) {
3632                    int count = countByThreadId(threadId);
3633    
3634                    if (count == 0) {
3635                            return null;
3636                    }
3637    
3638                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3639                                    orderByComparator);
3640    
3641                    if (!list.isEmpty()) {
3642                            return list.get(0);
3643                    }
3644    
3645                    return null;
3646            }
3647    
3648            /**
3649             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3650             *
3651             * @param messageId the primary key of the current message-boards message
3652             * @param threadId the thread ID
3653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3654             * @return the previous, current, and next message-boards message
3655             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3656             */
3657            @Override
3658            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3659                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3660                    throws NoSuchMessageException {
3661                    MBMessage mbMessage = findByPrimaryKey(messageId);
3662    
3663                    Session session = null;
3664    
3665                    try {
3666                            session = openSession();
3667    
3668                            MBMessage[] array = new MBMessageImpl[3];
3669    
3670                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3671                                            orderByComparator, true);
3672    
3673                            array[1] = mbMessage;
3674    
3675                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3676                                            orderByComparator, false);
3677    
3678                            return array;
3679                    }
3680                    catch (Exception e) {
3681                            throw processException(e);
3682                    }
3683                    finally {
3684                            closeSession(session);
3685                    }
3686            }
3687    
3688            protected MBMessage getByThreadId_PrevAndNext(Session session,
3689                    MBMessage mbMessage, long threadId,
3690                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3691                    StringBundler query = null;
3692    
3693                    if (orderByComparator != null) {
3694                            query = new StringBundler(4 +
3695                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3696                                            (orderByComparator.getOrderByFields().length * 3));
3697                    }
3698                    else {
3699                            query = new StringBundler(3);
3700                    }
3701    
3702                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3703    
3704                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3705    
3706                    if (orderByComparator != null) {
3707                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3708    
3709                            if (orderByConditionFields.length > 0) {
3710                                    query.append(WHERE_AND);
3711                            }
3712    
3713                            for (int i = 0; i < orderByConditionFields.length; i++) {
3714                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3715                                    query.append(orderByConditionFields[i]);
3716    
3717                                    if ((i + 1) < orderByConditionFields.length) {
3718                                            if (orderByComparator.isAscending() ^ previous) {
3719                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3720                                            }
3721                                            else {
3722                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3723                                            }
3724                                    }
3725                                    else {
3726                                            if (orderByComparator.isAscending() ^ previous) {
3727                                                    query.append(WHERE_GREATER_THAN);
3728                                            }
3729                                            else {
3730                                                    query.append(WHERE_LESSER_THAN);
3731                                            }
3732                                    }
3733                            }
3734    
3735                            query.append(ORDER_BY_CLAUSE);
3736    
3737                            String[] orderByFields = orderByComparator.getOrderByFields();
3738    
3739                            for (int i = 0; i < orderByFields.length; i++) {
3740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3741                                    query.append(orderByFields[i]);
3742    
3743                                    if ((i + 1) < orderByFields.length) {
3744                                            if (orderByComparator.isAscending() ^ previous) {
3745                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3746                                            }
3747                                            else {
3748                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3749                                            }
3750                                    }
3751                                    else {
3752                                            if (orderByComparator.isAscending() ^ previous) {
3753                                                    query.append(ORDER_BY_ASC);
3754                                            }
3755                                            else {
3756                                                    query.append(ORDER_BY_DESC);
3757                                            }
3758                                    }
3759                            }
3760                    }
3761                    else {
3762                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3763                    }
3764    
3765                    String sql = query.toString();
3766    
3767                    Query q = session.createQuery(sql);
3768    
3769                    q.setFirstResult(0);
3770                    q.setMaxResults(2);
3771    
3772                    QueryPos qPos = QueryPos.getInstance(q);
3773    
3774                    qPos.add(threadId);
3775    
3776                    if (orderByComparator != null) {
3777                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3778    
3779                            for (Object value : values) {
3780                                    qPos.add(value);
3781                            }
3782                    }
3783    
3784                    List<MBMessage> list = q.list();
3785    
3786                    if (list.size() == 2) {
3787                            return list.get(1);
3788                    }
3789                    else {
3790                            return null;
3791                    }
3792            }
3793    
3794            /**
3795             * Removes all the message-boards messages where threadId = &#63; from the database.
3796             *
3797             * @param threadId the thread ID
3798             */
3799            @Override
3800            public void removeByThreadId(long threadId) {
3801                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3802                                    QueryUtil.ALL_POS, null)) {
3803                            remove(mbMessage);
3804                    }
3805            }
3806    
3807            /**
3808             * Returns the number of message-boards messages where threadId = &#63;.
3809             *
3810             * @param threadId the thread ID
3811             * @return the number of matching message-boards messages
3812             */
3813            @Override
3814            public int countByThreadId(long threadId) {
3815                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3816    
3817                    Object[] finderArgs = new Object[] { threadId };
3818    
3819                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3820    
3821                    if (count == null) {
3822                            StringBundler query = new StringBundler(2);
3823    
3824                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3825    
3826                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3827    
3828                            String sql = query.toString();
3829    
3830                            Session session = null;
3831    
3832                            try {
3833                                    session = openSession();
3834    
3835                                    Query q = session.createQuery(sql);
3836    
3837                                    QueryPos qPos = QueryPos.getInstance(q);
3838    
3839                                    qPos.add(threadId);
3840    
3841                                    count = (Long)q.uniqueResult();
3842    
3843                                    finderCache.putResult(finderPath, finderArgs, count);
3844                            }
3845                            catch (Exception e) {
3846                                    finderCache.removeResult(finderPath, finderArgs);
3847    
3848                                    throw processException(e);
3849                            }
3850                            finally {
3851                                    closeSession(session);
3852                            }
3853                    }
3854    
3855                    return count.intValue();
3856            }
3857    
3858            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3859            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3860                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3861                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3862                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3863                            new String[] {
3864                                    Long.class.getName(),
3865                                    
3866                            Integer.class.getName(), Integer.class.getName(),
3867                                    OrderByComparator.class.getName()
3868                            });
3869            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3870                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3871                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3872                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3873                            new String[] { Long.class.getName() },
3874                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3875                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3876            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3877                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3878                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3879                            new String[] { Long.class.getName() });
3880    
3881            /**
3882             * Returns all the message-boards messages where threadId = &#63;.
3883             *
3884             * @param threadId the thread ID
3885             * @return the matching message-boards messages
3886             */
3887            @Override
3888            public List<MBMessage> findByThreadReplies(long threadId) {
3889                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3890                            QueryUtil.ALL_POS, null);
3891            }
3892    
3893            /**
3894             * Returns a range of all the message-boards messages where threadId = &#63;.
3895             *
3896             * <p>
3897             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3898             * </p>
3899             *
3900             * @param threadId the thread ID
3901             * @param start the lower bound of the range of message-boards messages
3902             * @param end the upper bound of the range of message-boards messages (not inclusive)
3903             * @return the range of matching message-boards messages
3904             */
3905            @Override
3906            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3907                    return findByThreadReplies(threadId, start, end, null);
3908            }
3909    
3910            /**
3911             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3912             *
3913             * <p>
3914             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3915             * </p>
3916             *
3917             * @param threadId the thread ID
3918             * @param start the lower bound of the range of message-boards messages
3919             * @param end the upper bound of the range of message-boards messages (not inclusive)
3920             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3921             * @return the ordered range of matching message-boards messages
3922             */
3923            @Override
3924            public List<MBMessage> findByThreadReplies(long threadId, int start,
3925                    int end, OrderByComparator<MBMessage> orderByComparator) {
3926                    return findByThreadReplies(threadId, start, end, orderByComparator, true);
3927            }
3928    
3929            /**
3930             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3931             *
3932             * <p>
3933             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3934             * </p>
3935             *
3936             * @param threadId the thread ID
3937             * @param start the lower bound of the range of message-boards messages
3938             * @param end the upper bound of the range of message-boards messages (not inclusive)
3939             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3940             * @param retrieveFromCache whether to retrieve from the finder cache
3941             * @return the ordered range of matching message-boards messages
3942             */
3943            @Override
3944            public List<MBMessage> findByThreadReplies(long threadId, int start,
3945                    int end, OrderByComparator<MBMessage> orderByComparator,
3946                    boolean retrieveFromCache) {
3947                    boolean pagination = true;
3948                    FinderPath finderPath = null;
3949                    Object[] finderArgs = null;
3950    
3951                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3952                                    (orderByComparator == null)) {
3953                            pagination = false;
3954                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3955                            finderArgs = new Object[] { threadId };
3956                    }
3957                    else {
3958                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3959                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3960                    }
3961    
3962                    List<MBMessage> list = null;
3963    
3964                    if (retrieveFromCache) {
3965                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3966                                            finderArgs, this);
3967    
3968                            if ((list != null) && !list.isEmpty()) {
3969                                    for (MBMessage mbMessage : list) {
3970                                            if ((threadId != mbMessage.getThreadId())) {
3971                                                    list = null;
3972    
3973                                                    break;
3974                                            }
3975                                    }
3976                            }
3977                    }
3978    
3979                    if (list == null) {
3980                            StringBundler query = null;
3981    
3982                            if (orderByComparator != null) {
3983                                    query = new StringBundler(3 +
3984                                                    (orderByComparator.getOrderByFields().length * 2));
3985                            }
3986                            else {
3987                                    query = new StringBundler(3);
3988                            }
3989    
3990                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3991    
3992                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3993    
3994                            if (orderByComparator != null) {
3995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3996                                            orderByComparator);
3997                            }
3998                            else
3999                             if (pagination) {
4000                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4001                            }
4002    
4003                            String sql = query.toString();
4004    
4005                            Session session = null;
4006    
4007                            try {
4008                                    session = openSession();
4009    
4010                                    Query q = session.createQuery(sql);
4011    
4012                                    QueryPos qPos = QueryPos.getInstance(q);
4013    
4014                                    qPos.add(threadId);
4015    
4016                                    if (!pagination) {
4017                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4018                                                            start, end, false);
4019    
4020                                            Collections.sort(list);
4021    
4022                                            list = Collections.unmodifiableList(list);
4023                                    }
4024                                    else {
4025                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4026                                                            start, end);
4027                                    }
4028    
4029                                    cacheResult(list);
4030    
4031                                    finderCache.putResult(finderPath, finderArgs, list);
4032                            }
4033                            catch (Exception e) {
4034                                    finderCache.removeResult(finderPath, finderArgs);
4035    
4036                                    throw processException(e);
4037                            }
4038                            finally {
4039                                    closeSession(session);
4040                            }
4041                    }
4042    
4043                    return list;
4044            }
4045    
4046            /**
4047             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4048             *
4049             * @param threadId the thread ID
4050             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4051             * @return the first matching message-boards message
4052             * @throws NoSuchMessageException if a matching message-boards message could not be found
4053             */
4054            @Override
4055            public MBMessage findByThreadReplies_First(long threadId,
4056                    OrderByComparator<MBMessage> orderByComparator)
4057                    throws NoSuchMessageException {
4058                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4059                                    orderByComparator);
4060    
4061                    if (mbMessage != null) {
4062                            return mbMessage;
4063                    }
4064    
4065                    StringBundler msg = new StringBundler(4);
4066    
4067                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4068    
4069                    msg.append("threadId=");
4070                    msg.append(threadId);
4071    
4072                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4073    
4074                    throw new NoSuchMessageException(msg.toString());
4075            }
4076    
4077            /**
4078             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4079             *
4080             * @param threadId the thread ID
4081             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4082             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4083             */
4084            @Override
4085            public MBMessage fetchByThreadReplies_First(long threadId,
4086                    OrderByComparator<MBMessage> orderByComparator) {
4087                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4088                                    orderByComparator);
4089    
4090                    if (!list.isEmpty()) {
4091                            return list.get(0);
4092                    }
4093    
4094                    return null;
4095            }
4096    
4097            /**
4098             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4099             *
4100             * @param threadId the thread ID
4101             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4102             * @return the last matching message-boards message
4103             * @throws NoSuchMessageException if a matching message-boards message could not be found
4104             */
4105            @Override
4106            public MBMessage findByThreadReplies_Last(long threadId,
4107                    OrderByComparator<MBMessage> orderByComparator)
4108                    throws NoSuchMessageException {
4109                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4110                                    orderByComparator);
4111    
4112                    if (mbMessage != null) {
4113                            return mbMessage;
4114                    }
4115    
4116                    StringBundler msg = new StringBundler(4);
4117    
4118                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4119    
4120                    msg.append("threadId=");
4121                    msg.append(threadId);
4122    
4123                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4124    
4125                    throw new NoSuchMessageException(msg.toString());
4126            }
4127    
4128            /**
4129             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4130             *
4131             * @param threadId the thread ID
4132             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4133             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4134             */
4135            @Override
4136            public MBMessage fetchByThreadReplies_Last(long threadId,
4137                    OrderByComparator<MBMessage> orderByComparator) {
4138                    int count = countByThreadReplies(threadId);
4139    
4140                    if (count == 0) {
4141                            return null;
4142                    }
4143    
4144                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4145                                    orderByComparator);
4146    
4147                    if (!list.isEmpty()) {
4148                            return list.get(0);
4149                    }
4150    
4151                    return null;
4152            }
4153    
4154            /**
4155             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4156             *
4157             * @param messageId the primary key of the current message-boards message
4158             * @param threadId the thread ID
4159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4160             * @return the previous, current, and next message-boards message
4161             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4162             */
4163            @Override
4164            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4165                    long threadId, OrderByComparator<MBMessage> orderByComparator)
4166                    throws NoSuchMessageException {
4167                    MBMessage mbMessage = findByPrimaryKey(messageId);
4168    
4169                    Session session = null;
4170    
4171                    try {
4172                            session = openSession();
4173    
4174                            MBMessage[] array = new MBMessageImpl[3];
4175    
4176                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4177                                            threadId, orderByComparator, true);
4178    
4179                            array[1] = mbMessage;
4180    
4181                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4182                                            threadId, orderByComparator, false);
4183    
4184                            return array;
4185                    }
4186                    catch (Exception e) {
4187                            throw processException(e);
4188                    }
4189                    finally {
4190                            closeSession(session);
4191                    }
4192            }
4193    
4194            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4195                    MBMessage mbMessage, long threadId,
4196                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4197                    StringBundler query = null;
4198    
4199                    if (orderByComparator != null) {
4200                            query = new StringBundler(4 +
4201                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4202                                            (orderByComparator.getOrderByFields().length * 3));
4203                    }
4204                    else {
4205                            query = new StringBundler(3);
4206                    }
4207    
4208                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4209    
4210                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4211    
4212                    if (orderByComparator != null) {
4213                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4214    
4215                            if (orderByConditionFields.length > 0) {
4216                                    query.append(WHERE_AND);
4217                            }
4218    
4219                            for (int i = 0; i < orderByConditionFields.length; i++) {
4220                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4221                                    query.append(orderByConditionFields[i]);
4222    
4223                                    if ((i + 1) < orderByConditionFields.length) {
4224                                            if (orderByComparator.isAscending() ^ previous) {
4225                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4226                                            }
4227                                            else {
4228                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4229                                            }
4230                                    }
4231                                    else {
4232                                            if (orderByComparator.isAscending() ^ previous) {
4233                                                    query.append(WHERE_GREATER_THAN);
4234                                            }
4235                                            else {
4236                                                    query.append(WHERE_LESSER_THAN);
4237                                            }
4238                                    }
4239                            }
4240    
4241                            query.append(ORDER_BY_CLAUSE);
4242    
4243                            String[] orderByFields = orderByComparator.getOrderByFields();
4244    
4245                            for (int i = 0; i < orderByFields.length; i++) {
4246                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4247                                    query.append(orderByFields[i]);
4248    
4249                                    if ((i + 1) < orderByFields.length) {
4250                                            if (orderByComparator.isAscending() ^ previous) {
4251                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4252                                            }
4253                                            else {
4254                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4255                                            }
4256                                    }
4257                                    else {
4258                                            if (orderByComparator.isAscending() ^ previous) {
4259                                                    query.append(ORDER_BY_ASC);
4260                                            }
4261                                            else {
4262                                                    query.append(ORDER_BY_DESC);
4263                                            }
4264                                    }
4265                            }
4266                    }
4267                    else {
4268                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4269                    }
4270    
4271                    String sql = query.toString();
4272    
4273                    Query q = session.createQuery(sql);
4274    
4275                    q.setFirstResult(0);
4276                    q.setMaxResults(2);
4277    
4278                    QueryPos qPos = QueryPos.getInstance(q);
4279    
4280                    qPos.add(threadId);
4281    
4282                    if (orderByComparator != null) {
4283                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4284    
4285                            for (Object value : values) {
4286                                    qPos.add(value);
4287                            }
4288                    }
4289    
4290                    List<MBMessage> list = q.list();
4291    
4292                    if (list.size() == 2) {
4293                            return list.get(1);
4294                    }
4295                    else {
4296                            return null;
4297                    }
4298            }
4299    
4300            /**
4301             * Removes all the message-boards messages where threadId = &#63; from the database.
4302             *
4303             * @param threadId the thread ID
4304             */
4305            @Override
4306            public void removeByThreadReplies(long threadId) {
4307                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4308                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4309                            remove(mbMessage);
4310                    }
4311            }
4312    
4313            /**
4314             * Returns the number of message-boards messages where threadId = &#63;.
4315             *
4316             * @param threadId the thread ID
4317             * @return the number of matching message-boards messages
4318             */
4319            @Override
4320            public int countByThreadReplies(long threadId) {
4321                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4322    
4323                    Object[] finderArgs = new Object[] { threadId };
4324    
4325                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4326    
4327                    if (count == null) {
4328                            StringBundler query = new StringBundler(2);
4329    
4330                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4331    
4332                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4333    
4334                            String sql = query.toString();
4335    
4336                            Session session = null;
4337    
4338                            try {
4339                                    session = openSession();
4340    
4341                                    Query q = session.createQuery(sql);
4342    
4343                                    QueryPos qPos = QueryPos.getInstance(q);
4344    
4345                                    qPos.add(threadId);
4346    
4347                                    count = (Long)q.uniqueResult();
4348    
4349                                    finderCache.putResult(finderPath, finderArgs, count);
4350                            }
4351                            catch (Exception e) {
4352                                    finderCache.removeResult(finderPath, finderArgs);
4353    
4354                                    throw processException(e);
4355                            }
4356                            finally {
4357                                    closeSession(session);
4358                            }
4359                    }
4360    
4361                    return count.intValue();
4362            }
4363    
4364            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4365            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4366                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4367                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4368                            new String[] {
4369                                    Long.class.getName(), Long.class.getName(),
4370                                    
4371                            Integer.class.getName(), Integer.class.getName(),
4372                                    OrderByComparator.class.getName()
4373                            });
4374            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4375                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4376                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4377                            new String[] { Long.class.getName(), Long.class.getName() },
4378                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4379                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4380                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4381            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4382                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4383                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4384                            new String[] { Long.class.getName(), Long.class.getName() });
4385    
4386            /**
4387             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4388             *
4389             * @param groupId the group ID
4390             * @param userId the user ID
4391             * @return the matching message-boards messages
4392             */
4393            @Override
4394            public List<MBMessage> findByG_U(long groupId, long userId) {
4395                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4396                            null);
4397            }
4398    
4399            /**
4400             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4401             *
4402             * <p>
4403             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4404             * </p>
4405             *
4406             * @param groupId the group ID
4407             * @param userId the user ID
4408             * @param start the lower bound of the range of message-boards messages
4409             * @param end the upper bound of the range of message-boards messages (not inclusive)
4410             * @return the range of matching message-boards messages
4411             */
4412            @Override
4413            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4414                    int end) {
4415                    return findByG_U(groupId, userId, start, end, null);
4416            }
4417    
4418            /**
4419             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4420             *
4421             * <p>
4422             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4423             * </p>
4424             *
4425             * @param groupId the group ID
4426             * @param userId the user ID
4427             * @param start the lower bound of the range of message-boards messages
4428             * @param end the upper bound of the range of message-boards messages (not inclusive)
4429             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4430             * @return the ordered range of matching message-boards messages
4431             */
4432            @Override
4433            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4434                    int end, OrderByComparator<MBMessage> orderByComparator) {
4435                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
4436            }
4437    
4438            /**
4439             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4440             *
4441             * <p>
4442             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4443             * </p>
4444             *
4445             * @param groupId the group ID
4446             * @param userId the user ID
4447             * @param start the lower bound of the range of message-boards messages
4448             * @param end the upper bound of the range of message-boards messages (not inclusive)
4449             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4450             * @param retrieveFromCache whether to retrieve from the finder cache
4451             * @return the ordered range of matching message-boards messages
4452             */
4453            @Override
4454            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4455                    int end, OrderByComparator<MBMessage> orderByComparator,
4456                    boolean retrieveFromCache) {
4457                    boolean pagination = true;
4458                    FinderPath finderPath = null;
4459                    Object[] finderArgs = null;
4460    
4461                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4462                                    (orderByComparator == null)) {
4463                            pagination = false;
4464                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4465                            finderArgs = new Object[] { groupId, userId };
4466                    }
4467                    else {
4468                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4469                            finderArgs = new Object[] {
4470                                            groupId, userId,
4471                                            
4472                                            start, end, orderByComparator
4473                                    };
4474                    }
4475    
4476                    List<MBMessage> list = null;
4477    
4478                    if (retrieveFromCache) {
4479                            list = (List<MBMessage>)finderCache.getResult(finderPath,
4480                                            finderArgs, this);
4481    
4482                            if ((list != null) && !list.isEmpty()) {
4483                                    for (MBMessage mbMessage : list) {
4484                                            if ((groupId != mbMessage.getGroupId()) ||
4485                                                            (userId != mbMessage.getUserId())) {
4486                                                    list = null;
4487    
4488                                                    break;
4489                                            }
4490                                    }
4491                            }
4492                    }
4493    
4494                    if (list == null) {
4495                            StringBundler query = null;
4496    
4497                            if (orderByComparator != null) {
4498                                    query = new StringBundler(4 +
4499                                                    (orderByComparator.getOrderByFields().length * 2));
4500                            }
4501                            else {
4502                                    query = new StringBundler(4);
4503                            }
4504    
4505                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4506    
4507                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4508    
4509                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4510    
4511                            if (orderByComparator != null) {
4512                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4513                                            orderByComparator);
4514                            }
4515                            else
4516                             if (pagination) {
4517                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4518                            }
4519    
4520                            String sql = query.toString();
4521    
4522                            Session session = null;
4523    
4524                            try {
4525                                    session = openSession();
4526    
4527                                    Query q = session.createQuery(sql);
4528    
4529                                    QueryPos qPos = QueryPos.getInstance(q);
4530    
4531                                    qPos.add(groupId);
4532    
4533                                    qPos.add(userId);
4534    
4535                                    if (!pagination) {
4536                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4537                                                            start, end, false);
4538    
4539                                            Collections.sort(list);
4540    
4541                                            list = Collections.unmodifiableList(list);
4542                                    }
4543                                    else {
4544                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4545                                                            start, end);
4546                                    }
4547    
4548                                    cacheResult(list);
4549    
4550                                    finderCache.putResult(finderPath, finderArgs, list);
4551                            }
4552                            catch (Exception e) {
4553                                    finderCache.removeResult(finderPath, finderArgs);
4554    
4555                                    throw processException(e);
4556                            }
4557                            finally {
4558                                    closeSession(session);
4559                            }
4560                    }
4561    
4562                    return list;
4563            }
4564    
4565            /**
4566             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4567             *
4568             * @param groupId the group ID
4569             * @param userId the user ID
4570             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4571             * @return the first matching message-boards message
4572             * @throws NoSuchMessageException if a matching message-boards message could not be found
4573             */
4574            @Override
4575            public MBMessage findByG_U_First(long groupId, long userId,
4576                    OrderByComparator<MBMessage> orderByComparator)
4577                    throws NoSuchMessageException {
4578                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4579                                    orderByComparator);
4580    
4581                    if (mbMessage != null) {
4582                            return mbMessage;
4583                    }
4584    
4585                    StringBundler msg = new StringBundler(6);
4586    
4587                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4588    
4589                    msg.append("groupId=");
4590                    msg.append(groupId);
4591    
4592                    msg.append(", userId=");
4593                    msg.append(userId);
4594    
4595                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4596    
4597                    throw new NoSuchMessageException(msg.toString());
4598            }
4599    
4600            /**
4601             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4602             *
4603             * @param groupId the group ID
4604             * @param userId the user ID
4605             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4606             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4607             */
4608            @Override
4609            public MBMessage fetchByG_U_First(long groupId, long userId,
4610                    OrderByComparator<MBMessage> orderByComparator) {
4611                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4612                                    orderByComparator);
4613    
4614                    if (!list.isEmpty()) {
4615                            return list.get(0);
4616                    }
4617    
4618                    return null;
4619            }
4620    
4621            /**
4622             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4623             *
4624             * @param groupId the group ID
4625             * @param userId the user ID
4626             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4627             * @return the last matching message-boards message
4628             * @throws NoSuchMessageException if a matching message-boards message could not be found
4629             */
4630            @Override
4631            public MBMessage findByG_U_Last(long groupId, long userId,
4632                    OrderByComparator<MBMessage> orderByComparator)
4633                    throws NoSuchMessageException {
4634                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4635    
4636                    if (mbMessage != null) {
4637                            return mbMessage;
4638                    }
4639    
4640                    StringBundler msg = new StringBundler(6);
4641    
4642                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4643    
4644                    msg.append("groupId=");
4645                    msg.append(groupId);
4646    
4647                    msg.append(", userId=");
4648                    msg.append(userId);
4649    
4650                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4651    
4652                    throw new NoSuchMessageException(msg.toString());
4653            }
4654    
4655            /**
4656             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4657             *
4658             * @param groupId the group ID
4659             * @param userId the user ID
4660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4661             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4662             */
4663            @Override
4664            public MBMessage fetchByG_U_Last(long groupId, long userId,
4665                    OrderByComparator<MBMessage> orderByComparator) {
4666                    int count = countByG_U(groupId, userId);
4667    
4668                    if (count == 0) {
4669                            return null;
4670                    }
4671    
4672                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4673                                    orderByComparator);
4674    
4675                    if (!list.isEmpty()) {
4676                            return list.get(0);
4677                    }
4678    
4679                    return null;
4680            }
4681    
4682            /**
4683             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4684             *
4685             * @param messageId the primary key of the current message-boards message
4686             * @param groupId the group ID
4687             * @param userId the user ID
4688             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4689             * @return the previous, current, and next message-boards message
4690             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4691             */
4692            @Override
4693            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4694                    long userId, OrderByComparator<MBMessage> orderByComparator)
4695                    throws NoSuchMessageException {
4696                    MBMessage mbMessage = findByPrimaryKey(messageId);
4697    
4698                    Session session = null;
4699    
4700                    try {
4701                            session = openSession();
4702    
4703                            MBMessage[] array = new MBMessageImpl[3];
4704    
4705                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4706                                            userId, orderByComparator, true);
4707    
4708                            array[1] = mbMessage;
4709    
4710                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4711                                            userId, orderByComparator, false);
4712    
4713                            return array;
4714                    }
4715                    catch (Exception e) {
4716                            throw processException(e);
4717                    }
4718                    finally {
4719                            closeSession(session);
4720                    }
4721            }
4722    
4723            protected MBMessage getByG_U_PrevAndNext(Session session,
4724                    MBMessage mbMessage, long groupId, long userId,
4725                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4726                    StringBundler query = null;
4727    
4728                    if (orderByComparator != null) {
4729                            query = new StringBundler(5 +
4730                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4731                                            (orderByComparator.getOrderByFields().length * 3));
4732                    }
4733                    else {
4734                            query = new StringBundler(4);
4735                    }
4736    
4737                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4738    
4739                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4740    
4741                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4742    
4743                    if (orderByComparator != null) {
4744                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4745    
4746                            if (orderByConditionFields.length > 0) {
4747                                    query.append(WHERE_AND);
4748                            }
4749    
4750                            for (int i = 0; i < orderByConditionFields.length; i++) {
4751                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4752                                    query.append(orderByConditionFields[i]);
4753    
4754                                    if ((i + 1) < orderByConditionFields.length) {
4755                                            if (orderByComparator.isAscending() ^ previous) {
4756                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4757                                            }
4758                                            else {
4759                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4760                                            }
4761                                    }
4762                                    else {
4763                                            if (orderByComparator.isAscending() ^ previous) {
4764                                                    query.append(WHERE_GREATER_THAN);
4765                                            }
4766                                            else {
4767                                                    query.append(WHERE_LESSER_THAN);
4768                                            }
4769                                    }
4770                            }
4771    
4772                            query.append(ORDER_BY_CLAUSE);
4773    
4774                            String[] orderByFields = orderByComparator.getOrderByFields();
4775    
4776                            for (int i = 0; i < orderByFields.length; i++) {
4777                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4778                                    query.append(orderByFields[i]);
4779    
4780                                    if ((i + 1) < orderByFields.length) {
4781                                            if (orderByComparator.isAscending() ^ previous) {
4782                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4783                                            }
4784                                            else {
4785                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4786                                            }
4787                                    }
4788                                    else {
4789                                            if (orderByComparator.isAscending() ^ previous) {
4790                                                    query.append(ORDER_BY_ASC);
4791                                            }
4792                                            else {
4793                                                    query.append(ORDER_BY_DESC);
4794                                            }
4795                                    }
4796                            }
4797                    }
4798                    else {
4799                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4800                    }
4801    
4802                    String sql = query.toString();
4803    
4804                    Query q = session.createQuery(sql);
4805    
4806                    q.setFirstResult(0);
4807                    q.setMaxResults(2);
4808    
4809                    QueryPos qPos = QueryPos.getInstance(q);
4810    
4811                    qPos.add(groupId);
4812    
4813                    qPos.add(userId);
4814    
4815                    if (orderByComparator != null) {
4816                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4817    
4818                            for (Object value : values) {
4819                                    qPos.add(value);
4820                            }
4821                    }
4822    
4823                    List<MBMessage> list = q.list();
4824    
4825                    if (list.size() == 2) {
4826                            return list.get(1);
4827                    }
4828                    else {
4829                            return null;
4830                    }
4831            }
4832    
4833            /**
4834             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4835             *
4836             * @param groupId the group ID
4837             * @param userId the user ID
4838             * @return the matching message-boards messages that the user has permission to view
4839             */
4840            @Override
4841            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4842                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4843                            QueryUtil.ALL_POS, null);
4844            }
4845    
4846            /**
4847             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4848             *
4849             * <p>
4850             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4851             * </p>
4852             *
4853             * @param groupId the group ID
4854             * @param userId the user ID
4855             * @param start the lower bound of the range of message-boards messages
4856             * @param end the upper bound of the range of message-boards messages (not inclusive)
4857             * @return the range of matching message-boards messages that the user has permission to view
4858             */
4859            @Override
4860            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4861                    int start, int end) {
4862                    return filterFindByG_U(groupId, userId, start, end, null);
4863            }
4864    
4865            /**
4866             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4867             *
4868             * <p>
4869             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4870             * </p>
4871             *
4872             * @param groupId the group ID
4873             * @param userId the user ID
4874             * @param start the lower bound of the range of message-boards messages
4875             * @param end the upper bound of the range of message-boards messages (not inclusive)
4876             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4877             * @return the ordered range of matching message-boards messages that the user has permission to view
4878             */
4879            @Override
4880            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4881                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4882                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4883                            return findByG_U(groupId, userId, start, end, orderByComparator);
4884                    }
4885    
4886                    StringBundler query = null;
4887    
4888                    if (orderByComparator != null) {
4889                            query = new StringBundler(4 +
4890                                            (orderByComparator.getOrderByFields().length * 2));
4891                    }
4892                    else {
4893                            query = new StringBundler(5);
4894                    }
4895    
4896                    if (getDB().isSupportsInlineDistinct()) {
4897                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4898                    }
4899                    else {
4900                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4901                    }
4902    
4903                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4904    
4905                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4906    
4907                    if (!getDB().isSupportsInlineDistinct()) {
4908                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4909                    }
4910    
4911                    if (orderByComparator != null) {
4912                            if (getDB().isSupportsInlineDistinct()) {
4913                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4914                                            orderByComparator, true);
4915                            }
4916                            else {
4917                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4918                                            orderByComparator, true);
4919                            }
4920                    }
4921                    else {
4922                            if (getDB().isSupportsInlineDistinct()) {
4923                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4924                            }
4925                            else {
4926                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4927                            }
4928                    }
4929    
4930                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4931                                    MBMessage.class.getName(),
4932                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4933    
4934                    Session session = null;
4935    
4936                    try {
4937                            session = openSession();
4938    
4939                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4940    
4941                            if (getDB().isSupportsInlineDistinct()) {
4942                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4943                            }
4944                            else {
4945                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4946                            }
4947    
4948                            QueryPos qPos = QueryPos.getInstance(q);
4949    
4950                            qPos.add(groupId);
4951    
4952                            qPos.add(userId);
4953    
4954                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4955                    }
4956                    catch (Exception e) {
4957                            throw processException(e);
4958                    }
4959                    finally {
4960                            closeSession(session);
4961                    }
4962            }
4963    
4964            /**
4965             * 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;.
4966             *
4967             * @param messageId the primary key of the current message-boards message
4968             * @param groupId the group ID
4969             * @param userId the user ID
4970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4971             * @return the previous, current, and next message-boards message
4972             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4973             */
4974            @Override
4975            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4976                    long groupId, long userId,
4977                    OrderByComparator<MBMessage> orderByComparator)
4978                    throws NoSuchMessageException {
4979                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4980                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4981                                    orderByComparator);
4982                    }
4983    
4984                    MBMessage mbMessage = findByPrimaryKey(messageId);
4985    
4986                    Session session = null;
4987    
4988                    try {
4989                            session = openSession();
4990    
4991                            MBMessage[] array = new MBMessageImpl[3];
4992    
4993                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4994                                            userId, orderByComparator, true);
4995    
4996                            array[1] = mbMessage;
4997    
4998                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4999                                            userId, orderByComparator, false);
5000    
5001                            return array;
5002                    }
5003                    catch (Exception e) {
5004                            throw processException(e);
5005                    }
5006                    finally {
5007                            closeSession(session);
5008                    }
5009            }
5010    
5011            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5012                    MBMessage mbMessage, long groupId, long userId,
5013                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5014                    StringBundler query = null;
5015    
5016                    if (orderByComparator != null) {
5017                            query = new StringBundler(6 +
5018                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5019                                            (orderByComparator.getOrderByFields().length * 3));
5020                    }
5021                    else {
5022                            query = new StringBundler(5);
5023                    }
5024    
5025                    if (getDB().isSupportsInlineDistinct()) {
5026                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5027                    }
5028                    else {
5029                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5030                    }
5031    
5032                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5033    
5034                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5035    
5036                    if (!getDB().isSupportsInlineDistinct()) {
5037                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5038                    }
5039    
5040                    if (orderByComparator != null) {
5041                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5042    
5043                            if (orderByConditionFields.length > 0) {
5044                                    query.append(WHERE_AND);
5045                            }
5046    
5047                            for (int i = 0; i < orderByConditionFields.length; i++) {
5048                                    if (getDB().isSupportsInlineDistinct()) {
5049                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5050                                    }
5051                                    else {
5052                                            query.append(_ORDER_BY_ENTITY_TABLE);
5053                                    }
5054    
5055                                    query.append(orderByConditionFields[i]);
5056    
5057                                    if ((i + 1) < orderByConditionFields.length) {
5058                                            if (orderByComparator.isAscending() ^ previous) {
5059                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5060                                            }
5061                                            else {
5062                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5063                                            }
5064                                    }
5065                                    else {
5066                                            if (orderByComparator.isAscending() ^ previous) {
5067                                                    query.append(WHERE_GREATER_THAN);
5068                                            }
5069                                            else {
5070                                                    query.append(WHERE_LESSER_THAN);
5071                                            }
5072                                    }
5073                            }
5074    
5075                            query.append(ORDER_BY_CLAUSE);
5076    
5077                            String[] orderByFields = orderByComparator.getOrderByFields();
5078    
5079                            for (int i = 0; i < orderByFields.length; i++) {
5080                                    if (getDB().isSupportsInlineDistinct()) {
5081                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5082                                    }
5083                                    else {
5084                                            query.append(_ORDER_BY_ENTITY_TABLE);
5085                                    }
5086    
5087                                    query.append(orderByFields[i]);
5088    
5089                                    if ((i + 1) < orderByFields.length) {
5090                                            if (orderByComparator.isAscending() ^ previous) {
5091                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5092                                            }
5093                                            else {
5094                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5095                                            }
5096                                    }
5097                                    else {
5098                                            if (orderByComparator.isAscending() ^ previous) {
5099                                                    query.append(ORDER_BY_ASC);
5100                                            }
5101                                            else {
5102                                                    query.append(ORDER_BY_DESC);
5103                                            }
5104                                    }
5105                            }
5106                    }
5107                    else {
5108                            if (getDB().isSupportsInlineDistinct()) {
5109                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5110                            }
5111                            else {
5112                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5113                            }
5114                    }
5115    
5116                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5117                                    MBMessage.class.getName(),
5118                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5119    
5120                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5121    
5122                    q.setFirstResult(0);
5123                    q.setMaxResults(2);
5124    
5125                    if (getDB().isSupportsInlineDistinct()) {
5126                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5127                    }
5128                    else {
5129                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5130                    }
5131    
5132                    QueryPos qPos = QueryPos.getInstance(q);
5133    
5134                    qPos.add(groupId);
5135    
5136                    qPos.add(userId);
5137    
5138                    if (orderByComparator != null) {
5139                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5140    
5141                            for (Object value : values) {
5142                                    qPos.add(value);
5143                            }
5144                    }
5145    
5146                    List<MBMessage> list = q.list();
5147    
5148                    if (list.size() == 2) {
5149                            return list.get(1);
5150                    }
5151                    else {
5152                            return null;
5153                    }
5154            }
5155    
5156            /**
5157             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5158             *
5159             * @param groupId the group ID
5160             * @param userId the user ID
5161             */
5162            @Override
5163            public void removeByG_U(long groupId, long userId) {
5164                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5165                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5166                            remove(mbMessage);
5167                    }
5168            }
5169    
5170            /**
5171             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5172             *
5173             * @param groupId the group ID
5174             * @param userId the user ID
5175             * @return the number of matching message-boards messages
5176             */
5177            @Override
5178            public int countByG_U(long groupId, long userId) {
5179                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5180    
5181                    Object[] finderArgs = new Object[] { groupId, userId };
5182    
5183                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5184    
5185                    if (count == null) {
5186                            StringBundler query = new StringBundler(3);
5187    
5188                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5189    
5190                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5191    
5192                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5193    
5194                            String sql = query.toString();
5195    
5196                            Session session = null;
5197    
5198                            try {
5199                                    session = openSession();
5200    
5201                                    Query q = session.createQuery(sql);
5202    
5203                                    QueryPos qPos = QueryPos.getInstance(q);
5204    
5205                                    qPos.add(groupId);
5206    
5207                                    qPos.add(userId);
5208    
5209                                    count = (Long)q.uniqueResult();
5210    
5211                                    finderCache.putResult(finderPath, finderArgs, count);
5212                            }
5213                            catch (Exception e) {
5214                                    finderCache.removeResult(finderPath, finderArgs);
5215    
5216                                    throw processException(e);
5217                            }
5218                            finally {
5219                                    closeSession(session);
5220                            }
5221                    }
5222    
5223                    return count.intValue();
5224            }
5225    
5226            /**
5227             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5228             *
5229             * @param groupId the group ID
5230             * @param userId the user ID
5231             * @return the number of matching message-boards messages that the user has permission to view
5232             */
5233            @Override
5234            public int filterCountByG_U(long groupId, long userId) {
5235                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5236                            return countByG_U(groupId, userId);
5237                    }
5238    
5239                    StringBundler query = new StringBundler(3);
5240    
5241                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5242    
5243                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5244    
5245                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5246    
5247                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5248                                    MBMessage.class.getName(),
5249                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5250    
5251                    Session session = null;
5252    
5253                    try {
5254                            session = openSession();
5255    
5256                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5257    
5258                            q.addScalar(COUNT_COLUMN_NAME,
5259                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5260    
5261                            QueryPos qPos = QueryPos.getInstance(q);
5262    
5263                            qPos.add(groupId);
5264    
5265                            qPos.add(userId);
5266    
5267                            Long count = (Long)q.uniqueResult();
5268    
5269                            return count.intValue();
5270                    }
5271                    catch (Exception e) {
5272                            throw processException(e);
5273                    }
5274                    finally {
5275                            closeSession(session);
5276                    }
5277            }
5278    
5279            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5280            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5281            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5282                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5283                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5284                            new String[] {
5285                                    Long.class.getName(), Long.class.getName(),
5286                                    
5287                            Integer.class.getName(), Integer.class.getName(),
5288                                    OrderByComparator.class.getName()
5289                            });
5290            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5291                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5292                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5293                            new String[] { Long.class.getName(), Long.class.getName() },
5294                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5295                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5296                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5297            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5298                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5299                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5300                            new String[] { Long.class.getName(), Long.class.getName() });
5301    
5302            /**
5303             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5304             *
5305             * @param groupId the group ID
5306             * @param categoryId the category ID
5307             * @return the matching message-boards messages
5308             */
5309            @Override
5310            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5311                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5312                            QueryUtil.ALL_POS, null);
5313            }
5314    
5315            /**
5316             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5317             *
5318             * <p>
5319             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5320             * </p>
5321             *
5322             * @param groupId the group ID
5323             * @param categoryId the category ID
5324             * @param start the lower bound of the range of message-boards messages
5325             * @param end the upper bound of the range of message-boards messages (not inclusive)
5326             * @return the range of matching message-boards messages
5327             */
5328            @Override
5329            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5330                    int end) {
5331                    return findByG_C(groupId, categoryId, start, end, null);
5332            }
5333    
5334            /**
5335             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5336             *
5337             * <p>
5338             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5339             * </p>
5340             *
5341             * @param groupId the group ID
5342             * @param categoryId the category ID
5343             * @param start the lower bound of the range of message-boards messages
5344             * @param end the upper bound of the range of message-boards messages (not inclusive)
5345             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5346             * @return the ordered range of matching message-boards messages
5347             */
5348            @Override
5349            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5350                    int end, OrderByComparator<MBMessage> orderByComparator) {
5351                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
5352                            true);
5353            }
5354    
5355            /**
5356             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5357             *
5358             * <p>
5359             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5360             * </p>
5361             *
5362             * @param groupId the group ID
5363             * @param categoryId the category ID
5364             * @param start the lower bound of the range of message-boards messages
5365             * @param end the upper bound of the range of message-boards messages (not inclusive)
5366             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5367             * @param retrieveFromCache whether to retrieve from the finder cache
5368             * @return the ordered range of matching message-boards messages
5369             */
5370            @Override
5371            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5372                    int end, OrderByComparator<MBMessage> orderByComparator,
5373                    boolean retrieveFromCache) {
5374                    boolean pagination = true;
5375                    FinderPath finderPath = null;
5376                    Object[] finderArgs = null;
5377    
5378                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5379                                    (orderByComparator == null)) {
5380                            pagination = false;
5381                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5382                            finderArgs = new Object[] { groupId, categoryId };
5383                    }
5384                    else {
5385                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5386                            finderArgs = new Object[] {
5387                                            groupId, categoryId,
5388                                            
5389                                            start, end, orderByComparator
5390                                    };
5391                    }
5392    
5393                    List<MBMessage> list = null;
5394    
5395                    if (retrieveFromCache) {
5396                            list = (List<MBMessage>)finderCache.getResult(finderPath,
5397                                            finderArgs, this);
5398    
5399                            if ((list != null) && !list.isEmpty()) {
5400                                    for (MBMessage mbMessage : list) {
5401                                            if ((groupId != mbMessage.getGroupId()) ||
5402                                                            (categoryId != mbMessage.getCategoryId())) {
5403                                                    list = null;
5404    
5405                                                    break;
5406                                            }
5407                                    }
5408                            }
5409                    }
5410    
5411                    if (list == null) {
5412                            StringBundler query = null;
5413    
5414                            if (orderByComparator != null) {
5415                                    query = new StringBundler(4 +
5416                                                    (orderByComparator.getOrderByFields().length * 2));
5417                            }
5418                            else {
5419                                    query = new StringBundler(4);
5420                            }
5421    
5422                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5423    
5424                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5425    
5426                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5427    
5428                            if (orderByComparator != null) {
5429                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5430                                            orderByComparator);
5431                            }
5432                            else
5433                             if (pagination) {
5434                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5435                            }
5436    
5437                            String sql = query.toString();
5438    
5439                            Session session = null;
5440    
5441                            try {
5442                                    session = openSession();
5443    
5444                                    Query q = session.createQuery(sql);
5445    
5446                                    QueryPos qPos = QueryPos.getInstance(q);
5447    
5448                                    qPos.add(groupId);
5449    
5450                                    qPos.add(categoryId);
5451    
5452                                    if (!pagination) {
5453                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5454                                                            start, end, false);
5455    
5456                                            Collections.sort(list);
5457    
5458                                            list = Collections.unmodifiableList(list);
5459                                    }
5460                                    else {
5461                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5462                                                            start, end);
5463                                    }
5464    
5465                                    cacheResult(list);
5466    
5467                                    finderCache.putResult(finderPath, finderArgs, list);
5468                            }
5469                            catch (Exception e) {
5470                                    finderCache.removeResult(finderPath, finderArgs);
5471    
5472                                    throw processException(e);
5473                            }
5474                            finally {
5475                                    closeSession(session);
5476                            }
5477                    }
5478    
5479                    return list;
5480            }
5481    
5482            /**
5483             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5484             *
5485             * @param groupId the group ID
5486             * @param categoryId the category ID
5487             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5488             * @return the first matching message-boards message
5489             * @throws NoSuchMessageException if a matching message-boards message could not be found
5490             */
5491            @Override
5492            public MBMessage findByG_C_First(long groupId, long categoryId,
5493                    OrderByComparator<MBMessage> orderByComparator)
5494                    throws NoSuchMessageException {
5495                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5496                                    orderByComparator);
5497    
5498                    if (mbMessage != null) {
5499                            return mbMessage;
5500                    }
5501    
5502                    StringBundler msg = new StringBundler(6);
5503    
5504                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5505    
5506                    msg.append("groupId=");
5507                    msg.append(groupId);
5508    
5509                    msg.append(", categoryId=");
5510                    msg.append(categoryId);
5511    
5512                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5513    
5514                    throw new NoSuchMessageException(msg.toString());
5515            }
5516    
5517            /**
5518             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5519             *
5520             * @param groupId the group ID
5521             * @param categoryId the category ID
5522             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5523             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5524             */
5525            @Override
5526            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5527                    OrderByComparator<MBMessage> orderByComparator) {
5528                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5529                                    orderByComparator);
5530    
5531                    if (!list.isEmpty()) {
5532                            return list.get(0);
5533                    }
5534    
5535                    return null;
5536            }
5537    
5538            /**
5539             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5540             *
5541             * @param groupId the group ID
5542             * @param categoryId the category ID
5543             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5544             * @return the last matching message-boards message
5545             * @throws NoSuchMessageException if a matching message-boards message could not be found
5546             */
5547            @Override
5548            public MBMessage findByG_C_Last(long groupId, long categoryId,
5549                    OrderByComparator<MBMessage> orderByComparator)
5550                    throws NoSuchMessageException {
5551                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5552                                    orderByComparator);
5553    
5554                    if (mbMessage != null) {
5555                            return mbMessage;
5556                    }
5557    
5558                    StringBundler msg = new StringBundler(6);
5559    
5560                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5561    
5562                    msg.append("groupId=");
5563                    msg.append(groupId);
5564    
5565                    msg.append(", categoryId=");
5566                    msg.append(categoryId);
5567    
5568                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5569    
5570                    throw new NoSuchMessageException(msg.toString());
5571            }
5572    
5573            /**
5574             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5575             *
5576             * @param groupId the group ID
5577             * @param categoryId the category ID
5578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5579             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5580             */
5581            @Override
5582            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5583                    OrderByComparator<MBMessage> orderByComparator) {
5584                    int count = countByG_C(groupId, categoryId);
5585    
5586                    if (count == 0) {
5587                            return null;
5588                    }
5589    
5590                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5591                                    orderByComparator);
5592    
5593                    if (!list.isEmpty()) {
5594                            return list.get(0);
5595                    }
5596    
5597                    return null;
5598            }
5599    
5600            /**
5601             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5602             *
5603             * @param messageId the primary key of the current message-boards message
5604             * @param groupId the group ID
5605             * @param categoryId the category ID
5606             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5607             * @return the previous, current, and next message-boards message
5608             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5609             */
5610            @Override
5611            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5612                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5613                    throws NoSuchMessageException {
5614                    MBMessage mbMessage = findByPrimaryKey(messageId);
5615    
5616                    Session session = null;
5617    
5618                    try {
5619                            session = openSession();
5620    
5621                            MBMessage[] array = new MBMessageImpl[3];
5622    
5623                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5624                                            categoryId, orderByComparator, true);
5625    
5626                            array[1] = mbMessage;
5627    
5628                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5629                                            categoryId, orderByComparator, false);
5630    
5631                            return array;
5632                    }
5633                    catch (Exception e) {
5634                            throw processException(e);
5635                    }
5636                    finally {
5637                            closeSession(session);
5638                    }
5639            }
5640    
5641            protected MBMessage getByG_C_PrevAndNext(Session session,
5642                    MBMessage mbMessage, long groupId, long categoryId,
5643                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5644                    StringBundler query = null;
5645    
5646                    if (orderByComparator != null) {
5647                            query = new StringBundler(5 +
5648                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5649                                            (orderByComparator.getOrderByFields().length * 3));
5650                    }
5651                    else {
5652                            query = new StringBundler(4);
5653                    }
5654    
5655                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5656    
5657                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5658    
5659                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5660    
5661                    if (orderByComparator != null) {
5662                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5663    
5664                            if (orderByConditionFields.length > 0) {
5665                                    query.append(WHERE_AND);
5666                            }
5667    
5668                            for (int i = 0; i < orderByConditionFields.length; i++) {
5669                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5670                                    query.append(orderByConditionFields[i]);
5671    
5672                                    if ((i + 1) < orderByConditionFields.length) {
5673                                            if (orderByComparator.isAscending() ^ previous) {
5674                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5675                                            }
5676                                            else {
5677                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5678                                            }
5679                                    }
5680                                    else {
5681                                            if (orderByComparator.isAscending() ^ previous) {
5682                                                    query.append(WHERE_GREATER_THAN);
5683                                            }
5684                                            else {
5685                                                    query.append(WHERE_LESSER_THAN);
5686                                            }
5687                                    }
5688                            }
5689    
5690                            query.append(ORDER_BY_CLAUSE);
5691    
5692                            String[] orderByFields = orderByComparator.getOrderByFields();
5693    
5694                            for (int i = 0; i < orderByFields.length; i++) {
5695                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5696                                    query.append(orderByFields[i]);
5697    
5698                                    if ((i + 1) < orderByFields.length) {
5699                                            if (orderByComparator.isAscending() ^ previous) {
5700                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5701                                            }
5702                                            else {
5703                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5704                                            }
5705                                    }
5706                                    else {
5707                                            if (orderByComparator.isAscending() ^ previous) {
5708                                                    query.append(ORDER_BY_ASC);
5709                                            }
5710                                            else {
5711                                                    query.append(ORDER_BY_DESC);
5712                                            }
5713                                    }
5714                            }
5715                    }
5716                    else {
5717                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5718                    }
5719    
5720                    String sql = query.toString();
5721    
5722                    Query q = session.createQuery(sql);
5723    
5724                    q.setFirstResult(0);
5725                    q.setMaxResults(2);
5726    
5727                    QueryPos qPos = QueryPos.getInstance(q);
5728    
5729                    qPos.add(groupId);
5730    
5731                    qPos.add(categoryId);
5732    
5733                    if (orderByComparator != null) {
5734                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5735    
5736                            for (Object value : values) {
5737                                    qPos.add(value);
5738                            }
5739                    }
5740    
5741                    List<MBMessage> list = q.list();
5742    
5743                    if (list.size() == 2) {
5744                            return list.get(1);
5745                    }
5746                    else {
5747                            return null;
5748                    }
5749            }
5750    
5751            /**
5752             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5753             *
5754             * @param groupId the group ID
5755             * @param categoryId the category ID
5756             * @return the matching message-boards messages that the user has permission to view
5757             */
5758            @Override
5759            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5760                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5761                            QueryUtil.ALL_POS, null);
5762            }
5763    
5764            /**
5765             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5766             *
5767             * <p>
5768             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5769             * </p>
5770             *
5771             * @param groupId the group ID
5772             * @param categoryId the category ID
5773             * @param start the lower bound of the range of message-boards messages
5774             * @param end the upper bound of the range of message-boards messages (not inclusive)
5775             * @return the range of matching message-boards messages that the user has permission to view
5776             */
5777            @Override
5778            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5779                    int start, int end) {
5780                    return filterFindByG_C(groupId, categoryId, start, end, null);
5781            }
5782    
5783            /**
5784             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5785             *
5786             * <p>
5787             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5788             * </p>
5789             *
5790             * @param groupId the group ID
5791             * @param categoryId the category ID
5792             * @param start the lower bound of the range of message-boards messages
5793             * @param end the upper bound of the range of message-boards messages (not inclusive)
5794             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5795             * @return the ordered range of matching message-boards messages that the user has permission to view
5796             */
5797            @Override
5798            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5799                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5800                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5801                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5802                    }
5803    
5804                    StringBundler query = null;
5805    
5806                    if (orderByComparator != null) {
5807                            query = new StringBundler(4 +
5808                                            (orderByComparator.getOrderByFields().length * 2));
5809                    }
5810                    else {
5811                            query = new StringBundler(5);
5812                    }
5813    
5814                    if (getDB().isSupportsInlineDistinct()) {
5815                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5816                    }
5817                    else {
5818                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5819                    }
5820    
5821                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5822    
5823                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5824    
5825                    if (!getDB().isSupportsInlineDistinct()) {
5826                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5827                    }
5828    
5829                    if (orderByComparator != null) {
5830                            if (getDB().isSupportsInlineDistinct()) {
5831                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5832                                            orderByComparator, true);
5833                            }
5834                            else {
5835                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5836                                            orderByComparator, true);
5837                            }
5838                    }
5839                    else {
5840                            if (getDB().isSupportsInlineDistinct()) {
5841                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5842                            }
5843                            else {
5844                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5845                            }
5846                    }
5847    
5848                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5849                                    MBMessage.class.getName(),
5850                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5851    
5852                    Session session = null;
5853    
5854                    try {
5855                            session = openSession();
5856    
5857                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5858    
5859                            if (getDB().isSupportsInlineDistinct()) {
5860                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5861                            }
5862                            else {
5863                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5864                            }
5865    
5866                            QueryPos qPos = QueryPos.getInstance(q);
5867    
5868                            qPos.add(groupId);
5869    
5870                            qPos.add(categoryId);
5871    
5872                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5873                    }
5874                    catch (Exception e) {
5875                            throw processException(e);
5876                    }
5877                    finally {
5878                            closeSession(session);
5879                    }
5880            }
5881    
5882            /**
5883             * 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;.
5884             *
5885             * @param messageId the primary key of the current message-boards message
5886             * @param groupId the group ID
5887             * @param categoryId the category ID
5888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5889             * @return the previous, current, and next message-boards message
5890             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5891             */
5892            @Override
5893            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5894                    long groupId, long categoryId,
5895                    OrderByComparator<MBMessage> orderByComparator)
5896                    throws NoSuchMessageException {
5897                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5898                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5899                                    orderByComparator);
5900                    }
5901    
5902                    MBMessage mbMessage = findByPrimaryKey(messageId);
5903    
5904                    Session session = null;
5905    
5906                    try {
5907                            session = openSession();
5908    
5909                            MBMessage[] array = new MBMessageImpl[3];
5910    
5911                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5912                                            categoryId, orderByComparator, true);
5913    
5914                            array[1] = mbMessage;
5915    
5916                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5917                                            categoryId, orderByComparator, false);
5918    
5919                            return array;
5920                    }
5921                    catch (Exception e) {
5922                            throw processException(e);
5923                    }
5924                    finally {
5925                            closeSession(session);
5926                    }
5927            }
5928    
5929            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5930                    MBMessage mbMessage, long groupId, long categoryId,
5931                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5932                    StringBundler query = null;
5933    
5934                    if (orderByComparator != null) {
5935                            query = new StringBundler(6 +
5936                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5937                                            (orderByComparator.getOrderByFields().length * 3));
5938                    }
5939                    else {
5940                            query = new StringBundler(5);
5941                    }
5942    
5943                    if (getDB().isSupportsInlineDistinct()) {
5944                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5945                    }
5946                    else {
5947                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5948                    }
5949    
5950                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5951    
5952                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5953    
5954                    if (!getDB().isSupportsInlineDistinct()) {
5955                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5956                    }
5957    
5958                    if (orderByComparator != null) {
5959                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5960    
5961                            if (orderByConditionFields.length > 0) {
5962                                    query.append(WHERE_AND);
5963                            }
5964    
5965                            for (int i = 0; i < orderByConditionFields.length; i++) {
5966                                    if (getDB().isSupportsInlineDistinct()) {
5967                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5968                                    }
5969                                    else {
5970                                            query.append(_ORDER_BY_ENTITY_TABLE);
5971                                    }
5972    
5973                                    query.append(orderByConditionFields[i]);
5974    
5975                                    if ((i + 1) < orderByConditionFields.length) {
5976                                            if (orderByComparator.isAscending() ^ previous) {
5977                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5978                                            }
5979                                            else {
5980                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5981                                            }
5982                                    }
5983                                    else {
5984                                            if (orderByComparator.isAscending() ^ previous) {
5985                                                    query.append(WHERE_GREATER_THAN);
5986                                            }
5987                                            else {
5988                                                    query.append(WHERE_LESSER_THAN);
5989                                            }
5990                                    }
5991                            }
5992    
5993                            query.append(ORDER_BY_CLAUSE);
5994    
5995                            String[] orderByFields = orderByComparator.getOrderByFields();
5996    
5997                            for (int i = 0; i < orderByFields.length; i++) {
5998                                    if (getDB().isSupportsInlineDistinct()) {
5999                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6000                                    }
6001                                    else {
6002                                            query.append(_ORDER_BY_ENTITY_TABLE);
6003                                    }
6004    
6005                                    query.append(orderByFields[i]);
6006    
6007                                    if ((i + 1) < orderByFields.length) {
6008                                            if (orderByComparator.isAscending() ^ previous) {
6009                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6010                                            }
6011                                            else {
6012                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6013                                            }
6014                                    }
6015                                    else {
6016                                            if (orderByComparator.isAscending() ^ previous) {
6017                                                    query.append(ORDER_BY_ASC);
6018                                            }
6019                                            else {
6020                                                    query.append(ORDER_BY_DESC);
6021                                            }
6022                                    }
6023                            }
6024                    }
6025                    else {
6026                            if (getDB().isSupportsInlineDistinct()) {
6027                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6028                            }
6029                            else {
6030                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6031                            }
6032                    }
6033    
6034                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6035                                    MBMessage.class.getName(),
6036                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6037    
6038                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6039    
6040                    q.setFirstResult(0);
6041                    q.setMaxResults(2);
6042    
6043                    if (getDB().isSupportsInlineDistinct()) {
6044                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6045                    }
6046                    else {
6047                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6048                    }
6049    
6050                    QueryPos qPos = QueryPos.getInstance(q);
6051    
6052                    qPos.add(groupId);
6053    
6054                    qPos.add(categoryId);
6055    
6056                    if (orderByComparator != null) {
6057                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6058    
6059                            for (Object value : values) {
6060                                    qPos.add(value);
6061                            }
6062                    }
6063    
6064                    List<MBMessage> list = q.list();
6065    
6066                    if (list.size() == 2) {
6067                            return list.get(1);
6068                    }
6069                    else {
6070                            return null;
6071                    }
6072            }
6073    
6074            /**
6075             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
6076             *
6077             * @param groupId the group ID
6078             * @param categoryId the category ID
6079             */
6080            @Override
6081            public void removeByG_C(long groupId, long categoryId) {
6082                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
6083                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6084                            remove(mbMessage);
6085                    }
6086            }
6087    
6088            /**
6089             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
6090             *
6091             * @param groupId the group ID
6092             * @param categoryId the category ID
6093             * @return the number of matching message-boards messages
6094             */
6095            @Override
6096            public int countByG_C(long groupId, long categoryId) {
6097                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6098    
6099                    Object[] finderArgs = new Object[] { groupId, categoryId };
6100    
6101                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6102    
6103                    if (count == null) {
6104                            StringBundler query = new StringBundler(3);
6105    
6106                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6107    
6108                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6109    
6110                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6111    
6112                            String sql = query.toString();
6113    
6114                            Session session = null;
6115    
6116                            try {
6117                                    session = openSession();
6118    
6119                                    Query q = session.createQuery(sql);
6120    
6121                                    QueryPos qPos = QueryPos.getInstance(q);
6122    
6123                                    qPos.add(groupId);
6124    
6125                                    qPos.add(categoryId);
6126    
6127                                    count = (Long)q.uniqueResult();
6128    
6129                                    finderCache.putResult(finderPath, finderArgs, count);
6130                            }
6131                            catch (Exception e) {
6132                                    finderCache.removeResult(finderPath, finderArgs);
6133    
6134                                    throw processException(e);
6135                            }
6136                            finally {
6137                                    closeSession(session);
6138                            }
6139                    }
6140    
6141                    return count.intValue();
6142            }
6143    
6144            /**
6145             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6146             *
6147             * @param groupId the group ID
6148             * @param categoryId the category ID
6149             * @return the number of matching message-boards messages that the user has permission to view
6150             */
6151            @Override
6152            public int filterCountByG_C(long groupId, long categoryId) {
6153                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6154                            return countByG_C(groupId, categoryId);
6155                    }
6156    
6157                    StringBundler query = new StringBundler(3);
6158    
6159                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6160    
6161                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6162    
6163                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6164    
6165                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6166                                    MBMessage.class.getName(),
6167                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6168    
6169                    Session session = null;
6170    
6171                    try {
6172                            session = openSession();
6173    
6174                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6175    
6176                            q.addScalar(COUNT_COLUMN_NAME,
6177                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6178    
6179                            QueryPos qPos = QueryPos.getInstance(q);
6180    
6181                            qPos.add(groupId);
6182    
6183                            qPos.add(categoryId);
6184    
6185                            Long count = (Long)q.uniqueResult();
6186    
6187                            return count.intValue();
6188                    }
6189                    catch (Exception e) {
6190                            throw processException(e);
6191                    }
6192                    finally {
6193                            closeSession(session);
6194                    }
6195            }
6196    
6197            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6198            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6199            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6200                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6201                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6202                            new String[] {
6203                                    Long.class.getName(), Integer.class.getName(),
6204                                    
6205                            Integer.class.getName(), Integer.class.getName(),
6206                                    OrderByComparator.class.getName()
6207                            });
6208            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6209                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6210                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6211                            new String[] { Long.class.getName(), Integer.class.getName() },
6212                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6213                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6214                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6215            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6216                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6217                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6218                            new String[] { Long.class.getName(), Integer.class.getName() });
6219    
6220            /**
6221             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6222             *
6223             * @param groupId the group ID
6224             * @param status the status
6225             * @return the matching message-boards messages
6226             */
6227            @Override
6228            public List<MBMessage> findByG_S(long groupId, int status) {
6229                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6230                            null);
6231            }
6232    
6233            /**
6234             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6235             *
6236             * <p>
6237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6238             * </p>
6239             *
6240             * @param groupId the group ID
6241             * @param status the status
6242             * @param start the lower bound of the range of message-boards messages
6243             * @param end the upper bound of the range of message-boards messages (not inclusive)
6244             * @return the range of matching message-boards messages
6245             */
6246            @Override
6247            public List<MBMessage> findByG_S(long groupId, int status, int start,
6248                    int end) {
6249                    return findByG_S(groupId, status, start, end, null);
6250            }
6251    
6252            /**
6253             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6254             *
6255             * <p>
6256             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6257             * </p>
6258             *
6259             * @param groupId the group ID
6260             * @param status the status
6261             * @param start the lower bound of the range of message-boards messages
6262             * @param end the upper bound of the range of message-boards messages (not inclusive)
6263             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6264             * @return the ordered range of matching message-boards messages
6265             */
6266            @Override
6267            public List<MBMessage> findByG_S(long groupId, int status, int start,
6268                    int end, OrderByComparator<MBMessage> orderByComparator) {
6269                    return findByG_S(groupId, status, start, end, orderByComparator, true);
6270            }
6271    
6272            /**
6273             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6274             *
6275             * <p>
6276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6277             * </p>
6278             *
6279             * @param groupId the group ID
6280             * @param status the status
6281             * @param start the lower bound of the range of message-boards messages
6282             * @param end the upper bound of the range of message-boards messages (not inclusive)
6283             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6284             * @param retrieveFromCache whether to retrieve from the finder cache
6285             * @return the ordered range of matching message-boards messages
6286             */
6287            @Override
6288            public List<MBMessage> findByG_S(long groupId, int status, int start,
6289                    int end, OrderByComparator<MBMessage> orderByComparator,
6290                    boolean retrieveFromCache) {
6291                    boolean pagination = true;
6292                    FinderPath finderPath = null;
6293                    Object[] finderArgs = null;
6294    
6295                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6296                                    (orderByComparator == null)) {
6297                            pagination = false;
6298                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6299                            finderArgs = new Object[] { groupId, status };
6300                    }
6301                    else {
6302                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6303                            finderArgs = new Object[] {
6304                                            groupId, status,
6305                                            
6306                                            start, end, orderByComparator
6307                                    };
6308                    }
6309    
6310                    List<MBMessage> list = null;
6311    
6312                    if (retrieveFromCache) {
6313                            list = (List<MBMessage>)finderCache.getResult(finderPath,
6314                                            finderArgs, this);
6315    
6316                            if ((list != null) && !list.isEmpty()) {
6317                                    for (MBMessage mbMessage : list) {
6318                                            if ((groupId != mbMessage.getGroupId()) ||
6319                                                            (status != mbMessage.getStatus())) {
6320                                                    list = null;
6321    
6322                                                    break;
6323                                            }
6324                                    }
6325                            }
6326                    }
6327    
6328                    if (list == null) {
6329                            StringBundler query = null;
6330    
6331                            if (orderByComparator != null) {
6332                                    query = new StringBundler(4 +
6333                                                    (orderByComparator.getOrderByFields().length * 2));
6334                            }
6335                            else {
6336                                    query = new StringBundler(4);
6337                            }
6338    
6339                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6340    
6341                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6342    
6343                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6344    
6345                            if (orderByComparator != null) {
6346                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6347                                            orderByComparator);
6348                            }
6349                            else
6350                             if (pagination) {
6351                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6352                            }
6353    
6354                            String sql = query.toString();
6355    
6356                            Session session = null;
6357    
6358                            try {
6359                                    session = openSession();
6360    
6361                                    Query q = session.createQuery(sql);
6362    
6363                                    QueryPos qPos = QueryPos.getInstance(q);
6364    
6365                                    qPos.add(groupId);
6366    
6367                                    qPos.add(status);
6368    
6369                                    if (!pagination) {
6370                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6371                                                            start, end, false);
6372    
6373                                            Collections.sort(list);
6374    
6375                                            list = Collections.unmodifiableList(list);
6376                                    }
6377                                    else {
6378                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6379                                                            start, end);
6380                                    }
6381    
6382                                    cacheResult(list);
6383    
6384                                    finderCache.putResult(finderPath, finderArgs, list);
6385                            }
6386                            catch (Exception e) {
6387                                    finderCache.removeResult(finderPath, finderArgs);
6388    
6389                                    throw processException(e);
6390                            }
6391                            finally {
6392                                    closeSession(session);
6393                            }
6394                    }
6395    
6396                    return list;
6397            }
6398    
6399            /**
6400             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6401             *
6402             * @param groupId the group ID
6403             * @param status the status
6404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6405             * @return the first matching message-boards message
6406             * @throws NoSuchMessageException if a matching message-boards message could not be found
6407             */
6408            @Override
6409            public MBMessage findByG_S_First(long groupId, int status,
6410                    OrderByComparator<MBMessage> orderByComparator)
6411                    throws NoSuchMessageException {
6412                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6413                                    orderByComparator);
6414    
6415                    if (mbMessage != null) {
6416                            return mbMessage;
6417                    }
6418    
6419                    StringBundler msg = new StringBundler(6);
6420    
6421                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6422    
6423                    msg.append("groupId=");
6424                    msg.append(groupId);
6425    
6426                    msg.append(", status=");
6427                    msg.append(status);
6428    
6429                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6430    
6431                    throw new NoSuchMessageException(msg.toString());
6432            }
6433    
6434            /**
6435             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6436             *
6437             * @param groupId the group ID
6438             * @param status the status
6439             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6440             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6441             */
6442            @Override
6443            public MBMessage fetchByG_S_First(long groupId, int status,
6444                    OrderByComparator<MBMessage> orderByComparator) {
6445                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6446                                    orderByComparator);
6447    
6448                    if (!list.isEmpty()) {
6449                            return list.get(0);
6450                    }
6451    
6452                    return null;
6453            }
6454    
6455            /**
6456             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6457             *
6458             * @param groupId the group ID
6459             * @param status the status
6460             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6461             * @return the last matching message-boards message
6462             * @throws NoSuchMessageException if a matching message-boards message could not be found
6463             */
6464            @Override
6465            public MBMessage findByG_S_Last(long groupId, int status,
6466                    OrderByComparator<MBMessage> orderByComparator)
6467                    throws NoSuchMessageException {
6468                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6469    
6470                    if (mbMessage != null) {
6471                            return mbMessage;
6472                    }
6473    
6474                    StringBundler msg = new StringBundler(6);
6475    
6476                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6477    
6478                    msg.append("groupId=");
6479                    msg.append(groupId);
6480    
6481                    msg.append(", status=");
6482                    msg.append(status);
6483    
6484                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6485    
6486                    throw new NoSuchMessageException(msg.toString());
6487            }
6488    
6489            /**
6490             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6491             *
6492             * @param groupId the group ID
6493             * @param status the status
6494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6495             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6496             */
6497            @Override
6498            public MBMessage fetchByG_S_Last(long groupId, int status,
6499                    OrderByComparator<MBMessage> orderByComparator) {
6500                    int count = countByG_S(groupId, status);
6501    
6502                    if (count == 0) {
6503                            return null;
6504                    }
6505    
6506                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6507                                    orderByComparator);
6508    
6509                    if (!list.isEmpty()) {
6510                            return list.get(0);
6511                    }
6512    
6513                    return null;
6514            }
6515    
6516            /**
6517             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6518             *
6519             * @param messageId the primary key of the current message-boards message
6520             * @param groupId the group ID
6521             * @param status the status
6522             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6523             * @return the previous, current, and next message-boards message
6524             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6525             */
6526            @Override
6527            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6528                    int status, OrderByComparator<MBMessage> orderByComparator)
6529                    throws NoSuchMessageException {
6530                    MBMessage mbMessage = findByPrimaryKey(messageId);
6531    
6532                    Session session = null;
6533    
6534                    try {
6535                            session = openSession();
6536    
6537                            MBMessage[] array = new MBMessageImpl[3];
6538    
6539                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6540                                            status, orderByComparator, true);
6541    
6542                            array[1] = mbMessage;
6543    
6544                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6545                                            status, orderByComparator, false);
6546    
6547                            return array;
6548                    }
6549                    catch (Exception e) {
6550                            throw processException(e);
6551                    }
6552                    finally {
6553                            closeSession(session);
6554                    }
6555            }
6556    
6557            protected MBMessage getByG_S_PrevAndNext(Session session,
6558                    MBMessage mbMessage, long groupId, int status,
6559                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6560                    StringBundler query = null;
6561    
6562                    if (orderByComparator != null) {
6563                            query = new StringBundler(5 +
6564                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6565                                            (orderByComparator.getOrderByFields().length * 3));
6566                    }
6567                    else {
6568                            query = new StringBundler(4);
6569                    }
6570    
6571                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6572    
6573                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6574    
6575                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6576    
6577                    if (orderByComparator != null) {
6578                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6579    
6580                            if (orderByConditionFields.length > 0) {
6581                                    query.append(WHERE_AND);
6582                            }
6583    
6584                            for (int i = 0; i < orderByConditionFields.length; i++) {
6585                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6586                                    query.append(orderByConditionFields[i]);
6587    
6588                                    if ((i + 1) < orderByConditionFields.length) {
6589                                            if (orderByComparator.isAscending() ^ previous) {
6590                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6591                                            }
6592                                            else {
6593                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6594                                            }
6595                                    }
6596                                    else {
6597                                            if (orderByComparator.isAscending() ^ previous) {
6598                                                    query.append(WHERE_GREATER_THAN);
6599                                            }
6600                                            else {
6601                                                    query.append(WHERE_LESSER_THAN);
6602                                            }
6603                                    }
6604                            }
6605    
6606                            query.append(ORDER_BY_CLAUSE);
6607    
6608                            String[] orderByFields = orderByComparator.getOrderByFields();
6609    
6610                            for (int i = 0; i < orderByFields.length; i++) {
6611                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6612                                    query.append(orderByFields[i]);
6613    
6614                                    if ((i + 1) < orderByFields.length) {
6615                                            if (orderByComparator.isAscending() ^ previous) {
6616                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6617                                            }
6618                                            else {
6619                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6620                                            }
6621                                    }
6622                                    else {
6623                                            if (orderByComparator.isAscending() ^ previous) {
6624                                                    query.append(ORDER_BY_ASC);
6625                                            }
6626                                            else {
6627                                                    query.append(ORDER_BY_DESC);
6628                                            }
6629                                    }
6630                            }
6631                    }
6632                    else {
6633                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6634                    }
6635    
6636                    String sql = query.toString();
6637    
6638                    Query q = session.createQuery(sql);
6639    
6640                    q.setFirstResult(0);
6641                    q.setMaxResults(2);
6642    
6643                    QueryPos qPos = QueryPos.getInstance(q);
6644    
6645                    qPos.add(groupId);
6646    
6647                    qPos.add(status);
6648    
6649                    if (orderByComparator != null) {
6650                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6651    
6652                            for (Object value : values) {
6653                                    qPos.add(value);
6654                            }
6655                    }
6656    
6657                    List<MBMessage> list = q.list();
6658    
6659                    if (list.size() == 2) {
6660                            return list.get(1);
6661                    }
6662                    else {
6663                            return null;
6664                    }
6665            }
6666    
6667            /**
6668             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6669             *
6670             * @param groupId the group ID
6671             * @param status the status
6672             * @return the matching message-boards messages that the user has permission to view
6673             */
6674            @Override
6675            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6676                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6677                            QueryUtil.ALL_POS, null);
6678            }
6679    
6680            /**
6681             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6682             *
6683             * <p>
6684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6685             * </p>
6686             *
6687             * @param groupId the group ID
6688             * @param status the status
6689             * @param start the lower bound of the range of message-boards messages
6690             * @param end the upper bound of the range of message-boards messages (not inclusive)
6691             * @return the range of matching message-boards messages that the user has permission to view
6692             */
6693            @Override
6694            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6695                    int end) {
6696                    return filterFindByG_S(groupId, status, start, end, null);
6697            }
6698    
6699            /**
6700             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6701             *
6702             * <p>
6703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6704             * </p>
6705             *
6706             * @param groupId the group ID
6707             * @param status the status
6708             * @param start the lower bound of the range of message-boards messages
6709             * @param end the upper bound of the range of message-boards messages (not inclusive)
6710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6711             * @return the ordered range of matching message-boards messages that the user has permission to view
6712             */
6713            @Override
6714            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6715                    int end, OrderByComparator<MBMessage> orderByComparator) {
6716                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6717                            return findByG_S(groupId, status, start, end, orderByComparator);
6718                    }
6719    
6720                    StringBundler query = null;
6721    
6722                    if (orderByComparator != null) {
6723                            query = new StringBundler(4 +
6724                                            (orderByComparator.getOrderByFields().length * 2));
6725                    }
6726                    else {
6727                            query = new StringBundler(5);
6728                    }
6729    
6730                    if (getDB().isSupportsInlineDistinct()) {
6731                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6732                    }
6733                    else {
6734                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6735                    }
6736    
6737                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6738    
6739                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6740    
6741                    if (!getDB().isSupportsInlineDistinct()) {
6742                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6743                    }
6744    
6745                    if (orderByComparator != null) {
6746                            if (getDB().isSupportsInlineDistinct()) {
6747                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6748                                            orderByComparator, true);
6749                            }
6750                            else {
6751                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6752                                            orderByComparator, true);
6753                            }
6754                    }
6755                    else {
6756                            if (getDB().isSupportsInlineDistinct()) {
6757                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6758                            }
6759                            else {
6760                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6761                            }
6762                    }
6763    
6764                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6765                                    MBMessage.class.getName(),
6766                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6767    
6768                    Session session = null;
6769    
6770                    try {
6771                            session = openSession();
6772    
6773                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6774    
6775                            if (getDB().isSupportsInlineDistinct()) {
6776                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6777                            }
6778                            else {
6779                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6780                            }
6781    
6782                            QueryPos qPos = QueryPos.getInstance(q);
6783    
6784                            qPos.add(groupId);
6785    
6786                            qPos.add(status);
6787    
6788                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6789                    }
6790                    catch (Exception e) {
6791                            throw processException(e);
6792                    }
6793                    finally {
6794                            closeSession(session);
6795                    }
6796            }
6797    
6798            /**
6799             * 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;.
6800             *
6801             * @param messageId the primary key of the current message-boards message
6802             * @param groupId the group ID
6803             * @param status the status
6804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6805             * @return the previous, current, and next message-boards message
6806             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6807             */
6808            @Override
6809            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6810                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6811                    throws NoSuchMessageException {
6812                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6813                            return findByG_S_PrevAndNext(messageId, groupId, status,
6814                                    orderByComparator);
6815                    }
6816    
6817                    MBMessage mbMessage = findByPrimaryKey(messageId);
6818    
6819                    Session session = null;
6820    
6821                    try {
6822                            session = openSession();
6823    
6824                            MBMessage[] array = new MBMessageImpl[3];
6825    
6826                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6827                                            status, orderByComparator, true);
6828    
6829                            array[1] = mbMessage;
6830    
6831                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6832                                            status, orderByComparator, false);
6833    
6834                            return array;
6835                    }
6836                    catch (Exception e) {
6837                            throw processException(e);
6838                    }
6839                    finally {
6840                            closeSession(session);
6841                    }
6842            }
6843    
6844            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6845                    MBMessage mbMessage, long groupId, int status,
6846                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6847                    StringBundler query = null;
6848    
6849                    if (orderByComparator != null) {
6850                            query = new StringBundler(6 +
6851                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6852                                            (orderByComparator.getOrderByFields().length * 3));
6853                    }
6854                    else {
6855                            query = new StringBundler(5);
6856                    }
6857    
6858                    if (getDB().isSupportsInlineDistinct()) {
6859                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6860                    }
6861                    else {
6862                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6863                    }
6864    
6865                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6866    
6867                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6868    
6869                    if (!getDB().isSupportsInlineDistinct()) {
6870                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6871                    }
6872    
6873                    if (orderByComparator != null) {
6874                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6875    
6876                            if (orderByConditionFields.length > 0) {
6877                                    query.append(WHERE_AND);
6878                            }
6879    
6880                            for (int i = 0; i < orderByConditionFields.length; i++) {
6881                                    if (getDB().isSupportsInlineDistinct()) {
6882                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6883                                    }
6884                                    else {
6885                                            query.append(_ORDER_BY_ENTITY_TABLE);
6886                                    }
6887    
6888                                    query.append(orderByConditionFields[i]);
6889    
6890                                    if ((i + 1) < orderByConditionFields.length) {
6891                                            if (orderByComparator.isAscending() ^ previous) {
6892                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6893                                            }
6894                                            else {
6895                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6896                                            }
6897                                    }
6898                                    else {
6899                                            if (orderByComparator.isAscending() ^ previous) {
6900                                                    query.append(WHERE_GREATER_THAN);
6901                                            }
6902                                            else {
6903                                                    query.append(WHERE_LESSER_THAN);
6904                                            }
6905                                    }
6906                            }
6907    
6908                            query.append(ORDER_BY_CLAUSE);
6909    
6910                            String[] orderByFields = orderByComparator.getOrderByFields();
6911    
6912                            for (int i = 0; i < orderByFields.length; i++) {
6913                                    if (getDB().isSupportsInlineDistinct()) {
6914                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6915                                    }
6916                                    else {
6917                                            query.append(_ORDER_BY_ENTITY_TABLE);
6918                                    }
6919    
6920                                    query.append(orderByFields[i]);
6921    
6922                                    if ((i + 1) < orderByFields.length) {
6923                                            if (orderByComparator.isAscending() ^ previous) {
6924                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6925                                            }
6926                                            else {
6927                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6928                                            }
6929                                    }
6930                                    else {
6931                                            if (orderByComparator.isAscending() ^ previous) {
6932                                                    query.append(ORDER_BY_ASC);
6933                                            }
6934                                            else {
6935                                                    query.append(ORDER_BY_DESC);
6936                                            }
6937                                    }
6938                            }
6939                    }
6940                    else {
6941                            if (getDB().isSupportsInlineDistinct()) {
6942                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6943                            }
6944                            else {
6945                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6946                            }
6947                    }
6948    
6949                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6950                                    MBMessage.class.getName(),
6951                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6952    
6953                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6954    
6955                    q.setFirstResult(0);
6956                    q.setMaxResults(2);
6957    
6958                    if (getDB().isSupportsInlineDistinct()) {
6959                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6960                    }
6961                    else {
6962                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6963                    }
6964    
6965                    QueryPos qPos = QueryPos.getInstance(q);
6966    
6967                    qPos.add(groupId);
6968    
6969                    qPos.add(status);
6970    
6971                    if (orderByComparator != null) {
6972                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6973    
6974                            for (Object value : values) {
6975                                    qPos.add(value);
6976                            }
6977                    }
6978    
6979                    List<MBMessage> list = q.list();
6980    
6981                    if (list.size() == 2) {
6982                            return list.get(1);
6983                    }
6984                    else {
6985                            return null;
6986                    }
6987            }
6988    
6989            /**
6990             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6991             *
6992             * @param groupId the group ID
6993             * @param status the status
6994             */
6995            @Override
6996            public void removeByG_S(long groupId, int status) {
6997                    for (MBMessage mbMessage : findByG_S(groupId, status,
6998                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6999                            remove(mbMessage);
7000                    }
7001            }
7002    
7003            /**
7004             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
7005             *
7006             * @param groupId the group ID
7007             * @param status the status
7008             * @return the number of matching message-boards messages
7009             */
7010            @Override
7011            public int countByG_S(long groupId, int status) {
7012                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
7013    
7014                    Object[] finderArgs = new Object[] { groupId, status };
7015    
7016                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7017    
7018                    if (count == null) {
7019                            StringBundler query = new StringBundler(3);
7020    
7021                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7022    
7023                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7024    
7025                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
7026    
7027                            String sql = query.toString();
7028    
7029                            Session session = null;
7030    
7031                            try {
7032                                    session = openSession();
7033    
7034                                    Query q = session.createQuery(sql);
7035    
7036                                    QueryPos qPos = QueryPos.getInstance(q);
7037    
7038                                    qPos.add(groupId);
7039    
7040                                    qPos.add(status);
7041    
7042                                    count = (Long)q.uniqueResult();
7043    
7044                                    finderCache.putResult(finderPath, finderArgs, count);
7045                            }
7046                            catch (Exception e) {
7047                                    finderCache.removeResult(finderPath, finderArgs);
7048    
7049                                    throw processException(e);
7050                            }
7051                            finally {
7052                                    closeSession(session);
7053                            }
7054                    }
7055    
7056                    return count.intValue();
7057            }
7058    
7059            /**
7060             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
7061             *
7062             * @param groupId the group ID
7063             * @param status the status
7064             * @return the number of matching message-boards messages that the user has permission to view
7065             */
7066            @Override
7067            public int filterCountByG_S(long groupId, int status) {
7068                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7069                            return countByG_S(groupId, status);
7070                    }
7071    
7072                    StringBundler query = new StringBundler(3);
7073    
7074                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
7075    
7076                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7077    
7078                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
7079    
7080                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7081                                    MBMessage.class.getName(),
7082                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7083    
7084                    Session session = null;
7085    
7086                    try {
7087                            session = openSession();
7088    
7089                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7090    
7091                            q.addScalar(COUNT_COLUMN_NAME,
7092                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7093    
7094                            QueryPos qPos = QueryPos.getInstance(q);
7095    
7096                            qPos.add(groupId);
7097    
7098                            qPos.add(status);
7099    
7100                            Long count = (Long)q.uniqueResult();
7101    
7102                            return count.intValue();
7103                    }
7104                    catch (Exception e) {
7105                            throw processException(e);
7106                    }
7107                    finally {
7108                            closeSession(session);
7109                    }
7110            }
7111    
7112            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
7113            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7114            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7116                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7117                            new String[] {
7118                                    Long.class.getName(), Integer.class.getName(),
7119                                    
7120                            Integer.class.getName(), Integer.class.getName(),
7121                                    OrderByComparator.class.getName()
7122                            });
7123            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7124                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7126                            new String[] { Long.class.getName(), Integer.class.getName() },
7127                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7128                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7129                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7130            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7131                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7132                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7133                            new String[] { Long.class.getName(), Integer.class.getName() });
7134    
7135            /**
7136             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7137             *
7138             * @param companyId the company ID
7139             * @param status the status
7140             * @return the matching message-boards messages
7141             */
7142            @Override
7143            public List<MBMessage> findByC_S(long companyId, int status) {
7144                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7145                            QueryUtil.ALL_POS, null);
7146            }
7147    
7148            /**
7149             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7150             *
7151             * <p>
7152             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7153             * </p>
7154             *
7155             * @param companyId the company ID
7156             * @param status the status
7157             * @param start the lower bound of the range of message-boards messages
7158             * @param end the upper bound of the range of message-boards messages (not inclusive)
7159             * @return the range of matching message-boards messages
7160             */
7161            @Override
7162            public List<MBMessage> findByC_S(long companyId, int status, int start,
7163                    int end) {
7164                    return findByC_S(companyId, status, start, end, null);
7165            }
7166    
7167            /**
7168             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7169             *
7170             * <p>
7171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7172             * </p>
7173             *
7174             * @param companyId the company ID
7175             * @param status the status
7176             * @param start the lower bound of the range of message-boards messages
7177             * @param end the upper bound of the range of message-boards messages (not inclusive)
7178             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7179             * @return the ordered range of matching message-boards messages
7180             */
7181            @Override
7182            public List<MBMessage> findByC_S(long companyId, int status, int start,
7183                    int end, OrderByComparator<MBMessage> orderByComparator) {
7184                    return findByC_S(companyId, status, start, end, orderByComparator, true);
7185            }
7186    
7187            /**
7188             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7189             *
7190             * <p>
7191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7192             * </p>
7193             *
7194             * @param companyId the company ID
7195             * @param status the status
7196             * @param start the lower bound of the range of message-boards messages
7197             * @param end the upper bound of the range of message-boards messages (not inclusive)
7198             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7199             * @param retrieveFromCache whether to retrieve from the finder cache
7200             * @return the ordered range of matching message-boards messages
7201             */
7202            @Override
7203            public List<MBMessage> findByC_S(long companyId, int status, int start,
7204                    int end, OrderByComparator<MBMessage> orderByComparator,
7205                    boolean retrieveFromCache) {
7206                    boolean pagination = true;
7207                    FinderPath finderPath = null;
7208                    Object[] finderArgs = null;
7209    
7210                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7211                                    (orderByComparator == null)) {
7212                            pagination = false;
7213                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7214                            finderArgs = new Object[] { companyId, status };
7215                    }
7216                    else {
7217                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7218                            finderArgs = new Object[] {
7219                                            companyId, status,
7220                                            
7221                                            start, end, orderByComparator
7222                                    };
7223                    }
7224    
7225                    List<MBMessage> list = null;
7226    
7227                    if (retrieveFromCache) {
7228                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7229                                            finderArgs, this);
7230    
7231                            if ((list != null) && !list.isEmpty()) {
7232                                    for (MBMessage mbMessage : list) {
7233                                            if ((companyId != mbMessage.getCompanyId()) ||
7234                                                            (status != mbMessage.getStatus())) {
7235                                                    list = null;
7236    
7237                                                    break;
7238                                            }
7239                                    }
7240                            }
7241                    }
7242    
7243                    if (list == null) {
7244                            StringBundler query = null;
7245    
7246                            if (orderByComparator != null) {
7247                                    query = new StringBundler(4 +
7248                                                    (orderByComparator.getOrderByFields().length * 2));
7249                            }
7250                            else {
7251                                    query = new StringBundler(4);
7252                            }
7253    
7254                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7255    
7256                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7257    
7258                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7259    
7260                            if (orderByComparator != null) {
7261                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7262                                            orderByComparator);
7263                            }
7264                            else
7265                             if (pagination) {
7266                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7267                            }
7268    
7269                            String sql = query.toString();
7270    
7271                            Session session = null;
7272    
7273                            try {
7274                                    session = openSession();
7275    
7276                                    Query q = session.createQuery(sql);
7277    
7278                                    QueryPos qPos = QueryPos.getInstance(q);
7279    
7280                                    qPos.add(companyId);
7281    
7282                                    qPos.add(status);
7283    
7284                                    if (!pagination) {
7285                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7286                                                            start, end, false);
7287    
7288                                            Collections.sort(list);
7289    
7290                                            list = Collections.unmodifiableList(list);
7291                                    }
7292                                    else {
7293                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7294                                                            start, end);
7295                                    }
7296    
7297                                    cacheResult(list);
7298    
7299                                    finderCache.putResult(finderPath, finderArgs, list);
7300                            }
7301                            catch (Exception e) {
7302                                    finderCache.removeResult(finderPath, finderArgs);
7303    
7304                                    throw processException(e);
7305                            }
7306                            finally {
7307                                    closeSession(session);
7308                            }
7309                    }
7310    
7311                    return list;
7312            }
7313    
7314            /**
7315             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7316             *
7317             * @param companyId the company ID
7318             * @param status the status
7319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7320             * @return the first matching message-boards message
7321             * @throws NoSuchMessageException if a matching message-boards message could not be found
7322             */
7323            @Override
7324            public MBMessage findByC_S_First(long companyId, int status,
7325                    OrderByComparator<MBMessage> orderByComparator)
7326                    throws NoSuchMessageException {
7327                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7328                                    orderByComparator);
7329    
7330                    if (mbMessage != null) {
7331                            return mbMessage;
7332                    }
7333    
7334                    StringBundler msg = new StringBundler(6);
7335    
7336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7337    
7338                    msg.append("companyId=");
7339                    msg.append(companyId);
7340    
7341                    msg.append(", status=");
7342                    msg.append(status);
7343    
7344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7345    
7346                    throw new NoSuchMessageException(msg.toString());
7347            }
7348    
7349            /**
7350             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7351             *
7352             * @param companyId the company ID
7353             * @param status the status
7354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7355             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7356             */
7357            @Override
7358            public MBMessage fetchByC_S_First(long companyId, int status,
7359                    OrderByComparator<MBMessage> orderByComparator) {
7360                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7361                                    orderByComparator);
7362    
7363                    if (!list.isEmpty()) {
7364                            return list.get(0);
7365                    }
7366    
7367                    return null;
7368            }
7369    
7370            /**
7371             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7372             *
7373             * @param companyId the company ID
7374             * @param status the status
7375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7376             * @return the last matching message-boards message
7377             * @throws NoSuchMessageException if a matching message-boards message could not be found
7378             */
7379            @Override
7380            public MBMessage findByC_S_Last(long companyId, int status,
7381                    OrderByComparator<MBMessage> orderByComparator)
7382                    throws NoSuchMessageException {
7383                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7384                                    orderByComparator);
7385    
7386                    if (mbMessage != null) {
7387                            return mbMessage;
7388                    }
7389    
7390                    StringBundler msg = new StringBundler(6);
7391    
7392                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7393    
7394                    msg.append("companyId=");
7395                    msg.append(companyId);
7396    
7397                    msg.append(", status=");
7398                    msg.append(status);
7399    
7400                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7401    
7402                    throw new NoSuchMessageException(msg.toString());
7403            }
7404    
7405            /**
7406             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7407             *
7408             * @param companyId the company ID
7409             * @param status the status
7410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7411             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7412             */
7413            @Override
7414            public MBMessage fetchByC_S_Last(long companyId, int status,
7415                    OrderByComparator<MBMessage> orderByComparator) {
7416                    int count = countByC_S(companyId, status);
7417    
7418                    if (count == 0) {
7419                            return null;
7420                    }
7421    
7422                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7423                                    orderByComparator);
7424    
7425                    if (!list.isEmpty()) {
7426                            return list.get(0);
7427                    }
7428    
7429                    return null;
7430            }
7431    
7432            /**
7433             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7434             *
7435             * @param messageId the primary key of the current message-boards message
7436             * @param companyId the company ID
7437             * @param status the status
7438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7439             * @return the previous, current, and next message-boards message
7440             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7441             */
7442            @Override
7443            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7444                    int status, OrderByComparator<MBMessage> orderByComparator)
7445                    throws NoSuchMessageException {
7446                    MBMessage mbMessage = findByPrimaryKey(messageId);
7447    
7448                    Session session = null;
7449    
7450                    try {
7451                            session = openSession();
7452    
7453                            MBMessage[] array = new MBMessageImpl[3];
7454    
7455                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7456                                            status, orderByComparator, true);
7457    
7458                            array[1] = mbMessage;
7459    
7460                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7461                                            status, orderByComparator, false);
7462    
7463                            return array;
7464                    }
7465                    catch (Exception e) {
7466                            throw processException(e);
7467                    }
7468                    finally {
7469                            closeSession(session);
7470                    }
7471            }
7472    
7473            protected MBMessage getByC_S_PrevAndNext(Session session,
7474                    MBMessage mbMessage, long companyId, int status,
7475                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7476                    StringBundler query = null;
7477    
7478                    if (orderByComparator != null) {
7479                            query = new StringBundler(5 +
7480                                            (orderByComparator.getOrderByConditionFields().length * 3) +
7481                                            (orderByComparator.getOrderByFields().length * 3));
7482                    }
7483                    else {
7484                            query = new StringBundler(4);
7485                    }
7486    
7487                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7488    
7489                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7490    
7491                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7492    
7493                    if (orderByComparator != null) {
7494                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7495    
7496                            if (orderByConditionFields.length > 0) {
7497                                    query.append(WHERE_AND);
7498                            }
7499    
7500                            for (int i = 0; i < orderByConditionFields.length; i++) {
7501                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7502                                    query.append(orderByConditionFields[i]);
7503    
7504                                    if ((i + 1) < orderByConditionFields.length) {
7505                                            if (orderByComparator.isAscending() ^ previous) {
7506                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7507                                            }
7508                                            else {
7509                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7510                                            }
7511                                    }
7512                                    else {
7513                                            if (orderByComparator.isAscending() ^ previous) {
7514                                                    query.append(WHERE_GREATER_THAN);
7515                                            }
7516                                            else {
7517                                                    query.append(WHERE_LESSER_THAN);
7518                                            }
7519                                    }
7520                            }
7521    
7522                            query.append(ORDER_BY_CLAUSE);
7523    
7524                            String[] orderByFields = orderByComparator.getOrderByFields();
7525    
7526                            for (int i = 0; i < orderByFields.length; i++) {
7527                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7528                                    query.append(orderByFields[i]);
7529    
7530                                    if ((i + 1) < orderByFields.length) {
7531                                            if (orderByComparator.isAscending() ^ previous) {
7532                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7533                                            }
7534                                            else {
7535                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7536                                            }
7537                                    }
7538                                    else {
7539                                            if (orderByComparator.isAscending() ^ previous) {
7540                                                    query.append(ORDER_BY_ASC);
7541                                            }
7542                                            else {
7543                                                    query.append(ORDER_BY_DESC);
7544                                            }
7545                                    }
7546                            }
7547                    }
7548                    else {
7549                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7550                    }
7551    
7552                    String sql = query.toString();
7553    
7554                    Query q = session.createQuery(sql);
7555    
7556                    q.setFirstResult(0);
7557                    q.setMaxResults(2);
7558    
7559                    QueryPos qPos = QueryPos.getInstance(q);
7560    
7561                    qPos.add(companyId);
7562    
7563                    qPos.add(status);
7564    
7565                    if (orderByComparator != null) {
7566                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7567    
7568                            for (Object value : values) {
7569                                    qPos.add(value);
7570                            }
7571                    }
7572    
7573                    List<MBMessage> list = q.list();
7574    
7575                    if (list.size() == 2) {
7576                            return list.get(1);
7577                    }
7578                    else {
7579                            return null;
7580                    }
7581            }
7582    
7583            /**
7584             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7585             *
7586             * @param companyId the company ID
7587             * @param status the status
7588             */
7589            @Override
7590            public void removeByC_S(long companyId, int status) {
7591                    for (MBMessage mbMessage : findByC_S(companyId, status,
7592                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7593                            remove(mbMessage);
7594                    }
7595            }
7596    
7597            /**
7598             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7599             *
7600             * @param companyId the company ID
7601             * @param status the status
7602             * @return the number of matching message-boards messages
7603             */
7604            @Override
7605            public int countByC_S(long companyId, int status) {
7606                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7607    
7608                    Object[] finderArgs = new Object[] { companyId, status };
7609    
7610                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7611    
7612                    if (count == null) {
7613                            StringBundler query = new StringBundler(3);
7614    
7615                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7616    
7617                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7618    
7619                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7620    
7621                            String sql = query.toString();
7622    
7623                            Session session = null;
7624    
7625                            try {
7626                                    session = openSession();
7627    
7628                                    Query q = session.createQuery(sql);
7629    
7630                                    QueryPos qPos = QueryPos.getInstance(q);
7631    
7632                                    qPos.add(companyId);
7633    
7634                                    qPos.add(status);
7635    
7636                                    count = (Long)q.uniqueResult();
7637    
7638                                    finderCache.putResult(finderPath, finderArgs, count);
7639                            }
7640                            catch (Exception e) {
7641                                    finderCache.removeResult(finderPath, finderArgs);
7642    
7643                                    throw processException(e);
7644                            }
7645                            finally {
7646                                    closeSession(session);
7647                            }
7648                    }
7649    
7650                    return count.intValue();
7651            }
7652    
7653            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7654            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7655            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7656                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7657                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7658                            new String[] {
7659                                    Long.class.getName(), Long.class.getName(),
7660                                    
7661                            Integer.class.getName(), Integer.class.getName(),
7662                                    OrderByComparator.class.getName()
7663                            });
7664            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7665                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7666                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7667                            new String[] { Long.class.getName(), Long.class.getName() },
7668                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7669                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7670                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7671            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7672                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7673                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7674                            new String[] { Long.class.getName(), Long.class.getName() });
7675            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7676                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7677                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7678                            new String[] { Long.class.getName(), Long.class.getName() });
7679    
7680            /**
7681             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7682             *
7683             * @param userId the user ID
7684             * @param classNameId the class name ID
7685             * @return the matching message-boards messages
7686             */
7687            @Override
7688            public List<MBMessage> findByU_C(long userId, long classNameId) {
7689                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7690                            QueryUtil.ALL_POS, null);
7691            }
7692    
7693            /**
7694             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7695             *
7696             * <p>
7697             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7698             * </p>
7699             *
7700             * @param userId the user ID
7701             * @param classNameId the class name ID
7702             * @param start the lower bound of the range of message-boards messages
7703             * @param end the upper bound of the range of message-boards messages (not inclusive)
7704             * @return the range of matching message-boards messages
7705             */
7706            @Override
7707            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7708                    int end) {
7709                    return findByU_C(userId, classNameId, start, end, null);
7710            }
7711    
7712            /**
7713             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7714             *
7715             * <p>
7716             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7717             * </p>
7718             *
7719             * @param userId the user ID
7720             * @param classNameId the class name ID
7721             * @param start the lower bound of the range of message-boards messages
7722             * @param end the upper bound of the range of message-boards messages (not inclusive)
7723             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7724             * @return the ordered range of matching message-boards messages
7725             */
7726            @Override
7727            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7728                    int end, OrderByComparator<MBMessage> orderByComparator) {
7729                    return findByU_C(userId, classNameId, start, end, orderByComparator,
7730                            true);
7731            }
7732    
7733            /**
7734             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7735             *
7736             * <p>
7737             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7738             * </p>
7739             *
7740             * @param userId the user ID
7741             * @param classNameId the class name ID
7742             * @param start the lower bound of the range of message-boards messages
7743             * @param end the upper bound of the range of message-boards messages (not inclusive)
7744             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7745             * @param retrieveFromCache whether to retrieve from the finder cache
7746             * @return the ordered range of matching message-boards messages
7747             */
7748            @Override
7749            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7750                    int end, OrderByComparator<MBMessage> orderByComparator,
7751                    boolean retrieveFromCache) {
7752                    boolean pagination = true;
7753                    FinderPath finderPath = null;
7754                    Object[] finderArgs = null;
7755    
7756                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7757                                    (orderByComparator == null)) {
7758                            pagination = false;
7759                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7760                            finderArgs = new Object[] { userId, classNameId };
7761                    }
7762                    else {
7763                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7764                            finderArgs = new Object[] {
7765                                            userId, classNameId,
7766                                            
7767                                            start, end, orderByComparator
7768                                    };
7769                    }
7770    
7771                    List<MBMessage> list = null;
7772    
7773                    if (retrieveFromCache) {
7774                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7775                                            finderArgs, this);
7776    
7777                            if ((list != null) && !list.isEmpty()) {
7778                                    for (MBMessage mbMessage : list) {
7779                                            if ((userId != mbMessage.getUserId()) ||
7780                                                            (classNameId != mbMessage.getClassNameId())) {
7781                                                    list = null;
7782    
7783                                                    break;
7784                                            }
7785                                    }
7786                            }
7787                    }
7788    
7789                    if (list == null) {
7790                            StringBundler query = null;
7791    
7792                            if (orderByComparator != null) {
7793                                    query = new StringBundler(4 +
7794                                                    (orderByComparator.getOrderByFields().length * 2));
7795                            }
7796                            else {
7797                                    query = new StringBundler(4);
7798                            }
7799    
7800                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7801    
7802                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7803    
7804                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7805    
7806                            if (orderByComparator != null) {
7807                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7808                                            orderByComparator);
7809                            }
7810                            else
7811                             if (pagination) {
7812                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7813                            }
7814    
7815                            String sql = query.toString();
7816    
7817                            Session session = null;
7818    
7819                            try {
7820                                    session = openSession();
7821    
7822                                    Query q = session.createQuery(sql);
7823    
7824                                    QueryPos qPos = QueryPos.getInstance(q);
7825    
7826                                    qPos.add(userId);
7827    
7828                                    qPos.add(classNameId);
7829    
7830                                    if (!pagination) {
7831                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7832                                                            start, end, false);
7833    
7834                                            Collections.sort(list);
7835    
7836                                            list = Collections.unmodifiableList(list);
7837                                    }
7838                                    else {
7839                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7840                                                            start, end);
7841                                    }
7842    
7843                                    cacheResult(list);
7844    
7845                                    finderCache.putResult(finderPath, finderArgs, list);
7846                            }
7847                            catch (Exception e) {
7848                                    finderCache.removeResult(finderPath, finderArgs);
7849    
7850                                    throw processException(e);
7851                            }
7852                            finally {
7853                                    closeSession(session);
7854                            }
7855                    }
7856    
7857                    return list;
7858            }
7859    
7860            /**
7861             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7862             *
7863             * @param userId the user ID
7864             * @param classNameId the class name ID
7865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7866             * @return the first matching message-boards message
7867             * @throws NoSuchMessageException if a matching message-boards message could not be found
7868             */
7869            @Override
7870            public MBMessage findByU_C_First(long userId, long classNameId,
7871                    OrderByComparator<MBMessage> orderByComparator)
7872                    throws NoSuchMessageException {
7873                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7874                                    orderByComparator);
7875    
7876                    if (mbMessage != null) {
7877                            return mbMessage;
7878                    }
7879    
7880                    StringBundler msg = new StringBundler(6);
7881    
7882                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7883    
7884                    msg.append("userId=");
7885                    msg.append(userId);
7886    
7887                    msg.append(", classNameId=");
7888                    msg.append(classNameId);
7889    
7890                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7891    
7892                    throw new NoSuchMessageException(msg.toString());
7893            }
7894    
7895            /**
7896             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7897             *
7898             * @param userId the user ID
7899             * @param classNameId the class name ID
7900             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7901             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7902             */
7903            @Override
7904            public MBMessage fetchByU_C_First(long userId, long classNameId,
7905                    OrderByComparator<MBMessage> orderByComparator) {
7906                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7907                                    orderByComparator);
7908    
7909                    if (!list.isEmpty()) {
7910                            return list.get(0);
7911                    }
7912    
7913                    return null;
7914            }
7915    
7916            /**
7917             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7918             *
7919             * @param userId the user ID
7920             * @param classNameId the class name ID
7921             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7922             * @return the last matching message-boards message
7923             * @throws NoSuchMessageException if a matching message-boards message could not be found
7924             */
7925            @Override
7926            public MBMessage findByU_C_Last(long userId, long classNameId,
7927                    OrderByComparator<MBMessage> orderByComparator)
7928                    throws NoSuchMessageException {
7929                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7930                                    orderByComparator);
7931    
7932                    if (mbMessage != null) {
7933                            return mbMessage;
7934                    }
7935    
7936                    StringBundler msg = new StringBundler(6);
7937    
7938                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7939    
7940                    msg.append("userId=");
7941                    msg.append(userId);
7942    
7943                    msg.append(", classNameId=");
7944                    msg.append(classNameId);
7945    
7946                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7947    
7948                    throw new NoSuchMessageException(msg.toString());
7949            }
7950    
7951            /**
7952             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7953             *
7954             * @param userId the user ID
7955             * @param classNameId the class name ID
7956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7957             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7958             */
7959            @Override
7960            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7961                    OrderByComparator<MBMessage> orderByComparator) {
7962                    int count = countByU_C(userId, classNameId);
7963    
7964                    if (count == 0) {
7965                            return null;
7966                    }
7967    
7968                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7969                                    orderByComparator);
7970    
7971                    if (!list.isEmpty()) {
7972                            return list.get(0);
7973                    }
7974    
7975                    return null;
7976            }
7977    
7978            /**
7979             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7980             *
7981             * @param messageId the primary key of the current message-boards message
7982             * @param userId the user ID
7983             * @param classNameId the class name ID
7984             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7985             * @return the previous, current, and next message-boards message
7986             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7987             */
7988            @Override
7989            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7990                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7991                    throws NoSuchMessageException {
7992                    MBMessage mbMessage = findByPrimaryKey(messageId);
7993    
7994                    Session session = null;
7995    
7996                    try {
7997                            session = openSession();
7998    
7999                            MBMessage[] array = new MBMessageImpl[3];
8000    
8001                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
8002                                            classNameId, orderByComparator, true);
8003    
8004                            array[1] = mbMessage;
8005    
8006                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
8007                                            classNameId, orderByComparator, false);
8008    
8009                            return array;
8010                    }
8011                    catch (Exception e) {
8012                            throw processException(e);
8013                    }
8014                    finally {
8015                            closeSession(session);
8016                    }
8017            }
8018    
8019            protected MBMessage getByU_C_PrevAndNext(Session session,
8020                    MBMessage mbMessage, long userId, long classNameId,
8021                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8022                    StringBundler query = null;
8023    
8024                    if (orderByComparator != null) {
8025                            query = new StringBundler(5 +
8026                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8027                                            (orderByComparator.getOrderByFields().length * 3));
8028                    }
8029                    else {
8030                            query = new StringBundler(4);
8031                    }
8032    
8033                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8034    
8035                    query.append(_FINDER_COLUMN_U_C_USERID_2);
8036    
8037                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8038    
8039                    if (orderByComparator != null) {
8040                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8041    
8042                            if (orderByConditionFields.length > 0) {
8043                                    query.append(WHERE_AND);
8044                            }
8045    
8046                            for (int i = 0; i < orderByConditionFields.length; i++) {
8047                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8048                                    query.append(orderByConditionFields[i]);
8049    
8050                                    if ((i + 1) < orderByConditionFields.length) {
8051                                            if (orderByComparator.isAscending() ^ previous) {
8052                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8053                                            }
8054                                            else {
8055                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8056                                            }
8057                                    }
8058                                    else {
8059                                            if (orderByComparator.isAscending() ^ previous) {
8060                                                    query.append(WHERE_GREATER_THAN);
8061                                            }
8062                                            else {
8063                                                    query.append(WHERE_LESSER_THAN);
8064                                            }
8065                                    }
8066                            }
8067    
8068                            query.append(ORDER_BY_CLAUSE);
8069    
8070                            String[] orderByFields = orderByComparator.getOrderByFields();
8071    
8072                            for (int i = 0; i < orderByFields.length; i++) {
8073                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8074                                    query.append(orderByFields[i]);
8075    
8076                                    if ((i + 1) < orderByFields.length) {
8077                                            if (orderByComparator.isAscending() ^ previous) {
8078                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8079                                            }
8080                                            else {
8081                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8082                                            }
8083                                    }
8084                                    else {
8085                                            if (orderByComparator.isAscending() ^ previous) {
8086                                                    query.append(ORDER_BY_ASC);
8087                                            }
8088                                            else {
8089                                                    query.append(ORDER_BY_DESC);
8090                                            }
8091                                    }
8092                            }
8093                    }
8094                    else {
8095                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8096                    }
8097    
8098                    String sql = query.toString();
8099    
8100                    Query q = session.createQuery(sql);
8101    
8102                    q.setFirstResult(0);
8103                    q.setMaxResults(2);
8104    
8105                    QueryPos qPos = QueryPos.getInstance(q);
8106    
8107                    qPos.add(userId);
8108    
8109                    qPos.add(classNameId);
8110    
8111                    if (orderByComparator != null) {
8112                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8113    
8114                            for (Object value : values) {
8115                                    qPos.add(value);
8116                            }
8117                    }
8118    
8119                    List<MBMessage> list = q.list();
8120    
8121                    if (list.size() == 2) {
8122                            return list.get(1);
8123                    }
8124                    else {
8125                            return null;
8126                    }
8127            }
8128    
8129            /**
8130             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8131             *
8132             * <p>
8133             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8134             * </p>
8135             *
8136             * @param userId the user ID
8137             * @param classNameIds the class name IDs
8138             * @return the matching message-boards messages
8139             */
8140            @Override
8141            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
8142                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
8143                            QueryUtil.ALL_POS, null);
8144            }
8145    
8146            /**
8147             * Returns a 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             * @return the range of matching message-boards messages
8158             */
8159            @Override
8160            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8161                    int start, int end) {
8162                    return findByU_C(userId, classNameIds, start, end, null);
8163            }
8164    
8165            /**
8166             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8167             *
8168             * <p>
8169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8170             * </p>
8171             *
8172             * @param userId the user ID
8173             * @param classNameIds the class name IDs
8174             * @param start the lower bound of the range of message-boards messages
8175             * @param end the upper bound of the range of message-boards messages (not inclusive)
8176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8177             * @return the ordered range of matching message-boards messages
8178             */
8179            @Override
8180            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8181                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8182                    return findByU_C(userId, classNameIds, start, end, orderByComparator,
8183                            true);
8184            }
8185    
8186            /**
8187             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;, optionally using the finder cache.
8188             *
8189             * <p>
8190             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8191             * </p>
8192             *
8193             * @param userId the user ID
8194             * @param classNameId the class name ID
8195             * @param start the lower bound of the range of message-boards messages
8196             * @param end the upper bound of the range of message-boards messages (not inclusive)
8197             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8198             * @param retrieveFromCache whether to retrieve from the finder cache
8199             * @return the ordered range of matching message-boards messages
8200             */
8201            @Override
8202            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8203                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
8204                    boolean retrieveFromCache) {
8205                    if (classNameIds == null) {
8206                            classNameIds = new long[0];
8207                    }
8208                    else if (classNameIds.length > 1) {
8209                            classNameIds = ArrayUtil.unique(classNameIds);
8210    
8211                            Arrays.sort(classNameIds);
8212                    }
8213    
8214                    if (classNameIds.length == 1) {
8215                            return findByU_C(userId, classNameIds[0], start, end,
8216                                    orderByComparator);
8217                    }
8218    
8219                    boolean pagination = true;
8220                    Object[] finderArgs = null;
8221    
8222                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8223                                    (orderByComparator == null)) {
8224                            pagination = false;
8225                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8226                    }
8227                    else {
8228                            finderArgs = new Object[] {
8229                                            userId, StringUtil.merge(classNameIds),
8230                                            
8231                                            start, end, orderByComparator
8232                                    };
8233                    }
8234    
8235                    List<MBMessage> list = null;
8236    
8237                    if (retrieveFromCache) {
8238                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8239                                            finderArgs, this);
8240    
8241                            if ((list != null) && !list.isEmpty()) {
8242                                    for (MBMessage mbMessage : list) {
8243                                            if ((userId != mbMessage.getUserId()) ||
8244                                                            !ArrayUtil.contains(classNameIds,
8245                                                                    mbMessage.getClassNameId())) {
8246                                                    list = null;
8247    
8248                                                    break;
8249                                            }
8250                                    }
8251                            }
8252                    }
8253    
8254                    if (list == null) {
8255                            StringBundler query = new StringBundler();
8256    
8257                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8258    
8259                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8260    
8261                            if (classNameIds.length > 0) {
8262                                    query.append(StringPool.OPEN_PARENTHESIS);
8263    
8264                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8265    
8266                                    query.append(StringUtil.merge(classNameIds));
8267    
8268                                    query.append(StringPool.CLOSE_PARENTHESIS);
8269    
8270                                    query.append(StringPool.CLOSE_PARENTHESIS);
8271                            }
8272    
8273                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8274                                                    1)), query.index() - 1);
8275    
8276                            if (orderByComparator != null) {
8277                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8278                                            orderByComparator);
8279                            }
8280                            else
8281                             if (pagination) {
8282                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8283                            }
8284    
8285                            String sql = query.toString();
8286    
8287                            Session session = null;
8288    
8289                            try {
8290                                    session = openSession();
8291    
8292                                    Query q = session.createQuery(sql);
8293    
8294                                    QueryPos qPos = QueryPos.getInstance(q);
8295    
8296                                    qPos.add(userId);
8297    
8298                                    if (!pagination) {
8299                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8300                                                            start, end, false);
8301    
8302                                            Collections.sort(list);
8303    
8304                                            list = Collections.unmodifiableList(list);
8305                                    }
8306                                    else {
8307                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8308                                                            start, end);
8309                                    }
8310    
8311                                    cacheResult(list);
8312    
8313                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8314                                            finderArgs, list);
8315                            }
8316                            catch (Exception e) {
8317                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8318                                            finderArgs);
8319    
8320                                    throw processException(e);
8321                            }
8322                            finally {
8323                                    closeSession(session);
8324                            }
8325                    }
8326    
8327                    return list;
8328            }
8329    
8330            /**
8331             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8332             *
8333             * @param userId the user ID
8334             * @param classNameId the class name ID
8335             */
8336            @Override
8337            public void removeByU_C(long userId, long classNameId) {
8338                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8339                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8340                            remove(mbMessage);
8341                    }
8342            }
8343    
8344            /**
8345             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8346             *
8347             * @param userId the user ID
8348             * @param classNameId the class name ID
8349             * @return the number of matching message-boards messages
8350             */
8351            @Override
8352            public int countByU_C(long userId, long classNameId) {
8353                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8354    
8355                    Object[] finderArgs = new Object[] { userId, classNameId };
8356    
8357                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8358    
8359                    if (count == null) {
8360                            StringBundler query = new StringBundler(3);
8361    
8362                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8363    
8364                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8365    
8366                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8367    
8368                            String sql = query.toString();
8369    
8370                            Session session = null;
8371    
8372                            try {
8373                                    session = openSession();
8374    
8375                                    Query q = session.createQuery(sql);
8376    
8377                                    QueryPos qPos = QueryPos.getInstance(q);
8378    
8379                                    qPos.add(userId);
8380    
8381                                    qPos.add(classNameId);
8382    
8383                                    count = (Long)q.uniqueResult();
8384    
8385                                    finderCache.putResult(finderPath, finderArgs, count);
8386                            }
8387                            catch (Exception e) {
8388                                    finderCache.removeResult(finderPath, finderArgs);
8389    
8390                                    throw processException(e);
8391                            }
8392                            finally {
8393                                    closeSession(session);
8394                            }
8395                    }
8396    
8397                    return count.intValue();
8398            }
8399    
8400            /**
8401             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8402             *
8403             * @param userId the user ID
8404             * @param classNameIds the class name IDs
8405             * @return the number of matching message-boards messages
8406             */
8407            @Override
8408            public int countByU_C(long userId, long[] classNameIds) {
8409                    if (classNameIds == null) {
8410                            classNameIds = new long[0];
8411                    }
8412                    else if (classNameIds.length > 1) {
8413                            classNameIds = ArrayUtil.unique(classNameIds);
8414    
8415                            Arrays.sort(classNameIds);
8416                    }
8417    
8418                    Object[] finderArgs = new Object[] {
8419                                    userId, StringUtil.merge(classNameIds)
8420                            };
8421    
8422                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8423                                    finderArgs, this);
8424    
8425                    if (count == null) {
8426                            StringBundler query = new StringBundler();
8427    
8428                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8429    
8430                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8431    
8432                            if (classNameIds.length > 0) {
8433                                    query.append(StringPool.OPEN_PARENTHESIS);
8434    
8435                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8436    
8437                                    query.append(StringUtil.merge(classNameIds));
8438    
8439                                    query.append(StringPool.CLOSE_PARENTHESIS);
8440    
8441                                    query.append(StringPool.CLOSE_PARENTHESIS);
8442                            }
8443    
8444                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8445                                                    1)), query.index() - 1);
8446    
8447                            String sql = query.toString();
8448    
8449                            Session session = null;
8450    
8451                            try {
8452                                    session = openSession();
8453    
8454                                    Query q = session.createQuery(sql);
8455    
8456                                    QueryPos qPos = QueryPos.getInstance(q);
8457    
8458                                    qPos.add(userId);
8459    
8460                                    count = (Long)q.uniqueResult();
8461    
8462                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8463                                            finderArgs, count);
8464                            }
8465                            catch (Exception e) {
8466                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8467                                            finderArgs);
8468    
8469                                    throw processException(e);
8470                            }
8471                            finally {
8472                                    closeSession(session);
8473                            }
8474                    }
8475    
8476                    return count.intValue();
8477            }
8478    
8479            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8480            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8481            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8482            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8483                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8484                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8485                            new String[] {
8486                                    Long.class.getName(), Long.class.getName(),
8487                                    
8488                            Integer.class.getName(), Integer.class.getName(),
8489                                    OrderByComparator.class.getName()
8490                            });
8491            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8492                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8493                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8494                            new String[] { Long.class.getName(), Long.class.getName() },
8495                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8496                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8497                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8498            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8499                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8500                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8501                            new String[] { Long.class.getName(), Long.class.getName() });
8502    
8503            /**
8504             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8505             *
8506             * @param classNameId the class name ID
8507             * @param classPK the class p k
8508             * @return the matching message-boards messages
8509             */
8510            @Override
8511            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8512                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8513                            QueryUtil.ALL_POS, null);
8514            }
8515    
8516            /**
8517             * Returns a 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             * @return the range of matching message-boards messages
8528             */
8529            @Override
8530            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8531                    int end) {
8532                    return findByC_C(classNameId, classPK, start, end, null);
8533            }
8534    
8535            /**
8536             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8537             *
8538             * <p>
8539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8540             * </p>
8541             *
8542             * @param classNameId the class name ID
8543             * @param classPK the class p k
8544             * @param start the lower bound of the range of message-boards messages
8545             * @param end the upper bound of the range of message-boards messages (not inclusive)
8546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8547             * @return the ordered range of matching message-boards messages
8548             */
8549            @Override
8550            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8551                    int end, OrderByComparator<MBMessage> orderByComparator) {
8552                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
8553                            true);
8554            }
8555    
8556            /**
8557             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8558             *
8559             * <p>
8560             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8561             * </p>
8562             *
8563             * @param classNameId the class name ID
8564             * @param classPK the class p k
8565             * @param start the lower bound of the range of message-boards messages
8566             * @param end the upper bound of the range of message-boards messages (not inclusive)
8567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8568             * @param retrieveFromCache whether to retrieve from the finder cache
8569             * @return the ordered range of matching message-boards messages
8570             */
8571            @Override
8572            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8573                    int end, OrderByComparator<MBMessage> orderByComparator,
8574                    boolean retrieveFromCache) {
8575                    boolean pagination = true;
8576                    FinderPath finderPath = null;
8577                    Object[] finderArgs = null;
8578    
8579                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8580                                    (orderByComparator == null)) {
8581                            pagination = false;
8582                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8583                            finderArgs = new Object[] { classNameId, classPK };
8584                    }
8585                    else {
8586                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8587                            finderArgs = new Object[] {
8588                                            classNameId, classPK,
8589                                            
8590                                            start, end, orderByComparator
8591                                    };
8592                    }
8593    
8594                    List<MBMessage> list = null;
8595    
8596                    if (retrieveFromCache) {
8597                            list = (List<MBMessage>)finderCache.getResult(finderPath,
8598                                            finderArgs, this);
8599    
8600                            if ((list != null) && !list.isEmpty()) {
8601                                    for (MBMessage mbMessage : list) {
8602                                            if ((classNameId != mbMessage.getClassNameId()) ||
8603                                                            (classPK != mbMessage.getClassPK())) {
8604                                                    list = null;
8605    
8606                                                    break;
8607                                            }
8608                                    }
8609                            }
8610                    }
8611    
8612                    if (list == null) {
8613                            StringBundler query = null;
8614    
8615                            if (orderByComparator != null) {
8616                                    query = new StringBundler(4 +
8617                                                    (orderByComparator.getOrderByFields().length * 2));
8618                            }
8619                            else {
8620                                    query = new StringBundler(4);
8621                            }
8622    
8623                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8624    
8625                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8626    
8627                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8628    
8629                            if (orderByComparator != null) {
8630                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8631                                            orderByComparator);
8632                            }
8633                            else
8634                             if (pagination) {
8635                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8636                            }
8637    
8638                            String sql = query.toString();
8639    
8640                            Session session = null;
8641    
8642                            try {
8643                                    session = openSession();
8644    
8645                                    Query q = session.createQuery(sql);
8646    
8647                                    QueryPos qPos = QueryPos.getInstance(q);
8648    
8649                                    qPos.add(classNameId);
8650    
8651                                    qPos.add(classPK);
8652    
8653                                    if (!pagination) {
8654                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8655                                                            start, end, false);
8656    
8657                                            Collections.sort(list);
8658    
8659                                            list = Collections.unmodifiableList(list);
8660                                    }
8661                                    else {
8662                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8663                                                            start, end);
8664                                    }
8665    
8666                                    cacheResult(list);
8667    
8668                                    finderCache.putResult(finderPath, finderArgs, list);
8669                            }
8670                            catch (Exception e) {
8671                                    finderCache.removeResult(finderPath, finderArgs);
8672    
8673                                    throw processException(e);
8674                            }
8675                            finally {
8676                                    closeSession(session);
8677                            }
8678                    }
8679    
8680                    return list;
8681            }
8682    
8683            /**
8684             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8685             *
8686             * @param classNameId the class name ID
8687             * @param classPK the class p k
8688             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8689             * @return the first matching message-boards message
8690             * @throws NoSuchMessageException if a matching message-boards message could not be found
8691             */
8692            @Override
8693            public MBMessage findByC_C_First(long classNameId, long classPK,
8694                    OrderByComparator<MBMessage> orderByComparator)
8695                    throws NoSuchMessageException {
8696                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8697                                    orderByComparator);
8698    
8699                    if (mbMessage != null) {
8700                            return mbMessage;
8701                    }
8702    
8703                    StringBundler msg = new StringBundler(6);
8704    
8705                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8706    
8707                    msg.append("classNameId=");
8708                    msg.append(classNameId);
8709    
8710                    msg.append(", classPK=");
8711                    msg.append(classPK);
8712    
8713                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8714    
8715                    throw new NoSuchMessageException(msg.toString());
8716            }
8717    
8718            /**
8719             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8720             *
8721             * @param classNameId the class name ID
8722             * @param classPK the class p k
8723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8724             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8725             */
8726            @Override
8727            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8728                    OrderByComparator<MBMessage> orderByComparator) {
8729                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8730                                    orderByComparator);
8731    
8732                    if (!list.isEmpty()) {
8733                            return list.get(0);
8734                    }
8735    
8736                    return null;
8737            }
8738    
8739            /**
8740             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8741             *
8742             * @param classNameId the class name ID
8743             * @param classPK the class p k
8744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8745             * @return the last matching message-boards message
8746             * @throws NoSuchMessageException if a matching message-boards message could not be found
8747             */
8748            @Override
8749            public MBMessage findByC_C_Last(long classNameId, long classPK,
8750                    OrderByComparator<MBMessage> orderByComparator)
8751                    throws NoSuchMessageException {
8752                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8753                                    orderByComparator);
8754    
8755                    if (mbMessage != null) {
8756                            return mbMessage;
8757                    }
8758    
8759                    StringBundler msg = new StringBundler(6);
8760    
8761                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8762    
8763                    msg.append("classNameId=");
8764                    msg.append(classNameId);
8765    
8766                    msg.append(", classPK=");
8767                    msg.append(classPK);
8768    
8769                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8770    
8771                    throw new NoSuchMessageException(msg.toString());
8772            }
8773    
8774            /**
8775             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8776             *
8777             * @param classNameId the class name ID
8778             * @param classPK the class p k
8779             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8780             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8781             */
8782            @Override
8783            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8784                    OrderByComparator<MBMessage> orderByComparator) {
8785                    int count = countByC_C(classNameId, classPK);
8786    
8787                    if (count == 0) {
8788                            return null;
8789                    }
8790    
8791                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8792                                    count, orderByComparator);
8793    
8794                    if (!list.isEmpty()) {
8795                            return list.get(0);
8796                    }
8797    
8798                    return null;
8799            }
8800    
8801            /**
8802             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8803             *
8804             * @param messageId the primary key of the current message-boards message
8805             * @param classNameId the class name ID
8806             * @param classPK the class p k
8807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8808             * @return the previous, current, and next message-boards message
8809             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8810             */
8811            @Override
8812            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8813                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8814                    throws NoSuchMessageException {
8815                    MBMessage mbMessage = findByPrimaryKey(messageId);
8816    
8817                    Session session = null;
8818    
8819                    try {
8820                            session = openSession();
8821    
8822                            MBMessage[] array = new MBMessageImpl[3];
8823    
8824                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8825                                            classPK, orderByComparator, true);
8826    
8827                            array[1] = mbMessage;
8828    
8829                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8830                                            classPK, orderByComparator, false);
8831    
8832                            return array;
8833                    }
8834                    catch (Exception e) {
8835                            throw processException(e);
8836                    }
8837                    finally {
8838                            closeSession(session);
8839                    }
8840            }
8841    
8842            protected MBMessage getByC_C_PrevAndNext(Session session,
8843                    MBMessage mbMessage, long classNameId, long classPK,
8844                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8845                    StringBundler query = null;
8846    
8847                    if (orderByComparator != null) {
8848                            query = new StringBundler(5 +
8849                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8850                                            (orderByComparator.getOrderByFields().length * 3));
8851                    }
8852                    else {
8853                            query = new StringBundler(4);
8854                    }
8855    
8856                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8857    
8858                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8859    
8860                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8861    
8862                    if (orderByComparator != null) {
8863                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8864    
8865                            if (orderByConditionFields.length > 0) {
8866                                    query.append(WHERE_AND);
8867                            }
8868    
8869                            for (int i = 0; i < orderByConditionFields.length; i++) {
8870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8871                                    query.append(orderByConditionFields[i]);
8872    
8873                                    if ((i + 1) < orderByConditionFields.length) {
8874                                            if (orderByComparator.isAscending() ^ previous) {
8875                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8876                                            }
8877                                            else {
8878                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8879                                            }
8880                                    }
8881                                    else {
8882                                            if (orderByComparator.isAscending() ^ previous) {
8883                                                    query.append(WHERE_GREATER_THAN);
8884                                            }
8885                                            else {
8886                                                    query.append(WHERE_LESSER_THAN);
8887                                            }
8888                                    }
8889                            }
8890    
8891                            query.append(ORDER_BY_CLAUSE);
8892    
8893                            String[] orderByFields = orderByComparator.getOrderByFields();
8894    
8895                            for (int i = 0; i < orderByFields.length; i++) {
8896                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8897                                    query.append(orderByFields[i]);
8898    
8899                                    if ((i + 1) < orderByFields.length) {
8900                                            if (orderByComparator.isAscending() ^ previous) {
8901                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8902                                            }
8903                                            else {
8904                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8905                                            }
8906                                    }
8907                                    else {
8908                                            if (orderByComparator.isAscending() ^ previous) {
8909                                                    query.append(ORDER_BY_ASC);
8910                                            }
8911                                            else {
8912                                                    query.append(ORDER_BY_DESC);
8913                                            }
8914                                    }
8915                            }
8916                    }
8917                    else {
8918                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8919                    }
8920    
8921                    String sql = query.toString();
8922    
8923                    Query q = session.createQuery(sql);
8924    
8925                    q.setFirstResult(0);
8926                    q.setMaxResults(2);
8927    
8928                    QueryPos qPos = QueryPos.getInstance(q);
8929    
8930                    qPos.add(classNameId);
8931    
8932                    qPos.add(classPK);
8933    
8934                    if (orderByComparator != null) {
8935                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8936    
8937                            for (Object value : values) {
8938                                    qPos.add(value);
8939                            }
8940                    }
8941    
8942                    List<MBMessage> list = q.list();
8943    
8944                    if (list.size() == 2) {
8945                            return list.get(1);
8946                    }
8947                    else {
8948                            return null;
8949                    }
8950            }
8951    
8952            /**
8953             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8954             *
8955             * @param classNameId the class name ID
8956             * @param classPK the class p k
8957             */
8958            @Override
8959            public void removeByC_C(long classNameId, long classPK) {
8960                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8961                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8962                            remove(mbMessage);
8963                    }
8964            }
8965    
8966            /**
8967             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8968             *
8969             * @param classNameId the class name ID
8970             * @param classPK the class p k
8971             * @return the number of matching message-boards messages
8972             */
8973            @Override
8974            public int countByC_C(long classNameId, long classPK) {
8975                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8976    
8977                    Object[] finderArgs = new Object[] { classNameId, classPK };
8978    
8979                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8980    
8981                    if (count == null) {
8982                            StringBundler query = new StringBundler(3);
8983    
8984                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8985    
8986                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8987    
8988                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8989    
8990                            String sql = query.toString();
8991    
8992                            Session session = null;
8993    
8994                            try {
8995                                    session = openSession();
8996    
8997                                    Query q = session.createQuery(sql);
8998    
8999                                    QueryPos qPos = QueryPos.getInstance(q);
9000    
9001                                    qPos.add(classNameId);
9002    
9003                                    qPos.add(classPK);
9004    
9005                                    count = (Long)q.uniqueResult();
9006    
9007                                    finderCache.putResult(finderPath, finderArgs, count);
9008                            }
9009                            catch (Exception e) {
9010                                    finderCache.removeResult(finderPath, finderArgs);
9011    
9012                                    throw processException(e);
9013                            }
9014                            finally {
9015                                    closeSession(session);
9016                            }
9017                    }
9018    
9019                    return count.intValue();
9020            }
9021    
9022            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
9023            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
9024            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9025                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9026                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
9027                            new String[] {
9028                                    Long.class.getName(), Long.class.getName(),
9029                                    
9030                            Integer.class.getName(), Integer.class.getName(),
9031                                    OrderByComparator.class.getName()
9032                            });
9033            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9034                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9035                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
9036                            new String[] { Long.class.getName(), Long.class.getName() },
9037                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9038                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
9039                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9040            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9041                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9042                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
9043                            new String[] { Long.class.getName(), Long.class.getName() });
9044    
9045            /**
9046             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9047             *
9048             * @param threadId the thread ID
9049             * @param parentMessageId the parent message ID
9050             * @return the matching message-boards messages
9051             */
9052            @Override
9053            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
9054                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
9055                            QueryUtil.ALL_POS, null);
9056            }
9057    
9058            /**
9059             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9060             *
9061             * <p>
9062             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9063             * </p>
9064             *
9065             * @param threadId the thread ID
9066             * @param parentMessageId the parent message ID
9067             * @param start the lower bound of the range of message-boards messages
9068             * @param end the upper bound of the range of message-boards messages (not inclusive)
9069             * @return the range of matching message-boards messages
9070             */
9071            @Override
9072            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9073                    int start, int end) {
9074                    return findByT_P(threadId, parentMessageId, start, end, null);
9075            }
9076    
9077            /**
9078             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9079             *
9080             * <p>
9081             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9082             * </p>
9083             *
9084             * @param threadId the thread ID
9085             * @param parentMessageId the parent message ID
9086             * @param start the lower bound of the range of message-boards messages
9087             * @param end the upper bound of the range of message-boards messages (not inclusive)
9088             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9089             * @return the ordered range of matching message-boards messages
9090             */
9091            @Override
9092            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9093                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
9094                    return findByT_P(threadId, parentMessageId, start, end,
9095                            orderByComparator, true);
9096            }
9097    
9098            /**
9099             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9100             *
9101             * <p>
9102             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9103             * </p>
9104             *
9105             * @param threadId the thread ID
9106             * @param parentMessageId the parent message ID
9107             * @param start the lower bound of the range of message-boards messages
9108             * @param end the upper bound of the range of message-boards messages (not inclusive)
9109             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9110             * @param retrieveFromCache whether to retrieve from the finder cache
9111             * @return the ordered range of matching message-boards messages
9112             */
9113            @Override
9114            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9115                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
9116                    boolean retrieveFromCache) {
9117                    boolean pagination = true;
9118                    FinderPath finderPath = null;
9119                    Object[] finderArgs = null;
9120    
9121                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9122                                    (orderByComparator == null)) {
9123                            pagination = false;
9124                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
9125                            finderArgs = new Object[] { threadId, parentMessageId };
9126                    }
9127                    else {
9128                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
9129                            finderArgs = new Object[] {
9130                                            threadId, parentMessageId,
9131                                            
9132                                            start, end, orderByComparator
9133                                    };
9134                    }
9135    
9136                    List<MBMessage> list = null;
9137    
9138                    if (retrieveFromCache) {
9139                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9140                                            finderArgs, this);
9141    
9142                            if ((list != null) && !list.isEmpty()) {
9143                                    for (MBMessage mbMessage : list) {
9144                                            if ((threadId != mbMessage.getThreadId()) ||
9145                                                            (parentMessageId != mbMessage.getParentMessageId())) {
9146                                                    list = null;
9147    
9148                                                    break;
9149                                            }
9150                                    }
9151                            }
9152                    }
9153    
9154                    if (list == null) {
9155                            StringBundler query = null;
9156    
9157                            if (orderByComparator != null) {
9158                                    query = new StringBundler(4 +
9159                                                    (orderByComparator.getOrderByFields().length * 2));
9160                            }
9161                            else {
9162                                    query = new StringBundler(4);
9163                            }
9164    
9165                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9166    
9167                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9168    
9169                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9170    
9171                            if (orderByComparator != null) {
9172                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9173                                            orderByComparator);
9174                            }
9175                            else
9176                             if (pagination) {
9177                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9178                            }
9179    
9180                            String sql = query.toString();
9181    
9182                            Session session = null;
9183    
9184                            try {
9185                                    session = openSession();
9186    
9187                                    Query q = session.createQuery(sql);
9188    
9189                                    QueryPos qPos = QueryPos.getInstance(q);
9190    
9191                                    qPos.add(threadId);
9192    
9193                                    qPos.add(parentMessageId);
9194    
9195                                    if (!pagination) {
9196                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9197                                                            start, end, false);
9198    
9199                                            Collections.sort(list);
9200    
9201                                            list = Collections.unmodifiableList(list);
9202                                    }
9203                                    else {
9204                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9205                                                            start, end);
9206                                    }
9207    
9208                                    cacheResult(list);
9209    
9210                                    finderCache.putResult(finderPath, finderArgs, list);
9211                            }
9212                            catch (Exception e) {
9213                                    finderCache.removeResult(finderPath, finderArgs);
9214    
9215                                    throw processException(e);
9216                            }
9217                            finally {
9218                                    closeSession(session);
9219                            }
9220                    }
9221    
9222                    return list;
9223            }
9224    
9225            /**
9226             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9227             *
9228             * @param threadId the thread ID
9229             * @param parentMessageId the parent message ID
9230             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9231             * @return the first matching message-boards message
9232             * @throws NoSuchMessageException if a matching message-boards message could not be found
9233             */
9234            @Override
9235            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9236                    OrderByComparator<MBMessage> orderByComparator)
9237                    throws NoSuchMessageException {
9238                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9239                                    orderByComparator);
9240    
9241                    if (mbMessage != null) {
9242                            return mbMessage;
9243                    }
9244    
9245                    StringBundler msg = new StringBundler(6);
9246    
9247                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9248    
9249                    msg.append("threadId=");
9250                    msg.append(threadId);
9251    
9252                    msg.append(", parentMessageId=");
9253                    msg.append(parentMessageId);
9254    
9255                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9256    
9257                    throw new NoSuchMessageException(msg.toString());
9258            }
9259    
9260            /**
9261             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9262             *
9263             * @param threadId the thread ID
9264             * @param parentMessageId the parent message ID
9265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9266             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9267             */
9268            @Override
9269            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9270                    OrderByComparator<MBMessage> orderByComparator) {
9271                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9272                                    orderByComparator);
9273    
9274                    if (!list.isEmpty()) {
9275                            return list.get(0);
9276                    }
9277    
9278                    return null;
9279            }
9280    
9281            /**
9282             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9283             *
9284             * @param threadId the thread ID
9285             * @param parentMessageId the parent message ID
9286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9287             * @return the last matching message-boards message
9288             * @throws NoSuchMessageException if a matching message-boards message could not be found
9289             */
9290            @Override
9291            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9292                    OrderByComparator<MBMessage> orderByComparator)
9293                    throws NoSuchMessageException {
9294                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9295                                    orderByComparator);
9296    
9297                    if (mbMessage != null) {
9298                            return mbMessage;
9299                    }
9300    
9301                    StringBundler msg = new StringBundler(6);
9302    
9303                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9304    
9305                    msg.append("threadId=");
9306                    msg.append(threadId);
9307    
9308                    msg.append(", parentMessageId=");
9309                    msg.append(parentMessageId);
9310    
9311                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9312    
9313                    throw new NoSuchMessageException(msg.toString());
9314            }
9315    
9316            /**
9317             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9318             *
9319             * @param threadId the thread ID
9320             * @param parentMessageId the parent message ID
9321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9322             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9323             */
9324            @Override
9325            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9326                    OrderByComparator<MBMessage> orderByComparator) {
9327                    int count = countByT_P(threadId, parentMessageId);
9328    
9329                    if (count == 0) {
9330                            return null;
9331                    }
9332    
9333                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9334                                    count, orderByComparator);
9335    
9336                    if (!list.isEmpty()) {
9337                            return list.get(0);
9338                    }
9339    
9340                    return null;
9341            }
9342    
9343            /**
9344             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9345             *
9346             * @param messageId the primary key of the current message-boards message
9347             * @param threadId the thread ID
9348             * @param parentMessageId the parent message ID
9349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9350             * @return the previous, current, and next message-boards message
9351             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9352             */
9353            @Override
9354            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9355                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
9356                    throws NoSuchMessageException {
9357                    MBMessage mbMessage = findByPrimaryKey(messageId);
9358    
9359                    Session session = null;
9360    
9361                    try {
9362                            session = openSession();
9363    
9364                            MBMessage[] array = new MBMessageImpl[3];
9365    
9366                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9367                                            parentMessageId, orderByComparator, true);
9368    
9369                            array[1] = mbMessage;
9370    
9371                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9372                                            parentMessageId, orderByComparator, false);
9373    
9374                            return array;
9375                    }
9376                    catch (Exception e) {
9377                            throw processException(e);
9378                    }
9379                    finally {
9380                            closeSession(session);
9381                    }
9382            }
9383    
9384            protected MBMessage getByT_P_PrevAndNext(Session session,
9385                    MBMessage mbMessage, long threadId, long parentMessageId,
9386                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9387                    StringBundler query = null;
9388    
9389                    if (orderByComparator != null) {
9390                            query = new StringBundler(5 +
9391                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9392                                            (orderByComparator.getOrderByFields().length * 3));
9393                    }
9394                    else {
9395                            query = new StringBundler(4);
9396                    }
9397    
9398                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9399    
9400                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9401    
9402                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9403    
9404                    if (orderByComparator != null) {
9405                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9406    
9407                            if (orderByConditionFields.length > 0) {
9408                                    query.append(WHERE_AND);
9409                            }
9410    
9411                            for (int i = 0; i < orderByConditionFields.length; i++) {
9412                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9413                                    query.append(orderByConditionFields[i]);
9414    
9415                                    if ((i + 1) < orderByConditionFields.length) {
9416                                            if (orderByComparator.isAscending() ^ previous) {
9417                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9418                                            }
9419                                            else {
9420                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9421                                            }
9422                                    }
9423                                    else {
9424                                            if (orderByComparator.isAscending() ^ previous) {
9425                                                    query.append(WHERE_GREATER_THAN);
9426                                            }
9427                                            else {
9428                                                    query.append(WHERE_LESSER_THAN);
9429                                            }
9430                                    }
9431                            }
9432    
9433                            query.append(ORDER_BY_CLAUSE);
9434    
9435                            String[] orderByFields = orderByComparator.getOrderByFields();
9436    
9437                            for (int i = 0; i < orderByFields.length; i++) {
9438                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9439                                    query.append(orderByFields[i]);
9440    
9441                                    if ((i + 1) < orderByFields.length) {
9442                                            if (orderByComparator.isAscending() ^ previous) {
9443                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9444                                            }
9445                                            else {
9446                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9447                                            }
9448                                    }
9449                                    else {
9450                                            if (orderByComparator.isAscending() ^ previous) {
9451                                                    query.append(ORDER_BY_ASC);
9452                                            }
9453                                            else {
9454                                                    query.append(ORDER_BY_DESC);
9455                                            }
9456                                    }
9457                            }
9458                    }
9459                    else {
9460                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9461                    }
9462    
9463                    String sql = query.toString();
9464    
9465                    Query q = session.createQuery(sql);
9466    
9467                    q.setFirstResult(0);
9468                    q.setMaxResults(2);
9469    
9470                    QueryPos qPos = QueryPos.getInstance(q);
9471    
9472                    qPos.add(threadId);
9473    
9474                    qPos.add(parentMessageId);
9475    
9476                    if (orderByComparator != null) {
9477                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9478    
9479                            for (Object value : values) {
9480                                    qPos.add(value);
9481                            }
9482                    }
9483    
9484                    List<MBMessage> list = q.list();
9485    
9486                    if (list.size() == 2) {
9487                            return list.get(1);
9488                    }
9489                    else {
9490                            return null;
9491                    }
9492            }
9493    
9494            /**
9495             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9496             *
9497             * @param threadId the thread ID
9498             * @param parentMessageId the parent message ID
9499             */
9500            @Override
9501            public void removeByT_P(long threadId, long parentMessageId) {
9502                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9503                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9504                            remove(mbMessage);
9505                    }
9506            }
9507    
9508            /**
9509             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9510             *
9511             * @param threadId the thread ID
9512             * @param parentMessageId the parent message ID
9513             * @return the number of matching message-boards messages
9514             */
9515            @Override
9516            public int countByT_P(long threadId, long parentMessageId) {
9517                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9518    
9519                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9520    
9521                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9522    
9523                    if (count == null) {
9524                            StringBundler query = new StringBundler(3);
9525    
9526                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9527    
9528                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9529    
9530                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9531    
9532                            String sql = query.toString();
9533    
9534                            Session session = null;
9535    
9536                            try {
9537                                    session = openSession();
9538    
9539                                    Query q = session.createQuery(sql);
9540    
9541                                    QueryPos qPos = QueryPos.getInstance(q);
9542    
9543                                    qPos.add(threadId);
9544    
9545                                    qPos.add(parentMessageId);
9546    
9547                                    count = (Long)q.uniqueResult();
9548    
9549                                    finderCache.putResult(finderPath, finderArgs, count);
9550                            }
9551                            catch (Exception e) {
9552                                    finderCache.removeResult(finderPath, finderArgs);
9553    
9554                                    throw processException(e);
9555                            }
9556                            finally {
9557                                    closeSession(session);
9558                            }
9559                    }
9560    
9561                    return count.intValue();
9562            }
9563    
9564            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9565            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9566            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9567                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9568                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9569                            new String[] {
9570                                    Long.class.getName(), Boolean.class.getName(),
9571                                    
9572                            Integer.class.getName(), Integer.class.getName(),
9573                                    OrderByComparator.class.getName()
9574                            });
9575            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9576                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9577                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9578                            new String[] { Long.class.getName(), Boolean.class.getName() },
9579                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9580                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9581                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9582            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9583                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9584                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9585                            new String[] { Long.class.getName(), Boolean.class.getName() });
9586    
9587            /**
9588             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9589             *
9590             * @param threadId the thread ID
9591             * @param answer the answer
9592             * @return the matching message-boards messages
9593             */
9594            @Override
9595            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9596                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9597                            QueryUtil.ALL_POS, null);
9598            }
9599    
9600            /**
9601             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9602             *
9603             * <p>
9604             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9605             * </p>
9606             *
9607             * @param threadId the thread ID
9608             * @param answer the answer
9609             * @param start the lower bound of the range of message-boards messages
9610             * @param end the upper bound of the range of message-boards messages (not inclusive)
9611             * @return the range of matching message-boards messages
9612             */
9613            @Override
9614            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9615                    int end) {
9616                    return findByT_A(threadId, answer, start, end, null);
9617            }
9618    
9619            /**
9620             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9621             *
9622             * <p>
9623             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9624             * </p>
9625             *
9626             * @param threadId the thread ID
9627             * @param answer the answer
9628             * @param start the lower bound of the range of message-boards messages
9629             * @param end the upper bound of the range of message-boards messages (not inclusive)
9630             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9631             * @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                    return findByT_A(threadId, answer, start, end, orderByComparator, true);
9637            }
9638    
9639            /**
9640             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9641             *
9642             * <p>
9643             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9644             * </p>
9645             *
9646             * @param threadId the thread ID
9647             * @param answer the answer
9648             * @param start the lower bound of the range of message-boards messages
9649             * @param end the upper bound of the range of message-boards messages (not inclusive)
9650             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9651             * @param retrieveFromCache whether to retrieve from the finder cache
9652             * @return the ordered range of matching message-boards messages
9653             */
9654            @Override
9655            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9656                    int end, OrderByComparator<MBMessage> orderByComparator,
9657                    boolean retrieveFromCache) {
9658                    boolean pagination = true;
9659                    FinderPath finderPath = null;
9660                    Object[] finderArgs = null;
9661    
9662                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9663                                    (orderByComparator == null)) {
9664                            pagination = false;
9665                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9666                            finderArgs = new Object[] { threadId, answer };
9667                    }
9668                    else {
9669                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9670                            finderArgs = new Object[] {
9671                                            threadId, answer,
9672                                            
9673                                            start, end, orderByComparator
9674                                    };
9675                    }
9676    
9677                    List<MBMessage> list = null;
9678    
9679                    if (retrieveFromCache) {
9680                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9681                                            finderArgs, this);
9682    
9683                            if ((list != null) && !list.isEmpty()) {
9684                                    for (MBMessage mbMessage : list) {
9685                                            if ((threadId != mbMessage.getThreadId()) ||
9686                                                            (answer != mbMessage.getAnswer())) {
9687                                                    list = null;
9688    
9689                                                    break;
9690                                            }
9691                                    }
9692                            }
9693                    }
9694    
9695                    if (list == null) {
9696                            StringBundler query = null;
9697    
9698                            if (orderByComparator != null) {
9699                                    query = new StringBundler(4 +
9700                                                    (orderByComparator.getOrderByFields().length * 2));
9701                            }
9702                            else {
9703                                    query = new StringBundler(4);
9704                            }
9705    
9706                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9707    
9708                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9709    
9710                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9711    
9712                            if (orderByComparator != null) {
9713                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9714                                            orderByComparator);
9715                            }
9716                            else
9717                             if (pagination) {
9718                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9719                            }
9720    
9721                            String sql = query.toString();
9722    
9723                            Session session = null;
9724    
9725                            try {
9726                                    session = openSession();
9727    
9728                                    Query q = session.createQuery(sql);
9729    
9730                                    QueryPos qPos = QueryPos.getInstance(q);
9731    
9732                                    qPos.add(threadId);
9733    
9734                                    qPos.add(answer);
9735    
9736                                    if (!pagination) {
9737                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9738                                                            start, end, false);
9739    
9740                                            Collections.sort(list);
9741    
9742                                            list = Collections.unmodifiableList(list);
9743                                    }
9744                                    else {
9745                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9746                                                            start, end);
9747                                    }
9748    
9749                                    cacheResult(list);
9750    
9751                                    finderCache.putResult(finderPath, finderArgs, list);
9752                            }
9753                            catch (Exception e) {
9754                                    finderCache.removeResult(finderPath, finderArgs);
9755    
9756                                    throw processException(e);
9757                            }
9758                            finally {
9759                                    closeSession(session);
9760                            }
9761                    }
9762    
9763                    return list;
9764            }
9765    
9766            /**
9767             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9768             *
9769             * @param threadId the thread ID
9770             * @param answer the answer
9771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9772             * @return the first matching message-boards message
9773             * @throws NoSuchMessageException if a matching message-boards message could not be found
9774             */
9775            @Override
9776            public MBMessage findByT_A_First(long threadId, boolean answer,
9777                    OrderByComparator<MBMessage> orderByComparator)
9778                    throws NoSuchMessageException {
9779                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9780                                    orderByComparator);
9781    
9782                    if (mbMessage != null) {
9783                            return mbMessage;
9784                    }
9785    
9786                    StringBundler msg = new StringBundler(6);
9787    
9788                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9789    
9790                    msg.append("threadId=");
9791                    msg.append(threadId);
9792    
9793                    msg.append(", answer=");
9794                    msg.append(answer);
9795    
9796                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9797    
9798                    throw new NoSuchMessageException(msg.toString());
9799            }
9800    
9801            /**
9802             * Returns the first 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 first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9808             */
9809            @Override
9810            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9811                    OrderByComparator<MBMessage> orderByComparator) {
9812                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9813                                    orderByComparator);
9814    
9815                    if (!list.isEmpty()) {
9816                            return list.get(0);
9817                    }
9818    
9819                    return null;
9820            }
9821    
9822            /**
9823             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9824             *
9825             * @param threadId the thread ID
9826             * @param answer the answer
9827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9828             * @return the last matching message-boards message
9829             * @throws NoSuchMessageException if a matching message-boards message could not be found
9830             */
9831            @Override
9832            public MBMessage findByT_A_Last(long threadId, boolean answer,
9833                    OrderByComparator<MBMessage> orderByComparator)
9834                    throws NoSuchMessageException {
9835                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9836                                    orderByComparator);
9837    
9838                    if (mbMessage != null) {
9839                            return mbMessage;
9840                    }
9841    
9842                    StringBundler msg = new StringBundler(6);
9843    
9844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9845    
9846                    msg.append("threadId=");
9847                    msg.append(threadId);
9848    
9849                    msg.append(", answer=");
9850                    msg.append(answer);
9851    
9852                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9853    
9854                    throw new NoSuchMessageException(msg.toString());
9855            }
9856    
9857            /**
9858             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9859             *
9860             * @param threadId the thread ID
9861             * @param answer the answer
9862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9863             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9864             */
9865            @Override
9866            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9867                    OrderByComparator<MBMessage> orderByComparator) {
9868                    int count = countByT_A(threadId, answer);
9869    
9870                    if (count == 0) {
9871                            return null;
9872                    }
9873    
9874                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9875                                    orderByComparator);
9876    
9877                    if (!list.isEmpty()) {
9878                            return list.get(0);
9879                    }
9880    
9881                    return null;
9882            }
9883    
9884            /**
9885             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9886             *
9887             * @param messageId the primary key of the current message-boards message
9888             * @param threadId the thread ID
9889             * @param answer the answer
9890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9891             * @return the previous, current, and next message-boards message
9892             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9893             */
9894            @Override
9895            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9896                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9897                    throws NoSuchMessageException {
9898                    MBMessage mbMessage = findByPrimaryKey(messageId);
9899    
9900                    Session session = null;
9901    
9902                    try {
9903                            session = openSession();
9904    
9905                            MBMessage[] array = new MBMessageImpl[3];
9906    
9907                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9908                                            answer, orderByComparator, true);
9909    
9910                            array[1] = mbMessage;
9911    
9912                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9913                                            answer, orderByComparator, false);
9914    
9915                            return array;
9916                    }
9917                    catch (Exception e) {
9918                            throw processException(e);
9919                    }
9920                    finally {
9921                            closeSession(session);
9922                    }
9923            }
9924    
9925            protected MBMessage getByT_A_PrevAndNext(Session session,
9926                    MBMessage mbMessage, long threadId, boolean answer,
9927                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9928                    StringBundler query = null;
9929    
9930                    if (orderByComparator != null) {
9931                            query = new StringBundler(5 +
9932                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9933                                            (orderByComparator.getOrderByFields().length * 3));
9934                    }
9935                    else {
9936                            query = new StringBundler(4);
9937                    }
9938    
9939                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9940    
9941                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9942    
9943                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9944    
9945                    if (orderByComparator != null) {
9946                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9947    
9948                            if (orderByConditionFields.length > 0) {
9949                                    query.append(WHERE_AND);
9950                            }
9951    
9952                            for (int i = 0; i < orderByConditionFields.length; i++) {
9953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9954                                    query.append(orderByConditionFields[i]);
9955    
9956                                    if ((i + 1) < orderByConditionFields.length) {
9957                                            if (orderByComparator.isAscending() ^ previous) {
9958                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9959                                            }
9960                                            else {
9961                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9962                                            }
9963                                    }
9964                                    else {
9965                                            if (orderByComparator.isAscending() ^ previous) {
9966                                                    query.append(WHERE_GREATER_THAN);
9967                                            }
9968                                            else {
9969                                                    query.append(WHERE_LESSER_THAN);
9970                                            }
9971                                    }
9972                            }
9973    
9974                            query.append(ORDER_BY_CLAUSE);
9975    
9976                            String[] orderByFields = orderByComparator.getOrderByFields();
9977    
9978                            for (int i = 0; i < orderByFields.length; i++) {
9979                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9980                                    query.append(orderByFields[i]);
9981    
9982                                    if ((i + 1) < orderByFields.length) {
9983                                            if (orderByComparator.isAscending() ^ previous) {
9984                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9985                                            }
9986                                            else {
9987                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9988                                            }
9989                                    }
9990                                    else {
9991                                            if (orderByComparator.isAscending() ^ previous) {
9992                                                    query.append(ORDER_BY_ASC);
9993                                            }
9994                                            else {
9995                                                    query.append(ORDER_BY_DESC);
9996                                            }
9997                                    }
9998                            }
9999                    }
10000                    else {
10001                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10002                    }
10003    
10004                    String sql = query.toString();
10005    
10006                    Query q = session.createQuery(sql);
10007    
10008                    q.setFirstResult(0);
10009                    q.setMaxResults(2);
10010    
10011                    QueryPos qPos = QueryPos.getInstance(q);
10012    
10013                    qPos.add(threadId);
10014    
10015                    qPos.add(answer);
10016    
10017                    if (orderByComparator != null) {
10018                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10019    
10020                            for (Object value : values) {
10021                                    qPos.add(value);
10022                            }
10023                    }
10024    
10025                    List<MBMessage> list = q.list();
10026    
10027                    if (list.size() == 2) {
10028                            return list.get(1);
10029                    }
10030                    else {
10031                            return null;
10032                    }
10033            }
10034    
10035            /**
10036             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
10037             *
10038             * @param threadId the thread ID
10039             * @param answer the answer
10040             */
10041            @Override
10042            public void removeByT_A(long threadId, boolean answer) {
10043                    for (MBMessage mbMessage : findByT_A(threadId, answer,
10044                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10045                            remove(mbMessage);
10046                    }
10047            }
10048    
10049            /**
10050             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
10051             *
10052             * @param threadId the thread ID
10053             * @param answer the answer
10054             * @return the number of matching message-boards messages
10055             */
10056            @Override
10057            public int countByT_A(long threadId, boolean answer) {
10058                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
10059    
10060                    Object[] finderArgs = new Object[] { threadId, answer };
10061    
10062                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10063    
10064                    if (count == null) {
10065                            StringBundler query = new StringBundler(3);
10066    
10067                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10068    
10069                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
10070    
10071                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
10072    
10073                            String sql = query.toString();
10074    
10075                            Session session = null;
10076    
10077                            try {
10078                                    session = openSession();
10079    
10080                                    Query q = session.createQuery(sql);
10081    
10082                                    QueryPos qPos = QueryPos.getInstance(q);
10083    
10084                                    qPos.add(threadId);
10085    
10086                                    qPos.add(answer);
10087    
10088                                    count = (Long)q.uniqueResult();
10089    
10090                                    finderCache.putResult(finderPath, finderArgs, count);
10091                            }
10092                            catch (Exception e) {
10093                                    finderCache.removeResult(finderPath, finderArgs);
10094    
10095                                    throw processException(e);
10096                            }
10097                            finally {
10098                                    closeSession(session);
10099                            }
10100                    }
10101    
10102                    return count.intValue();
10103            }
10104    
10105            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
10106            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
10107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10108                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10109                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
10110                            new String[] {
10111                                    Long.class.getName(), Integer.class.getName(),
10112                                    
10113                            Integer.class.getName(), Integer.class.getName(),
10114                                    OrderByComparator.class.getName()
10115                            });
10116            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
10119                            new String[] { Long.class.getName(), Integer.class.getName() },
10120                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10121                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10122                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10123            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10124                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
10126                            new String[] { Long.class.getName(), Integer.class.getName() });
10127    
10128            /**
10129             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10130             *
10131             * @param threadId the thread ID
10132             * @param status the status
10133             * @return the matching message-boards messages
10134             */
10135            @Override
10136            public List<MBMessage> findByT_S(long threadId, int status) {
10137                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
10138                            QueryUtil.ALL_POS, null);
10139            }
10140    
10141            /**
10142             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10143             *
10144             * <p>
10145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10146             * </p>
10147             *
10148             * @param threadId the thread ID
10149             * @param status the status
10150             * @param start the lower bound of the range of message-boards messages
10151             * @param end the upper bound of the range of message-boards messages (not inclusive)
10152             * @return the range of matching message-boards messages
10153             */
10154            @Override
10155            public List<MBMessage> findByT_S(long threadId, int status, int start,
10156                    int end) {
10157                    return findByT_S(threadId, status, start, end, null);
10158            }
10159    
10160            /**
10161             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10162             *
10163             * <p>
10164             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10165             * </p>
10166             *
10167             * @param threadId the thread ID
10168             * @param status the status
10169             * @param start the lower bound of the range of message-boards messages
10170             * @param end the upper bound of the range of message-boards messages (not inclusive)
10171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10172             * @return the ordered range of matching message-boards messages
10173             */
10174            @Override
10175            public List<MBMessage> findByT_S(long threadId, int status, int start,
10176                    int end, OrderByComparator<MBMessage> orderByComparator) {
10177                    return findByT_S(threadId, status, start, end, orderByComparator, true);
10178            }
10179    
10180            /**
10181             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10182             *
10183             * <p>
10184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10185             * </p>
10186             *
10187             * @param threadId the thread ID
10188             * @param status the status
10189             * @param start the lower bound of the range of message-boards messages
10190             * @param end the upper bound of the range of message-boards messages (not inclusive)
10191             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10192             * @param retrieveFromCache whether to retrieve from the finder cache
10193             * @return the ordered range of matching message-boards messages
10194             */
10195            @Override
10196            public List<MBMessage> findByT_S(long threadId, int status, int start,
10197                    int end, OrderByComparator<MBMessage> orderByComparator,
10198                    boolean retrieveFromCache) {
10199                    boolean pagination = true;
10200                    FinderPath finderPath = null;
10201                    Object[] finderArgs = null;
10202    
10203                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10204                                    (orderByComparator == null)) {
10205                            pagination = false;
10206                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10207                            finderArgs = new Object[] { threadId, status };
10208                    }
10209                    else {
10210                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10211                            finderArgs = new Object[] {
10212                                            threadId, status,
10213                                            
10214                                            start, end, orderByComparator
10215                                    };
10216                    }
10217    
10218                    List<MBMessage> list = null;
10219    
10220                    if (retrieveFromCache) {
10221                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10222                                            finderArgs, this);
10223    
10224                            if ((list != null) && !list.isEmpty()) {
10225                                    for (MBMessage mbMessage : list) {
10226                                            if ((threadId != mbMessage.getThreadId()) ||
10227                                                            (status != mbMessage.getStatus())) {
10228                                                    list = null;
10229    
10230                                                    break;
10231                                            }
10232                                    }
10233                            }
10234                    }
10235    
10236                    if (list == null) {
10237                            StringBundler query = null;
10238    
10239                            if (orderByComparator != null) {
10240                                    query = new StringBundler(4 +
10241                                                    (orderByComparator.getOrderByFields().length * 2));
10242                            }
10243                            else {
10244                                    query = new StringBundler(4);
10245                            }
10246    
10247                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10248    
10249                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10250    
10251                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10252    
10253                            if (orderByComparator != null) {
10254                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10255                                            orderByComparator);
10256                            }
10257                            else
10258                             if (pagination) {
10259                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10260                            }
10261    
10262                            String sql = query.toString();
10263    
10264                            Session session = null;
10265    
10266                            try {
10267                                    session = openSession();
10268    
10269                                    Query q = session.createQuery(sql);
10270    
10271                                    QueryPos qPos = QueryPos.getInstance(q);
10272    
10273                                    qPos.add(threadId);
10274    
10275                                    qPos.add(status);
10276    
10277                                    if (!pagination) {
10278                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10279                                                            start, end, false);
10280    
10281                                            Collections.sort(list);
10282    
10283                                            list = Collections.unmodifiableList(list);
10284                                    }
10285                                    else {
10286                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10287                                                            start, end);
10288                                    }
10289    
10290                                    cacheResult(list);
10291    
10292                                    finderCache.putResult(finderPath, finderArgs, list);
10293                            }
10294                            catch (Exception e) {
10295                                    finderCache.removeResult(finderPath, finderArgs);
10296    
10297                                    throw processException(e);
10298                            }
10299                            finally {
10300                                    closeSession(session);
10301                            }
10302                    }
10303    
10304                    return list;
10305            }
10306    
10307            /**
10308             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10309             *
10310             * @param threadId the thread ID
10311             * @param status the status
10312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10313             * @return the first matching message-boards message
10314             * @throws NoSuchMessageException if a matching message-boards message could not be found
10315             */
10316            @Override
10317            public MBMessage findByT_S_First(long threadId, int status,
10318                    OrderByComparator<MBMessage> orderByComparator)
10319                    throws NoSuchMessageException {
10320                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10321                                    orderByComparator);
10322    
10323                    if (mbMessage != null) {
10324                            return mbMessage;
10325                    }
10326    
10327                    StringBundler msg = new StringBundler(6);
10328    
10329                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10330    
10331                    msg.append("threadId=");
10332                    msg.append(threadId);
10333    
10334                    msg.append(", status=");
10335                    msg.append(status);
10336    
10337                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10338    
10339                    throw new NoSuchMessageException(msg.toString());
10340            }
10341    
10342            /**
10343             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10344             *
10345             * @param threadId the thread ID
10346             * @param status the status
10347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10348             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10349             */
10350            @Override
10351            public MBMessage fetchByT_S_First(long threadId, int status,
10352                    OrderByComparator<MBMessage> orderByComparator) {
10353                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10354                                    orderByComparator);
10355    
10356                    if (!list.isEmpty()) {
10357                            return list.get(0);
10358                    }
10359    
10360                    return null;
10361            }
10362    
10363            /**
10364             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10365             *
10366             * @param threadId the thread ID
10367             * @param status the status
10368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10369             * @return the last matching message-boards message
10370             * @throws NoSuchMessageException if a matching message-boards message could not be found
10371             */
10372            @Override
10373            public MBMessage findByT_S_Last(long threadId, int status,
10374                    OrderByComparator<MBMessage> orderByComparator)
10375                    throws NoSuchMessageException {
10376                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10377                                    orderByComparator);
10378    
10379                    if (mbMessage != null) {
10380                            return mbMessage;
10381                    }
10382    
10383                    StringBundler msg = new StringBundler(6);
10384    
10385                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10386    
10387                    msg.append("threadId=");
10388                    msg.append(threadId);
10389    
10390                    msg.append(", status=");
10391                    msg.append(status);
10392    
10393                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10394    
10395                    throw new NoSuchMessageException(msg.toString());
10396            }
10397    
10398            /**
10399             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10400             *
10401             * @param threadId the thread ID
10402             * @param status the status
10403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10404             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10405             */
10406            @Override
10407            public MBMessage fetchByT_S_Last(long threadId, int status,
10408                    OrderByComparator<MBMessage> orderByComparator) {
10409                    int count = countByT_S(threadId, status);
10410    
10411                    if (count == 0) {
10412                            return null;
10413                    }
10414    
10415                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10416                                    orderByComparator);
10417    
10418                    if (!list.isEmpty()) {
10419                            return list.get(0);
10420                    }
10421    
10422                    return null;
10423            }
10424    
10425            /**
10426             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10427             *
10428             * @param messageId the primary key of the current message-boards message
10429             * @param threadId the thread ID
10430             * @param status the status
10431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10432             * @return the previous, current, and next message-boards message
10433             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10434             */
10435            @Override
10436            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10437                    int status, OrderByComparator<MBMessage> orderByComparator)
10438                    throws NoSuchMessageException {
10439                    MBMessage mbMessage = findByPrimaryKey(messageId);
10440    
10441                    Session session = null;
10442    
10443                    try {
10444                            session = openSession();
10445    
10446                            MBMessage[] array = new MBMessageImpl[3];
10447    
10448                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10449                                            status, orderByComparator, true);
10450    
10451                            array[1] = mbMessage;
10452    
10453                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10454                                            status, orderByComparator, false);
10455    
10456                            return array;
10457                    }
10458                    catch (Exception e) {
10459                            throw processException(e);
10460                    }
10461                    finally {
10462                            closeSession(session);
10463                    }
10464            }
10465    
10466            protected MBMessage getByT_S_PrevAndNext(Session session,
10467                    MBMessage mbMessage, long threadId, int status,
10468                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10469                    StringBundler query = null;
10470    
10471                    if (orderByComparator != null) {
10472                            query = new StringBundler(5 +
10473                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10474                                            (orderByComparator.getOrderByFields().length * 3));
10475                    }
10476                    else {
10477                            query = new StringBundler(4);
10478                    }
10479    
10480                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10481    
10482                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10483    
10484                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10485    
10486                    if (orderByComparator != null) {
10487                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10488    
10489                            if (orderByConditionFields.length > 0) {
10490                                    query.append(WHERE_AND);
10491                            }
10492    
10493                            for (int i = 0; i < orderByConditionFields.length; i++) {
10494                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10495                                    query.append(orderByConditionFields[i]);
10496    
10497                                    if ((i + 1) < orderByConditionFields.length) {
10498                                            if (orderByComparator.isAscending() ^ previous) {
10499                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10500                                            }
10501                                            else {
10502                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10503                                            }
10504                                    }
10505                                    else {
10506                                            if (orderByComparator.isAscending() ^ previous) {
10507                                                    query.append(WHERE_GREATER_THAN);
10508                                            }
10509                                            else {
10510                                                    query.append(WHERE_LESSER_THAN);
10511                                            }
10512                                    }
10513                            }
10514    
10515                            query.append(ORDER_BY_CLAUSE);
10516    
10517                            String[] orderByFields = orderByComparator.getOrderByFields();
10518    
10519                            for (int i = 0; i < orderByFields.length; i++) {
10520                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10521                                    query.append(orderByFields[i]);
10522    
10523                                    if ((i + 1) < orderByFields.length) {
10524                                            if (orderByComparator.isAscending() ^ previous) {
10525                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10526                                            }
10527                                            else {
10528                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10529                                            }
10530                                    }
10531                                    else {
10532                                            if (orderByComparator.isAscending() ^ previous) {
10533                                                    query.append(ORDER_BY_ASC);
10534                                            }
10535                                            else {
10536                                                    query.append(ORDER_BY_DESC);
10537                                            }
10538                                    }
10539                            }
10540                    }
10541                    else {
10542                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10543                    }
10544    
10545                    String sql = query.toString();
10546    
10547                    Query q = session.createQuery(sql);
10548    
10549                    q.setFirstResult(0);
10550                    q.setMaxResults(2);
10551    
10552                    QueryPos qPos = QueryPos.getInstance(q);
10553    
10554                    qPos.add(threadId);
10555    
10556                    qPos.add(status);
10557    
10558                    if (orderByComparator != null) {
10559                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10560    
10561                            for (Object value : values) {
10562                                    qPos.add(value);
10563                            }
10564                    }
10565    
10566                    List<MBMessage> list = q.list();
10567    
10568                    if (list.size() == 2) {
10569                            return list.get(1);
10570                    }
10571                    else {
10572                            return null;
10573                    }
10574            }
10575    
10576            /**
10577             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10578             *
10579             * @param threadId the thread ID
10580             * @param status the status
10581             */
10582            @Override
10583            public void removeByT_S(long threadId, int status) {
10584                    for (MBMessage mbMessage : findByT_S(threadId, status,
10585                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10586                            remove(mbMessage);
10587                    }
10588            }
10589    
10590            /**
10591             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10592             *
10593             * @param threadId the thread ID
10594             * @param status the status
10595             * @return the number of matching message-boards messages
10596             */
10597            @Override
10598            public int countByT_S(long threadId, int status) {
10599                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10600    
10601                    Object[] finderArgs = new Object[] { threadId, status };
10602    
10603                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10604    
10605                    if (count == null) {
10606                            StringBundler query = new StringBundler(3);
10607    
10608                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10609    
10610                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10611    
10612                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10613    
10614                            String sql = query.toString();
10615    
10616                            Session session = null;
10617    
10618                            try {
10619                                    session = openSession();
10620    
10621                                    Query q = session.createQuery(sql);
10622    
10623                                    QueryPos qPos = QueryPos.getInstance(q);
10624    
10625                                    qPos.add(threadId);
10626    
10627                                    qPos.add(status);
10628    
10629                                    count = (Long)q.uniqueResult();
10630    
10631                                    finderCache.putResult(finderPath, finderArgs, count);
10632                            }
10633                            catch (Exception e) {
10634                                    finderCache.removeResult(finderPath, finderArgs);
10635    
10636                                    throw processException(e);
10637                            }
10638                            finally {
10639                                    closeSession(session);
10640                            }
10641                    }
10642    
10643                    return count.intValue();
10644            }
10645    
10646            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10647            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10648            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10649                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10650                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10651                            new String[] {
10652                                    Long.class.getName(), Integer.class.getName(),
10653                                    
10654                            Integer.class.getName(), Integer.class.getName(),
10655                                    OrderByComparator.class.getName()
10656                            });
10657            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10658                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10659                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10660                            new String[] { Long.class.getName(), Integer.class.getName() },
10661                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10662                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10663                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10664            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10665                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10666                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10667                            new String[] { Long.class.getName(), Integer.class.getName() });
10668    
10669            /**
10670             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10671             *
10672             * @param threadId the thread ID
10673             * @param status the status
10674             * @return the matching message-boards messages
10675             */
10676            @Override
10677            public List<MBMessage> findByTR_S(long threadId, int status) {
10678                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10679                            QueryUtil.ALL_POS, null);
10680            }
10681    
10682            /**
10683             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10684             *
10685             * <p>
10686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10687             * </p>
10688             *
10689             * @param threadId the thread ID
10690             * @param status the status
10691             * @param start the lower bound of the range of message-boards messages
10692             * @param end the upper bound of the range of message-boards messages (not inclusive)
10693             * @return the range of matching message-boards messages
10694             */
10695            @Override
10696            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10697                    int end) {
10698                    return findByTR_S(threadId, status, start, end, null);
10699            }
10700    
10701            /**
10702             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10703             *
10704             * <p>
10705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10706             * </p>
10707             *
10708             * @param threadId the thread ID
10709             * @param status the status
10710             * @param start the lower bound of the range of message-boards messages
10711             * @param end the upper bound of the range of message-boards messages (not inclusive)
10712             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10713             * @return the ordered range of matching message-boards messages
10714             */
10715            @Override
10716            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10717                    int end, OrderByComparator<MBMessage> orderByComparator) {
10718                    return findByTR_S(threadId, status, start, end, orderByComparator, true);
10719            }
10720    
10721            /**
10722             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10723             *
10724             * <p>
10725             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10726             * </p>
10727             *
10728             * @param threadId the thread ID
10729             * @param status the status
10730             * @param start the lower bound of the range of message-boards messages
10731             * @param end the upper bound of the range of message-boards messages (not inclusive)
10732             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10733             * @param retrieveFromCache whether to retrieve from the finder cache
10734             * @return the ordered range of matching message-boards messages
10735             */
10736            @Override
10737            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10738                    int end, OrderByComparator<MBMessage> orderByComparator,
10739                    boolean retrieveFromCache) {
10740                    boolean pagination = true;
10741                    FinderPath finderPath = null;
10742                    Object[] finderArgs = null;
10743    
10744                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10745                                    (orderByComparator == null)) {
10746                            pagination = false;
10747                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10748                            finderArgs = new Object[] { threadId, status };
10749                    }
10750                    else {
10751                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10752                            finderArgs = new Object[] {
10753                                            threadId, status,
10754                                            
10755                                            start, end, orderByComparator
10756                                    };
10757                    }
10758    
10759                    List<MBMessage> list = null;
10760    
10761                    if (retrieveFromCache) {
10762                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10763                                            finderArgs, this);
10764    
10765                            if ((list != null) && !list.isEmpty()) {
10766                                    for (MBMessage mbMessage : list) {
10767                                            if ((threadId != mbMessage.getThreadId()) ||
10768                                                            (status != mbMessage.getStatus())) {
10769                                                    list = null;
10770    
10771                                                    break;
10772                                            }
10773                                    }
10774                            }
10775                    }
10776    
10777                    if (list == null) {
10778                            StringBundler query = null;
10779    
10780                            if (orderByComparator != null) {
10781                                    query = new StringBundler(4 +
10782                                                    (orderByComparator.getOrderByFields().length * 2));
10783                            }
10784                            else {
10785                                    query = new StringBundler(4);
10786                            }
10787    
10788                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10789    
10790                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10791    
10792                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10793    
10794                            if (orderByComparator != null) {
10795                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10796                                            orderByComparator);
10797                            }
10798                            else
10799                             if (pagination) {
10800                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10801                            }
10802    
10803                            String sql = query.toString();
10804    
10805                            Session session = null;
10806    
10807                            try {
10808                                    session = openSession();
10809    
10810                                    Query q = session.createQuery(sql);
10811    
10812                                    QueryPos qPos = QueryPos.getInstance(q);
10813    
10814                                    qPos.add(threadId);
10815    
10816                                    qPos.add(status);
10817    
10818                                    if (!pagination) {
10819                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10820                                                            start, end, false);
10821    
10822                                            Collections.sort(list);
10823    
10824                                            list = Collections.unmodifiableList(list);
10825                                    }
10826                                    else {
10827                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10828                                                            start, end);
10829                                    }
10830    
10831                                    cacheResult(list);
10832    
10833                                    finderCache.putResult(finderPath, finderArgs, list);
10834                            }
10835                            catch (Exception e) {
10836                                    finderCache.removeResult(finderPath, finderArgs);
10837    
10838                                    throw processException(e);
10839                            }
10840                            finally {
10841                                    closeSession(session);
10842                            }
10843                    }
10844    
10845                    return list;
10846            }
10847    
10848            /**
10849             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10850             *
10851             * @param threadId the thread ID
10852             * @param status the status
10853             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10854             * @return the first matching message-boards message
10855             * @throws NoSuchMessageException if a matching message-boards message could not be found
10856             */
10857            @Override
10858            public MBMessage findByTR_S_First(long threadId, int status,
10859                    OrderByComparator<MBMessage> orderByComparator)
10860                    throws NoSuchMessageException {
10861                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10862                                    orderByComparator);
10863    
10864                    if (mbMessage != null) {
10865                            return mbMessage;
10866                    }
10867    
10868                    StringBundler msg = new StringBundler(6);
10869    
10870                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10871    
10872                    msg.append("threadId=");
10873                    msg.append(threadId);
10874    
10875                    msg.append(", status=");
10876                    msg.append(status);
10877    
10878                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10879    
10880                    throw new NoSuchMessageException(msg.toString());
10881            }
10882    
10883            /**
10884             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10885             *
10886             * @param threadId the thread ID
10887             * @param status the status
10888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10889             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10890             */
10891            @Override
10892            public MBMessage fetchByTR_S_First(long threadId, int status,
10893                    OrderByComparator<MBMessage> orderByComparator) {
10894                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10895                                    orderByComparator);
10896    
10897                    if (!list.isEmpty()) {
10898                            return list.get(0);
10899                    }
10900    
10901                    return null;
10902            }
10903    
10904            /**
10905             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10906             *
10907             * @param threadId the thread ID
10908             * @param status the status
10909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10910             * @return the last matching message-boards message
10911             * @throws NoSuchMessageException if a matching message-boards message could not be found
10912             */
10913            @Override
10914            public MBMessage findByTR_S_Last(long threadId, int status,
10915                    OrderByComparator<MBMessage> orderByComparator)
10916                    throws NoSuchMessageException {
10917                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10918                                    orderByComparator);
10919    
10920                    if (mbMessage != null) {
10921                            return mbMessage;
10922                    }
10923    
10924                    StringBundler msg = new StringBundler(6);
10925    
10926                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10927    
10928                    msg.append("threadId=");
10929                    msg.append(threadId);
10930    
10931                    msg.append(", status=");
10932                    msg.append(status);
10933    
10934                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10935    
10936                    throw new NoSuchMessageException(msg.toString());
10937            }
10938    
10939            /**
10940             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10941             *
10942             * @param threadId the thread ID
10943             * @param status the status
10944             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10945             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10946             */
10947            @Override
10948            public MBMessage fetchByTR_S_Last(long threadId, int status,
10949                    OrderByComparator<MBMessage> orderByComparator) {
10950                    int count = countByTR_S(threadId, status);
10951    
10952                    if (count == 0) {
10953                            return null;
10954                    }
10955    
10956                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10957                                    orderByComparator);
10958    
10959                    if (!list.isEmpty()) {
10960                            return list.get(0);
10961                    }
10962    
10963                    return null;
10964            }
10965    
10966            /**
10967             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10968             *
10969             * @param messageId the primary key of the current message-boards message
10970             * @param threadId the thread ID
10971             * @param status the status
10972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10973             * @return the previous, current, and next message-boards message
10974             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10975             */
10976            @Override
10977            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10978                    int status, OrderByComparator<MBMessage> orderByComparator)
10979                    throws NoSuchMessageException {
10980                    MBMessage mbMessage = findByPrimaryKey(messageId);
10981    
10982                    Session session = null;
10983    
10984                    try {
10985                            session = openSession();
10986    
10987                            MBMessage[] array = new MBMessageImpl[3];
10988    
10989                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10990                                            status, orderByComparator, true);
10991    
10992                            array[1] = mbMessage;
10993    
10994                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10995                                            status, orderByComparator, false);
10996    
10997                            return array;
10998                    }
10999                    catch (Exception e) {
11000                            throw processException(e);
11001                    }
11002                    finally {
11003                            closeSession(session);
11004                    }
11005            }
11006    
11007            protected MBMessage getByTR_S_PrevAndNext(Session session,
11008                    MBMessage mbMessage, long threadId, int status,
11009                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11010                    StringBundler query = null;
11011    
11012                    if (orderByComparator != null) {
11013                            query = new StringBundler(5 +
11014                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11015                                            (orderByComparator.getOrderByFields().length * 3));
11016                    }
11017                    else {
11018                            query = new StringBundler(4);
11019                    }
11020    
11021                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11022    
11023                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11024    
11025                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11026    
11027                    if (orderByComparator != null) {
11028                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11029    
11030                            if (orderByConditionFields.length > 0) {
11031                                    query.append(WHERE_AND);
11032                            }
11033    
11034                            for (int i = 0; i < orderByConditionFields.length; i++) {
11035                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11036                                    query.append(orderByConditionFields[i]);
11037    
11038                                    if ((i + 1) < orderByConditionFields.length) {
11039                                            if (orderByComparator.isAscending() ^ previous) {
11040                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11041                                            }
11042                                            else {
11043                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11044                                            }
11045                                    }
11046                                    else {
11047                                            if (orderByComparator.isAscending() ^ previous) {
11048                                                    query.append(WHERE_GREATER_THAN);
11049                                            }
11050                                            else {
11051                                                    query.append(WHERE_LESSER_THAN);
11052                                            }
11053                                    }
11054                            }
11055    
11056                            query.append(ORDER_BY_CLAUSE);
11057    
11058                            String[] orderByFields = orderByComparator.getOrderByFields();
11059    
11060                            for (int i = 0; i < orderByFields.length; i++) {
11061                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11062                                    query.append(orderByFields[i]);
11063    
11064                                    if ((i + 1) < orderByFields.length) {
11065                                            if (orderByComparator.isAscending() ^ previous) {
11066                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11067                                            }
11068                                            else {
11069                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11070                                            }
11071                                    }
11072                                    else {
11073                                            if (orderByComparator.isAscending() ^ previous) {
11074                                                    query.append(ORDER_BY_ASC);
11075                                            }
11076                                            else {
11077                                                    query.append(ORDER_BY_DESC);
11078                                            }
11079                                    }
11080                            }
11081                    }
11082                    else {
11083                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11084                    }
11085    
11086                    String sql = query.toString();
11087    
11088                    Query q = session.createQuery(sql);
11089    
11090                    q.setFirstResult(0);
11091                    q.setMaxResults(2);
11092    
11093                    QueryPos qPos = QueryPos.getInstance(q);
11094    
11095                    qPos.add(threadId);
11096    
11097                    qPos.add(status);
11098    
11099                    if (orderByComparator != null) {
11100                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11101    
11102                            for (Object value : values) {
11103                                    qPos.add(value);
11104                            }
11105                    }
11106    
11107                    List<MBMessage> list = q.list();
11108    
11109                    if (list.size() == 2) {
11110                            return list.get(1);
11111                    }
11112                    else {
11113                            return null;
11114                    }
11115            }
11116    
11117            /**
11118             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
11119             *
11120             * @param threadId the thread ID
11121             * @param status the status
11122             */
11123            @Override
11124            public void removeByTR_S(long threadId, int status) {
11125                    for (MBMessage mbMessage : findByTR_S(threadId, status,
11126                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11127                            remove(mbMessage);
11128                    }
11129            }
11130    
11131            /**
11132             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
11133             *
11134             * @param threadId the thread ID
11135             * @param status the status
11136             * @return the number of matching message-boards messages
11137             */
11138            @Override
11139            public int countByTR_S(long threadId, int status) {
11140                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
11141    
11142                    Object[] finderArgs = new Object[] { threadId, status };
11143    
11144                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
11145    
11146                    if (count == null) {
11147                            StringBundler query = new StringBundler(3);
11148    
11149                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11150    
11151                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11152    
11153                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11154    
11155                            String sql = query.toString();
11156    
11157                            Session session = null;
11158    
11159                            try {
11160                                    session = openSession();
11161    
11162                                    Query q = session.createQuery(sql);
11163    
11164                                    QueryPos qPos = QueryPos.getInstance(q);
11165    
11166                                    qPos.add(threadId);
11167    
11168                                    qPos.add(status);
11169    
11170                                    count = (Long)q.uniqueResult();
11171    
11172                                    finderCache.putResult(finderPath, finderArgs, count);
11173                            }
11174                            catch (Exception e) {
11175                                    finderCache.removeResult(finderPath, finderArgs);
11176    
11177                                    throw processException(e);
11178                            }
11179                            finally {
11180                                    closeSession(session);
11181                            }
11182                    }
11183    
11184                    return count.intValue();
11185            }
11186    
11187            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11188            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11189            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11190                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11191                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
11192                            new String[] {
11193                                    Long.class.getName(), Long.class.getName(),
11194                                    Integer.class.getName(),
11195                                    
11196                            Integer.class.getName(), Integer.class.getName(),
11197                                    OrderByComparator.class.getName()
11198                            });
11199            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11200                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
11202                            new String[] {
11203                                    Long.class.getName(), Long.class.getName(),
11204                                    Integer.class.getName()
11205                            },
11206                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11207                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
11208                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
11209                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11210            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11211                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11212                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
11213                            new String[] {
11214                                    Long.class.getName(), Long.class.getName(),
11215                                    Integer.class.getName()
11216                            });
11217    
11218            /**
11219             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11220             *
11221             * @param groupId the group ID
11222             * @param userId the user ID
11223             * @param status the status
11224             * @return the matching message-boards messages
11225             */
11226            @Override
11227            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
11228                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11229                            QueryUtil.ALL_POS, null);
11230            }
11231    
11232            /**
11233             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11234             *
11235             * <p>
11236             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11237             * </p>
11238             *
11239             * @param groupId the group ID
11240             * @param userId the user ID
11241             * @param status the status
11242             * @param start the lower bound of the range of message-boards messages
11243             * @param end the upper bound of the range of message-boards messages (not inclusive)
11244             * @return the range of matching message-boards messages
11245             */
11246            @Override
11247            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11248                    int start, int end) {
11249                    return findByG_U_S(groupId, userId, status, start, end, null);
11250            }
11251    
11252            /**
11253             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11254             *
11255             * <p>
11256             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11257             * </p>
11258             *
11259             * @param groupId the group ID
11260             * @param userId the user ID
11261             * @param status the status
11262             * @param start the lower bound of the range of message-boards messages
11263             * @param end the upper bound of the range of message-boards messages (not inclusive)
11264             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11265             * @return the ordered range of matching message-boards messages
11266             */
11267            @Override
11268            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11269                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
11270                    return findByG_U_S(groupId, userId, status, start, end,
11271                            orderByComparator, true);
11272            }
11273    
11274            /**
11275             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11276             *
11277             * <p>
11278             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11279             * </p>
11280             *
11281             * @param groupId the group ID
11282             * @param userId the user ID
11283             * @param status the status
11284             * @param start the lower bound of the range of message-boards messages
11285             * @param end the upper bound of the range of message-boards messages (not inclusive)
11286             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11287             * @param retrieveFromCache whether to retrieve from the finder cache
11288             * @return the ordered range of matching message-boards messages
11289             */
11290            @Override
11291            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11292                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
11293                    boolean retrieveFromCache) {
11294                    boolean pagination = true;
11295                    FinderPath finderPath = null;
11296                    Object[] finderArgs = null;
11297    
11298                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11299                                    (orderByComparator == null)) {
11300                            pagination = false;
11301                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11302                            finderArgs = new Object[] { groupId, userId, status };
11303                    }
11304                    else {
11305                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11306                            finderArgs = new Object[] {
11307                                            groupId, userId, status,
11308                                            
11309                                            start, end, orderByComparator
11310                                    };
11311                    }
11312    
11313                    List<MBMessage> list = null;
11314    
11315                    if (retrieveFromCache) {
11316                            list = (List<MBMessage>)finderCache.getResult(finderPath,
11317                                            finderArgs, this);
11318    
11319                            if ((list != null) && !list.isEmpty()) {
11320                                    for (MBMessage mbMessage : list) {
11321                                            if ((groupId != mbMessage.getGroupId()) ||
11322                                                            (userId != mbMessage.getUserId()) ||
11323                                                            (status != mbMessage.getStatus())) {
11324                                                    list = null;
11325    
11326                                                    break;
11327                                            }
11328                                    }
11329                            }
11330                    }
11331    
11332                    if (list == null) {
11333                            StringBundler query = null;
11334    
11335                            if (orderByComparator != null) {
11336                                    query = new StringBundler(5 +
11337                                                    (orderByComparator.getOrderByFields().length * 2));
11338                            }
11339                            else {
11340                                    query = new StringBundler(5);
11341                            }
11342    
11343                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11344    
11345                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11346    
11347                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11348    
11349                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11350    
11351                            if (orderByComparator != null) {
11352                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11353                                            orderByComparator);
11354                            }
11355                            else
11356                             if (pagination) {
11357                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11358                            }
11359    
11360                            String sql = query.toString();
11361    
11362                            Session session = null;
11363    
11364                            try {
11365                                    session = openSession();
11366    
11367                                    Query q = session.createQuery(sql);
11368    
11369                                    QueryPos qPos = QueryPos.getInstance(q);
11370    
11371                                    qPos.add(groupId);
11372    
11373                                    qPos.add(userId);
11374    
11375                                    qPos.add(status);
11376    
11377                                    if (!pagination) {
11378                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11379                                                            start, end, false);
11380    
11381                                            Collections.sort(list);
11382    
11383                                            list = Collections.unmodifiableList(list);
11384                                    }
11385                                    else {
11386                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11387                                                            start, end);
11388                                    }
11389    
11390                                    cacheResult(list);
11391    
11392                                    finderCache.putResult(finderPath, finderArgs, list);
11393                            }
11394                            catch (Exception e) {
11395                                    finderCache.removeResult(finderPath, finderArgs);
11396    
11397                                    throw processException(e);
11398                            }
11399                            finally {
11400                                    closeSession(session);
11401                            }
11402                    }
11403    
11404                    return list;
11405            }
11406    
11407            /**
11408             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11409             *
11410             * @param groupId the group ID
11411             * @param userId the user ID
11412             * @param status the status
11413             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11414             * @return the first matching message-boards message
11415             * @throws NoSuchMessageException if a matching message-boards message could not be found
11416             */
11417            @Override
11418            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11419                    OrderByComparator<MBMessage> orderByComparator)
11420                    throws NoSuchMessageException {
11421                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11422                                    orderByComparator);
11423    
11424                    if (mbMessage != null) {
11425                            return mbMessage;
11426                    }
11427    
11428                    StringBundler msg = new StringBundler(8);
11429    
11430                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11431    
11432                    msg.append("groupId=");
11433                    msg.append(groupId);
11434    
11435                    msg.append(", userId=");
11436                    msg.append(userId);
11437    
11438                    msg.append(", status=");
11439                    msg.append(status);
11440    
11441                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11442    
11443                    throw new NoSuchMessageException(msg.toString());
11444            }
11445    
11446            /**
11447             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11448             *
11449             * @param groupId the group ID
11450             * @param userId the user ID
11451             * @param status the status
11452             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11453             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11454             */
11455            @Override
11456            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11457                    OrderByComparator<MBMessage> orderByComparator) {
11458                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11459                                    orderByComparator);
11460    
11461                    if (!list.isEmpty()) {
11462                            return list.get(0);
11463                    }
11464    
11465                    return null;
11466            }
11467    
11468            /**
11469             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11470             *
11471             * @param groupId the group ID
11472             * @param userId the user ID
11473             * @param status the status
11474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11475             * @return the last matching message-boards message
11476             * @throws NoSuchMessageException if a matching message-boards message could not be found
11477             */
11478            @Override
11479            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11480                    OrderByComparator<MBMessage> orderByComparator)
11481                    throws NoSuchMessageException {
11482                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11483                                    orderByComparator);
11484    
11485                    if (mbMessage != null) {
11486                            return mbMessage;
11487                    }
11488    
11489                    StringBundler msg = new StringBundler(8);
11490    
11491                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11492    
11493                    msg.append("groupId=");
11494                    msg.append(groupId);
11495    
11496                    msg.append(", userId=");
11497                    msg.append(userId);
11498    
11499                    msg.append(", status=");
11500                    msg.append(status);
11501    
11502                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11503    
11504                    throw new NoSuchMessageException(msg.toString());
11505            }
11506    
11507            /**
11508             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11509             *
11510             * @param groupId the group ID
11511             * @param userId the user ID
11512             * @param status the status
11513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11514             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11515             */
11516            @Override
11517            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11518                    OrderByComparator<MBMessage> orderByComparator) {
11519                    int count = countByG_U_S(groupId, userId, status);
11520    
11521                    if (count == 0) {
11522                            return null;
11523                    }
11524    
11525                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11526                                    count, orderByComparator);
11527    
11528                    if (!list.isEmpty()) {
11529                            return list.get(0);
11530                    }
11531    
11532                    return null;
11533            }
11534    
11535            /**
11536             * 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;.
11537             *
11538             * @param messageId the primary key of the current message-boards message
11539             * @param groupId the group ID
11540             * @param userId the user ID
11541             * @param status the status
11542             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11543             * @return the previous, current, and next message-boards message
11544             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11545             */
11546            @Override
11547            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11548                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11549                    throws NoSuchMessageException {
11550                    MBMessage mbMessage = findByPrimaryKey(messageId);
11551    
11552                    Session session = null;
11553    
11554                    try {
11555                            session = openSession();
11556    
11557                            MBMessage[] array = new MBMessageImpl[3];
11558    
11559                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11560                                            userId, status, orderByComparator, true);
11561    
11562                            array[1] = mbMessage;
11563    
11564                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11565                                            userId, status, orderByComparator, false);
11566    
11567                            return array;
11568                    }
11569                    catch (Exception e) {
11570                            throw processException(e);
11571                    }
11572                    finally {
11573                            closeSession(session);
11574                    }
11575            }
11576    
11577            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11578                    MBMessage mbMessage, long groupId, long userId, int status,
11579                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11580                    StringBundler query = null;
11581    
11582                    if (orderByComparator != null) {
11583                            query = new StringBundler(6 +
11584                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11585                                            (orderByComparator.getOrderByFields().length * 3));
11586                    }
11587                    else {
11588                            query = new StringBundler(5);
11589                    }
11590    
11591                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11592    
11593                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11594    
11595                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11596    
11597                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11598    
11599                    if (orderByComparator != null) {
11600                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11601    
11602                            if (orderByConditionFields.length > 0) {
11603                                    query.append(WHERE_AND);
11604                            }
11605    
11606                            for (int i = 0; i < orderByConditionFields.length; i++) {
11607                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11608                                    query.append(orderByConditionFields[i]);
11609    
11610                                    if ((i + 1) < orderByConditionFields.length) {
11611                                            if (orderByComparator.isAscending() ^ previous) {
11612                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11613                                            }
11614                                            else {
11615                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11616                                            }
11617                                    }
11618                                    else {
11619                                            if (orderByComparator.isAscending() ^ previous) {
11620                                                    query.append(WHERE_GREATER_THAN);
11621                                            }
11622                                            else {
11623                                                    query.append(WHERE_LESSER_THAN);
11624                                            }
11625                                    }
11626                            }
11627    
11628                            query.append(ORDER_BY_CLAUSE);
11629    
11630                            String[] orderByFields = orderByComparator.getOrderByFields();
11631    
11632                            for (int i = 0; i < orderByFields.length; i++) {
11633                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11634                                    query.append(orderByFields[i]);
11635    
11636                                    if ((i + 1) < orderByFields.length) {
11637                                            if (orderByComparator.isAscending() ^ previous) {
11638                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11639                                            }
11640                                            else {
11641                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11642                                            }
11643                                    }
11644                                    else {
11645                                            if (orderByComparator.isAscending() ^ previous) {
11646                                                    query.append(ORDER_BY_ASC);
11647                                            }
11648                                            else {
11649                                                    query.append(ORDER_BY_DESC);
11650                                            }
11651                                    }
11652                            }
11653                    }
11654                    else {
11655                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11656                    }
11657    
11658                    String sql = query.toString();
11659    
11660                    Query q = session.createQuery(sql);
11661    
11662                    q.setFirstResult(0);
11663                    q.setMaxResults(2);
11664    
11665                    QueryPos qPos = QueryPos.getInstance(q);
11666    
11667                    qPos.add(groupId);
11668    
11669                    qPos.add(userId);
11670    
11671                    qPos.add(status);
11672    
11673                    if (orderByComparator != null) {
11674                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11675    
11676                            for (Object value : values) {
11677                                    qPos.add(value);
11678                            }
11679                    }
11680    
11681                    List<MBMessage> list = q.list();
11682    
11683                    if (list.size() == 2) {
11684                            return list.get(1);
11685                    }
11686                    else {
11687                            return null;
11688                    }
11689            }
11690    
11691            /**
11692             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11693             *
11694             * @param groupId the group ID
11695             * @param userId the user ID
11696             * @param status the status
11697             * @return the matching message-boards messages that the user has permission to view
11698             */
11699            @Override
11700            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11701                    int status) {
11702                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11703                            QueryUtil.ALL_POS, null);
11704            }
11705    
11706            /**
11707             * 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;.
11708             *
11709             * <p>
11710             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11711             * </p>
11712             *
11713             * @param groupId the group ID
11714             * @param userId the user ID
11715             * @param status the status
11716             * @param start the lower bound of the range of message-boards messages
11717             * @param end the upper bound of the range of message-boards messages (not inclusive)
11718             * @return the range of matching message-boards messages that the user has permission to view
11719             */
11720            @Override
11721            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11722                    int status, int start, int end) {
11723                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11724            }
11725    
11726            /**
11727             * 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;.
11728             *
11729             * <p>
11730             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11731             * </p>
11732             *
11733             * @param groupId the group ID
11734             * @param userId the user ID
11735             * @param status the status
11736             * @param start the lower bound of the range of message-boards messages
11737             * @param end the upper bound of the range of message-boards messages (not inclusive)
11738             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11739             * @return the ordered range of matching message-boards messages that the user has permission to view
11740             */
11741            @Override
11742            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11743                    int status, int start, int end,
11744                    OrderByComparator<MBMessage> orderByComparator) {
11745                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11746                            return findByG_U_S(groupId, userId, status, start, end,
11747                                    orderByComparator);
11748                    }
11749    
11750                    StringBundler query = null;
11751    
11752                    if (orderByComparator != null) {
11753                            query = new StringBundler(5 +
11754                                            (orderByComparator.getOrderByFields().length * 2));
11755                    }
11756                    else {
11757                            query = new StringBundler(6);
11758                    }
11759    
11760                    if (getDB().isSupportsInlineDistinct()) {
11761                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11762                    }
11763                    else {
11764                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11765                    }
11766    
11767                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11768    
11769                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11770    
11771                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11772    
11773                    if (!getDB().isSupportsInlineDistinct()) {
11774                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11775                    }
11776    
11777                    if (orderByComparator != null) {
11778                            if (getDB().isSupportsInlineDistinct()) {
11779                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11780                                            orderByComparator, true);
11781                            }
11782                            else {
11783                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11784                                            orderByComparator, true);
11785                            }
11786                    }
11787                    else {
11788                            if (getDB().isSupportsInlineDistinct()) {
11789                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11790                            }
11791                            else {
11792                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11793                            }
11794                    }
11795    
11796                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11797                                    MBMessage.class.getName(),
11798                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11799    
11800                    Session session = null;
11801    
11802                    try {
11803                            session = openSession();
11804    
11805                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11806    
11807                            if (getDB().isSupportsInlineDistinct()) {
11808                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11809                            }
11810                            else {
11811                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11812                            }
11813    
11814                            QueryPos qPos = QueryPos.getInstance(q);
11815    
11816                            qPos.add(groupId);
11817    
11818                            qPos.add(userId);
11819    
11820                            qPos.add(status);
11821    
11822                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11823                    }
11824                    catch (Exception e) {
11825                            throw processException(e);
11826                    }
11827                    finally {
11828                            closeSession(session);
11829                    }
11830            }
11831    
11832            /**
11833             * 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;.
11834             *
11835             * @param messageId the primary key of the current message-boards message
11836             * @param groupId the group ID
11837             * @param userId the user ID
11838             * @param status the status
11839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11840             * @return the previous, current, and next message-boards message
11841             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11842             */
11843            @Override
11844            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11845                    long groupId, long userId, int status,
11846                    OrderByComparator<MBMessage> orderByComparator)
11847                    throws NoSuchMessageException {
11848                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11849                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11850                                    orderByComparator);
11851                    }
11852    
11853                    MBMessage mbMessage = findByPrimaryKey(messageId);
11854    
11855                    Session session = null;
11856    
11857                    try {
11858                            session = openSession();
11859    
11860                            MBMessage[] array = new MBMessageImpl[3];
11861    
11862                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11863                                            groupId, userId, status, orderByComparator, true);
11864    
11865                            array[1] = mbMessage;
11866    
11867                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11868                                            groupId, userId, status, orderByComparator, false);
11869    
11870                            return array;
11871                    }
11872                    catch (Exception e) {
11873                            throw processException(e);
11874                    }
11875                    finally {
11876                            closeSession(session);
11877                    }
11878            }
11879    
11880            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11881                    MBMessage mbMessage, long groupId, long userId, int status,
11882                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11883                    StringBundler query = null;
11884    
11885                    if (orderByComparator != null) {
11886                            query = new StringBundler(7 +
11887                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11888                                            (orderByComparator.getOrderByFields().length * 3));
11889                    }
11890                    else {
11891                            query = new StringBundler(6);
11892                    }
11893    
11894                    if (getDB().isSupportsInlineDistinct()) {
11895                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11896                    }
11897                    else {
11898                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11899                    }
11900    
11901                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11902    
11903                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11904    
11905                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11906    
11907                    if (!getDB().isSupportsInlineDistinct()) {
11908                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11909                    }
11910    
11911                    if (orderByComparator != null) {
11912                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11913    
11914                            if (orderByConditionFields.length > 0) {
11915                                    query.append(WHERE_AND);
11916                            }
11917    
11918                            for (int i = 0; i < orderByConditionFields.length; i++) {
11919                                    if (getDB().isSupportsInlineDistinct()) {
11920                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11921                                    }
11922                                    else {
11923                                            query.append(_ORDER_BY_ENTITY_TABLE);
11924                                    }
11925    
11926                                    query.append(orderByConditionFields[i]);
11927    
11928                                    if ((i + 1) < orderByConditionFields.length) {
11929                                            if (orderByComparator.isAscending() ^ previous) {
11930                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11931                                            }
11932                                            else {
11933                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11934                                            }
11935                                    }
11936                                    else {
11937                                            if (orderByComparator.isAscending() ^ previous) {
11938                                                    query.append(WHERE_GREATER_THAN);
11939                                            }
11940                                            else {
11941                                                    query.append(WHERE_LESSER_THAN);
11942                                            }
11943                                    }
11944                            }
11945    
11946                            query.append(ORDER_BY_CLAUSE);
11947    
11948                            String[] orderByFields = orderByComparator.getOrderByFields();
11949    
11950                            for (int i = 0; i < orderByFields.length; i++) {
11951                                    if (getDB().isSupportsInlineDistinct()) {
11952                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11953                                    }
11954                                    else {
11955                                            query.append(_ORDER_BY_ENTITY_TABLE);
11956                                    }
11957    
11958                                    query.append(orderByFields[i]);
11959    
11960                                    if ((i + 1) < orderByFields.length) {
11961                                            if (orderByComparator.isAscending() ^ previous) {
11962                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11963                                            }
11964                                            else {
11965                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11966                                            }
11967                                    }
11968                                    else {
11969                                            if (orderByComparator.isAscending() ^ previous) {
11970                                                    query.append(ORDER_BY_ASC);
11971                                            }
11972                                            else {
11973                                                    query.append(ORDER_BY_DESC);
11974                                            }
11975                                    }
11976                            }
11977                    }
11978                    else {
11979                            if (getDB().isSupportsInlineDistinct()) {
11980                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11981                            }
11982                            else {
11983                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11984                            }
11985                    }
11986    
11987                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11988                                    MBMessage.class.getName(),
11989                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11990    
11991                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11992    
11993                    q.setFirstResult(0);
11994                    q.setMaxResults(2);
11995    
11996                    if (getDB().isSupportsInlineDistinct()) {
11997                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11998                    }
11999                    else {
12000                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12001                    }
12002    
12003                    QueryPos qPos = QueryPos.getInstance(q);
12004    
12005                    qPos.add(groupId);
12006    
12007                    qPos.add(userId);
12008    
12009                    qPos.add(status);
12010    
12011                    if (orderByComparator != null) {
12012                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12013    
12014                            for (Object value : values) {
12015                                    qPos.add(value);
12016                            }
12017                    }
12018    
12019                    List<MBMessage> list = q.list();
12020    
12021                    if (list.size() == 2) {
12022                            return list.get(1);
12023                    }
12024                    else {
12025                            return null;
12026                    }
12027            }
12028    
12029            /**
12030             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
12031             *
12032             * @param groupId the group ID
12033             * @param userId the user ID
12034             * @param status the status
12035             */
12036            @Override
12037            public void removeByG_U_S(long groupId, long userId, int status) {
12038                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
12039                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12040                            remove(mbMessage);
12041                    }
12042            }
12043    
12044            /**
12045             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
12046             *
12047             * @param groupId the group ID
12048             * @param userId the user ID
12049             * @param status the status
12050             * @return the number of matching message-boards messages
12051             */
12052            @Override
12053            public int countByG_U_S(long groupId, long userId, int status) {
12054                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
12055    
12056                    Object[] finderArgs = new Object[] { groupId, userId, status };
12057    
12058                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12059    
12060                    if (count == null) {
12061                            StringBundler query = new StringBundler(4);
12062    
12063                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12064    
12065                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12066    
12067                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12068    
12069                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12070    
12071                            String sql = query.toString();
12072    
12073                            Session session = null;
12074    
12075                            try {
12076                                    session = openSession();
12077    
12078                                    Query q = session.createQuery(sql);
12079    
12080                                    QueryPos qPos = QueryPos.getInstance(q);
12081    
12082                                    qPos.add(groupId);
12083    
12084                                    qPos.add(userId);
12085    
12086                                    qPos.add(status);
12087    
12088                                    count = (Long)q.uniqueResult();
12089    
12090                                    finderCache.putResult(finderPath, finderArgs, count);
12091                            }
12092                            catch (Exception e) {
12093                                    finderCache.removeResult(finderPath, finderArgs);
12094    
12095                                    throw processException(e);
12096                            }
12097                            finally {
12098                                    closeSession(session);
12099                            }
12100                    }
12101    
12102                    return count.intValue();
12103            }
12104    
12105            /**
12106             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
12107             *
12108             * @param groupId the group ID
12109             * @param userId the user ID
12110             * @param status the status
12111             * @return the number of matching message-boards messages that the user has permission to view
12112             */
12113            @Override
12114            public int filterCountByG_U_S(long groupId, long userId, int status) {
12115                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12116                            return countByG_U_S(groupId, userId, status);
12117                    }
12118    
12119                    StringBundler query = new StringBundler(4);
12120    
12121                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12122    
12123                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12124    
12125                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12126    
12127                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12128    
12129                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12130                                    MBMessage.class.getName(),
12131                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12132    
12133                    Session session = null;
12134    
12135                    try {
12136                            session = openSession();
12137    
12138                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12139    
12140                            q.addScalar(COUNT_COLUMN_NAME,
12141                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12142    
12143                            QueryPos qPos = QueryPos.getInstance(q);
12144    
12145                            qPos.add(groupId);
12146    
12147                            qPos.add(userId);
12148    
12149                            qPos.add(status);
12150    
12151                            Long count = (Long)q.uniqueResult();
12152    
12153                            return count.intValue();
12154                    }
12155                    catch (Exception e) {
12156                            throw processException(e);
12157                    }
12158                    finally {
12159                            closeSession(session);
12160                    }
12161            }
12162    
12163            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
12164            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
12165            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
12166            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12167                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12168                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
12169                            new String[] {
12170                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12171                                    
12172                            Integer.class.getName(), Integer.class.getName(),
12173                                    OrderByComparator.class.getName()
12174                            });
12175            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12176                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12177                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
12178                            new String[] {
12179                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12180                            },
12181                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12182                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12183                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
12184                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12185            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12186                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12187                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
12188                            new String[] {
12189                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12190                            });
12191    
12192            /**
12193             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12194             *
12195             * @param groupId the group ID
12196             * @param categoryId the category ID
12197             * @param threadId the thread ID
12198             * @return the matching message-boards messages
12199             */
12200            @Override
12201            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12202                    long threadId) {
12203                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
12204                            QueryUtil.ALL_POS, null);
12205            }
12206    
12207            /**
12208             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12209             *
12210             * <p>
12211             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12212             * </p>
12213             *
12214             * @param groupId the group ID
12215             * @param categoryId the category ID
12216             * @param threadId the thread ID
12217             * @param start the lower bound of the range of message-boards messages
12218             * @param end the upper bound of the range of message-boards messages (not inclusive)
12219             * @return the range of matching message-boards messages
12220             */
12221            @Override
12222            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12223                    long threadId, int start, int end) {
12224                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
12225            }
12226    
12227            /**
12228             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12229             *
12230             * <p>
12231             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12232             * </p>
12233             *
12234             * @param groupId the group ID
12235             * @param categoryId the category ID
12236             * @param threadId the thread ID
12237             * @param start the lower bound of the range of message-boards messages
12238             * @param end the upper bound of the range of message-boards messages (not inclusive)
12239             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12240             * @return the ordered range of matching message-boards messages
12241             */
12242            @Override
12243            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12244                    long threadId, int start, int end,
12245                    OrderByComparator<MBMessage> orderByComparator) {
12246                    return findByG_C_T(groupId, categoryId, threadId, start, end,
12247                            orderByComparator, true);
12248            }
12249    
12250            /**
12251             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12252             *
12253             * <p>
12254             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12255             * </p>
12256             *
12257             * @param groupId the group ID
12258             * @param categoryId the category ID
12259             * @param threadId the thread ID
12260             * @param start the lower bound of the range of message-boards messages
12261             * @param end the upper bound of the range of message-boards messages (not inclusive)
12262             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12263             * @param retrieveFromCache whether to retrieve from the finder cache
12264             * @return the ordered range of matching message-boards messages
12265             */
12266            @Override
12267            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12268                    long threadId, int start, int end,
12269                    OrderByComparator<MBMessage> orderByComparator,
12270                    boolean retrieveFromCache) {
12271                    boolean pagination = true;
12272                    FinderPath finderPath = null;
12273                    Object[] finderArgs = null;
12274    
12275                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12276                                    (orderByComparator == null)) {
12277                            pagination = false;
12278                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12279                            finderArgs = new Object[] { groupId, categoryId, threadId };
12280                    }
12281                    else {
12282                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12283                            finderArgs = new Object[] {
12284                                            groupId, categoryId, threadId,
12285                                            
12286                                            start, end, orderByComparator
12287                                    };
12288                    }
12289    
12290                    List<MBMessage> list = null;
12291    
12292                    if (retrieveFromCache) {
12293                            list = (List<MBMessage>)finderCache.getResult(finderPath,
12294                                            finderArgs, this);
12295    
12296                            if ((list != null) && !list.isEmpty()) {
12297                                    for (MBMessage mbMessage : list) {
12298                                            if ((groupId != mbMessage.getGroupId()) ||
12299                                                            (categoryId != mbMessage.getCategoryId()) ||
12300                                                            (threadId != mbMessage.getThreadId())) {
12301                                                    list = null;
12302    
12303                                                    break;
12304                                            }
12305                                    }
12306                            }
12307                    }
12308    
12309                    if (list == null) {
12310                            StringBundler query = null;
12311    
12312                            if (orderByComparator != null) {
12313                                    query = new StringBundler(5 +
12314                                                    (orderByComparator.getOrderByFields().length * 2));
12315                            }
12316                            else {
12317                                    query = new StringBundler(5);
12318                            }
12319    
12320                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12321    
12322                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12323    
12324                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12325    
12326                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12327    
12328                            if (orderByComparator != null) {
12329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12330                                            orderByComparator);
12331                            }
12332                            else
12333                             if (pagination) {
12334                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12335                            }
12336    
12337                            String sql = query.toString();
12338    
12339                            Session session = null;
12340    
12341                            try {
12342                                    session = openSession();
12343    
12344                                    Query q = session.createQuery(sql);
12345    
12346                                    QueryPos qPos = QueryPos.getInstance(q);
12347    
12348                                    qPos.add(groupId);
12349    
12350                                    qPos.add(categoryId);
12351    
12352                                    qPos.add(threadId);
12353    
12354                                    if (!pagination) {
12355                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12356                                                            start, end, false);
12357    
12358                                            Collections.sort(list);
12359    
12360                                            list = Collections.unmodifiableList(list);
12361                                    }
12362                                    else {
12363                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12364                                                            start, end);
12365                                    }
12366    
12367                                    cacheResult(list);
12368    
12369                                    finderCache.putResult(finderPath, finderArgs, list);
12370                            }
12371                            catch (Exception e) {
12372                                    finderCache.removeResult(finderPath, finderArgs);
12373    
12374                                    throw processException(e);
12375                            }
12376                            finally {
12377                                    closeSession(session);
12378                            }
12379                    }
12380    
12381                    return list;
12382            }
12383    
12384            /**
12385             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12386             *
12387             * @param groupId the group ID
12388             * @param categoryId the category ID
12389             * @param threadId the thread ID
12390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12391             * @return the first matching message-boards message
12392             * @throws NoSuchMessageException if a matching message-boards message could not be found
12393             */
12394            @Override
12395            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12396                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12397                    throws NoSuchMessageException {
12398                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12399                                    orderByComparator);
12400    
12401                    if (mbMessage != null) {
12402                            return mbMessage;
12403                    }
12404    
12405                    StringBundler msg = new StringBundler(8);
12406    
12407                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12408    
12409                    msg.append("groupId=");
12410                    msg.append(groupId);
12411    
12412                    msg.append(", categoryId=");
12413                    msg.append(categoryId);
12414    
12415                    msg.append(", threadId=");
12416                    msg.append(threadId);
12417    
12418                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12419    
12420                    throw new NoSuchMessageException(msg.toString());
12421            }
12422    
12423            /**
12424             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12425             *
12426             * @param groupId the group ID
12427             * @param categoryId the category ID
12428             * @param threadId the thread ID
12429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12430             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12431             */
12432            @Override
12433            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12434                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12435                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12436                                    orderByComparator);
12437    
12438                    if (!list.isEmpty()) {
12439                            return list.get(0);
12440                    }
12441    
12442                    return null;
12443            }
12444    
12445            /**
12446             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12447             *
12448             * @param groupId the group ID
12449             * @param categoryId the category ID
12450             * @param threadId the thread ID
12451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12452             * @return the last matching message-boards message
12453             * @throws NoSuchMessageException if a matching message-boards message could not be found
12454             */
12455            @Override
12456            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12457                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12458                    throws NoSuchMessageException {
12459                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12460                                    orderByComparator);
12461    
12462                    if (mbMessage != null) {
12463                            return mbMessage;
12464                    }
12465    
12466                    StringBundler msg = new StringBundler(8);
12467    
12468                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12469    
12470                    msg.append("groupId=");
12471                    msg.append(groupId);
12472    
12473                    msg.append(", categoryId=");
12474                    msg.append(categoryId);
12475    
12476                    msg.append(", threadId=");
12477                    msg.append(threadId);
12478    
12479                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12480    
12481                    throw new NoSuchMessageException(msg.toString());
12482            }
12483    
12484            /**
12485             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12486             *
12487             * @param groupId the group ID
12488             * @param categoryId the category ID
12489             * @param threadId the thread ID
12490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12491             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12492             */
12493            @Override
12494            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12495                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12496                    int count = countByG_C_T(groupId, categoryId, threadId);
12497    
12498                    if (count == 0) {
12499                            return null;
12500                    }
12501    
12502                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12503                                    count - 1, count, orderByComparator);
12504    
12505                    if (!list.isEmpty()) {
12506                            return list.get(0);
12507                    }
12508    
12509                    return null;
12510            }
12511    
12512            /**
12513             * 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;.
12514             *
12515             * @param messageId the primary key of the current message-boards message
12516             * @param groupId the group ID
12517             * @param categoryId the category ID
12518             * @param threadId the thread ID
12519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12520             * @return the previous, current, and next message-boards message
12521             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12522             */
12523            @Override
12524            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12525                    long categoryId, long threadId,
12526                    OrderByComparator<MBMessage> orderByComparator)
12527                    throws NoSuchMessageException {
12528                    MBMessage mbMessage = findByPrimaryKey(messageId);
12529    
12530                    Session session = null;
12531    
12532                    try {
12533                            session = openSession();
12534    
12535                            MBMessage[] array = new MBMessageImpl[3];
12536    
12537                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12538                                            categoryId, threadId, orderByComparator, true);
12539    
12540                            array[1] = mbMessage;
12541    
12542                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12543                                            categoryId, threadId, orderByComparator, false);
12544    
12545                            return array;
12546                    }
12547                    catch (Exception e) {
12548                            throw processException(e);
12549                    }
12550                    finally {
12551                            closeSession(session);
12552                    }
12553            }
12554    
12555            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12556                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12557                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12558                    StringBundler query = null;
12559    
12560                    if (orderByComparator != null) {
12561                            query = new StringBundler(6 +
12562                                            (orderByComparator.getOrderByConditionFields().length * 3) +
12563                                            (orderByComparator.getOrderByFields().length * 3));
12564                    }
12565                    else {
12566                            query = new StringBundler(5);
12567                    }
12568    
12569                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12570    
12571                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12572    
12573                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12574    
12575                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12576    
12577                    if (orderByComparator != null) {
12578                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12579    
12580                            if (orderByConditionFields.length > 0) {
12581                                    query.append(WHERE_AND);
12582                            }
12583    
12584                            for (int i = 0; i < orderByConditionFields.length; i++) {
12585                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12586                                    query.append(orderByConditionFields[i]);
12587    
12588                                    if ((i + 1) < orderByConditionFields.length) {
12589                                            if (orderByComparator.isAscending() ^ previous) {
12590                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12591                                            }
12592                                            else {
12593                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12594                                            }
12595                                    }
12596                                    else {
12597                                            if (orderByComparator.isAscending() ^ previous) {
12598                                                    query.append(WHERE_GREATER_THAN);
12599                                            }
12600                                            else {
12601                                                    query.append(WHERE_LESSER_THAN);
12602                                            }
12603                                    }
12604                            }
12605    
12606                            query.append(ORDER_BY_CLAUSE);
12607    
12608                            String[] orderByFields = orderByComparator.getOrderByFields();
12609    
12610                            for (int i = 0; i < orderByFields.length; i++) {
12611                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12612                                    query.append(orderByFields[i]);
12613    
12614                                    if ((i + 1) < orderByFields.length) {
12615                                            if (orderByComparator.isAscending() ^ previous) {
12616                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12617                                            }
12618                                            else {
12619                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12620                                            }
12621                                    }
12622                                    else {
12623                                            if (orderByComparator.isAscending() ^ previous) {
12624                                                    query.append(ORDER_BY_ASC);
12625                                            }
12626                                            else {
12627                                                    query.append(ORDER_BY_DESC);
12628                                            }
12629                                    }
12630                            }
12631                    }
12632                    else {
12633                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12634                    }
12635    
12636                    String sql = query.toString();
12637    
12638                    Query q = session.createQuery(sql);
12639    
12640                    q.setFirstResult(0);
12641                    q.setMaxResults(2);
12642    
12643                    QueryPos qPos = QueryPos.getInstance(q);
12644    
12645                    qPos.add(groupId);
12646    
12647                    qPos.add(categoryId);
12648    
12649                    qPos.add(threadId);
12650    
12651                    if (orderByComparator != null) {
12652                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12653    
12654                            for (Object value : values) {
12655                                    qPos.add(value);
12656                            }
12657                    }
12658    
12659                    List<MBMessage> list = q.list();
12660    
12661                    if (list.size() == 2) {
12662                            return list.get(1);
12663                    }
12664                    else {
12665                            return null;
12666                    }
12667            }
12668    
12669            /**
12670             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12671             *
12672             * @param groupId the group ID
12673             * @param categoryId the category ID
12674             * @param threadId the thread ID
12675             * @return the matching message-boards messages that the user has permission to view
12676             */
12677            @Override
12678            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12679                    long threadId) {
12680                    return filterFindByG_C_T(groupId, categoryId, threadId,
12681                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12682            }
12683    
12684            /**
12685             * 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;.
12686             *
12687             * <p>
12688             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12689             * </p>
12690             *
12691             * @param groupId the group ID
12692             * @param categoryId the category ID
12693             * @param threadId the thread ID
12694             * @param start the lower bound of the range of message-boards messages
12695             * @param end the upper bound of the range of message-boards messages (not inclusive)
12696             * @return the range of matching message-boards messages that the user has permission to view
12697             */
12698            @Override
12699            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12700                    long threadId, int start, int end) {
12701                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12702            }
12703    
12704            /**
12705             * 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;.
12706             *
12707             * <p>
12708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12709             * </p>
12710             *
12711             * @param groupId the group ID
12712             * @param categoryId the category ID
12713             * @param threadId the thread ID
12714             * @param start the lower bound of the range of message-boards messages
12715             * @param end the upper bound of the range of message-boards messages (not inclusive)
12716             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12717             * @return the ordered range of matching message-boards messages that the user has permission to view
12718             */
12719            @Override
12720            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12721                    long threadId, int start, int end,
12722                    OrderByComparator<MBMessage> orderByComparator) {
12723                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12724                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12725                                    orderByComparator);
12726                    }
12727    
12728                    StringBundler query = null;
12729    
12730                    if (orderByComparator != null) {
12731                            query = new StringBundler(5 +
12732                                            (orderByComparator.getOrderByFields().length * 2));
12733                    }
12734                    else {
12735                            query = new StringBundler(6);
12736                    }
12737    
12738                    if (getDB().isSupportsInlineDistinct()) {
12739                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12740                    }
12741                    else {
12742                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12743                    }
12744    
12745                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12746    
12747                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12748    
12749                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12750    
12751                    if (!getDB().isSupportsInlineDistinct()) {
12752                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12753                    }
12754    
12755                    if (orderByComparator != null) {
12756                            if (getDB().isSupportsInlineDistinct()) {
12757                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12758                                            orderByComparator, true);
12759                            }
12760                            else {
12761                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12762                                            orderByComparator, true);
12763                            }
12764                    }
12765                    else {
12766                            if (getDB().isSupportsInlineDistinct()) {
12767                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12768                            }
12769                            else {
12770                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12771                            }
12772                    }
12773    
12774                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12775                                    MBMessage.class.getName(),
12776                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12777    
12778                    Session session = null;
12779    
12780                    try {
12781                            session = openSession();
12782    
12783                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12784    
12785                            if (getDB().isSupportsInlineDistinct()) {
12786                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12787                            }
12788                            else {
12789                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12790                            }
12791    
12792                            QueryPos qPos = QueryPos.getInstance(q);
12793    
12794                            qPos.add(groupId);
12795    
12796                            qPos.add(categoryId);
12797    
12798                            qPos.add(threadId);
12799    
12800                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12801                    }
12802                    catch (Exception e) {
12803                            throw processException(e);
12804                    }
12805                    finally {
12806                            closeSession(session);
12807                    }
12808            }
12809    
12810            /**
12811             * 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;.
12812             *
12813             * @param messageId the primary key of the current message-boards message
12814             * @param groupId the group ID
12815             * @param categoryId the category ID
12816             * @param threadId the thread ID
12817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12818             * @return the previous, current, and next message-boards message
12819             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12820             */
12821            @Override
12822            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12823                    long groupId, long categoryId, long threadId,
12824                    OrderByComparator<MBMessage> orderByComparator)
12825                    throws NoSuchMessageException {
12826                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12827                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12828                                    threadId, orderByComparator);
12829                    }
12830    
12831                    MBMessage mbMessage = findByPrimaryKey(messageId);
12832    
12833                    Session session = null;
12834    
12835                    try {
12836                            session = openSession();
12837    
12838                            MBMessage[] array = new MBMessageImpl[3];
12839    
12840                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12841                                            groupId, categoryId, threadId, orderByComparator, true);
12842    
12843                            array[1] = mbMessage;
12844    
12845                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12846                                            groupId, categoryId, threadId, orderByComparator, false);
12847    
12848                            return array;
12849                    }
12850                    catch (Exception e) {
12851                            throw processException(e);
12852                    }
12853                    finally {
12854                            closeSession(session);
12855                    }
12856            }
12857    
12858            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12859                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12860                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12861                    StringBundler query = null;
12862    
12863                    if (orderByComparator != null) {
12864                            query = new StringBundler(7 +
12865                                            (orderByComparator.getOrderByConditionFields().length * 3) +
12866                                            (orderByComparator.getOrderByFields().length * 3));
12867                    }
12868                    else {
12869                            query = new StringBundler(6);
12870                    }
12871    
12872                    if (getDB().isSupportsInlineDistinct()) {
12873                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12874                    }
12875                    else {
12876                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12877                    }
12878    
12879                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12880    
12881                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12882    
12883                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12884    
12885                    if (!getDB().isSupportsInlineDistinct()) {
12886                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12887                    }
12888    
12889                    if (orderByComparator != null) {
12890                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12891    
12892                            if (orderByConditionFields.length > 0) {
12893                                    query.append(WHERE_AND);
12894                            }
12895    
12896                            for (int i = 0; i < orderByConditionFields.length; i++) {
12897                                    if (getDB().isSupportsInlineDistinct()) {
12898                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12899                                    }
12900                                    else {
12901                                            query.append(_ORDER_BY_ENTITY_TABLE);
12902                                    }
12903    
12904                                    query.append(orderByConditionFields[i]);
12905    
12906                                    if ((i + 1) < orderByConditionFields.length) {
12907                                            if (orderByComparator.isAscending() ^ previous) {
12908                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12909                                            }
12910                                            else {
12911                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12912                                            }
12913                                    }
12914                                    else {
12915                                            if (orderByComparator.isAscending() ^ previous) {
12916                                                    query.append(WHERE_GREATER_THAN);
12917                                            }
12918                                            else {
12919                                                    query.append(WHERE_LESSER_THAN);
12920                                            }
12921                                    }
12922                            }
12923    
12924                            query.append(ORDER_BY_CLAUSE);
12925    
12926                            String[] orderByFields = orderByComparator.getOrderByFields();
12927    
12928                            for (int i = 0; i < orderByFields.length; i++) {
12929                                    if (getDB().isSupportsInlineDistinct()) {
12930                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12931                                    }
12932                                    else {
12933                                            query.append(_ORDER_BY_ENTITY_TABLE);
12934                                    }
12935    
12936                                    query.append(orderByFields[i]);
12937    
12938                                    if ((i + 1) < orderByFields.length) {
12939                                            if (orderByComparator.isAscending() ^ previous) {
12940                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12941                                            }
12942                                            else {
12943                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12944                                            }
12945                                    }
12946                                    else {
12947                                            if (orderByComparator.isAscending() ^ previous) {
12948                                                    query.append(ORDER_BY_ASC);
12949                                            }
12950                                            else {
12951                                                    query.append(ORDER_BY_DESC);
12952                                            }
12953                                    }
12954                            }
12955                    }
12956                    else {
12957                            if (getDB().isSupportsInlineDistinct()) {
12958                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12959                            }
12960                            else {
12961                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12962                            }
12963                    }
12964    
12965                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12966                                    MBMessage.class.getName(),
12967                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12968    
12969                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12970    
12971                    q.setFirstResult(0);
12972                    q.setMaxResults(2);
12973    
12974                    if (getDB().isSupportsInlineDistinct()) {
12975                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12976                    }
12977                    else {
12978                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12979                    }
12980    
12981                    QueryPos qPos = QueryPos.getInstance(q);
12982    
12983                    qPos.add(groupId);
12984    
12985                    qPos.add(categoryId);
12986    
12987                    qPos.add(threadId);
12988    
12989                    if (orderByComparator != null) {
12990                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12991    
12992                            for (Object value : values) {
12993                                    qPos.add(value);
12994                            }
12995                    }
12996    
12997                    List<MBMessage> list = q.list();
12998    
12999                    if (list.size() == 2) {
13000                            return list.get(1);
13001                    }
13002                    else {
13003                            return null;
13004                    }
13005            }
13006    
13007            /**
13008             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
13009             *
13010             * @param groupId the group ID
13011             * @param categoryId the category ID
13012             * @param threadId the thread ID
13013             */
13014            @Override
13015            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
13016                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
13017                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13018                            remove(mbMessage);
13019                    }
13020            }
13021    
13022            /**
13023             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13024             *
13025             * @param groupId the group ID
13026             * @param categoryId the category ID
13027             * @param threadId the thread ID
13028             * @return the number of matching message-boards messages
13029             */
13030            @Override
13031            public int countByG_C_T(long groupId, long categoryId, long threadId) {
13032                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
13033    
13034                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
13035    
13036                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13037    
13038                    if (count == null) {
13039                            StringBundler query = new StringBundler(4);
13040    
13041                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13042    
13043                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13044    
13045                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13046    
13047                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13048    
13049                            String sql = query.toString();
13050    
13051                            Session session = null;
13052    
13053                            try {
13054                                    session = openSession();
13055    
13056                                    Query q = session.createQuery(sql);
13057    
13058                                    QueryPos qPos = QueryPos.getInstance(q);
13059    
13060                                    qPos.add(groupId);
13061    
13062                                    qPos.add(categoryId);
13063    
13064                                    qPos.add(threadId);
13065    
13066                                    count = (Long)q.uniqueResult();
13067    
13068                                    finderCache.putResult(finderPath, finderArgs, count);
13069                            }
13070                            catch (Exception e) {
13071                                    finderCache.removeResult(finderPath, finderArgs);
13072    
13073                                    throw processException(e);
13074                            }
13075                            finally {
13076                                    closeSession(session);
13077                            }
13078                    }
13079    
13080                    return count.intValue();
13081            }
13082    
13083            /**
13084             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13085             *
13086             * @param groupId the group ID
13087             * @param categoryId the category ID
13088             * @param threadId the thread ID
13089             * @return the number of matching message-boards messages that the user has permission to view
13090             */
13091            @Override
13092            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
13093                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13094                            return countByG_C_T(groupId, categoryId, threadId);
13095                    }
13096    
13097                    StringBundler query = new StringBundler(4);
13098    
13099                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13100    
13101                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13102    
13103                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13104    
13105                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13106    
13107                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13108                                    MBMessage.class.getName(),
13109                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13110    
13111                    Session session = null;
13112    
13113                    try {
13114                            session = openSession();
13115    
13116                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13117    
13118                            q.addScalar(COUNT_COLUMN_NAME,
13119                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13120    
13121                            QueryPos qPos = QueryPos.getInstance(q);
13122    
13123                            qPos.add(groupId);
13124    
13125                            qPos.add(categoryId);
13126    
13127                            qPos.add(threadId);
13128    
13129                            Long count = (Long)q.uniqueResult();
13130    
13131                            return count.intValue();
13132                    }
13133                    catch (Exception e) {
13134                            throw processException(e);
13135                    }
13136                    finally {
13137                            closeSession(session);
13138                    }
13139            }
13140    
13141            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
13142            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13143            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
13144            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13145                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13146                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
13147                            new String[] {
13148                                    Long.class.getName(), Long.class.getName(),
13149                                    Integer.class.getName(),
13150                                    
13151                            Integer.class.getName(), Integer.class.getName(),
13152                                    OrderByComparator.class.getName()
13153                            });
13154            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13155                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
13157                            new String[] {
13158                                    Long.class.getName(), Long.class.getName(),
13159                                    Integer.class.getName()
13160                            },
13161                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
13162                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
13163                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
13164                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13165            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
13168                            new String[] {
13169                                    Long.class.getName(), Long.class.getName(),
13170                                    Integer.class.getName()
13171                            });
13172    
13173            /**
13174             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13175             *
13176             * @param groupId the group ID
13177             * @param categoryId the category ID
13178             * @param status the status
13179             * @return the matching message-boards messages
13180             */
13181            @Override
13182            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
13183                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
13184                            QueryUtil.ALL_POS, null);
13185            }
13186    
13187            /**
13188             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13189             *
13190             * <p>
13191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13192             * </p>
13193             *
13194             * @param groupId the group ID
13195             * @param categoryId the category ID
13196             * @param status the status
13197             * @param start the lower bound of the range of message-boards messages
13198             * @param end the upper bound of the range of message-boards messages (not inclusive)
13199             * @return the range of matching message-boards messages
13200             */
13201            @Override
13202            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13203                    int status, int start, int end) {
13204                    return findByG_C_S(groupId, categoryId, status, start, end, null);
13205            }
13206    
13207            /**
13208             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13209             *
13210             * <p>
13211             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13212             * </p>
13213             *
13214             * @param groupId the group ID
13215             * @param categoryId the category ID
13216             * @param status the status
13217             * @param start the lower bound of the range of message-boards messages
13218             * @param end the upper bound of the range of message-boards messages (not inclusive)
13219             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13220             * @return the ordered range of matching message-boards messages
13221             */
13222            @Override
13223            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13224                    int status, int start, int end,
13225                    OrderByComparator<MBMessage> orderByComparator) {
13226                    return findByG_C_S(groupId, categoryId, status, start, end,
13227                            orderByComparator, true);
13228            }
13229    
13230            /**
13231             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13232             *
13233             * <p>
13234             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13235             * </p>
13236             *
13237             * @param groupId the group ID
13238             * @param categoryId the category ID
13239             * @param status the status
13240             * @param start the lower bound of the range of message-boards messages
13241             * @param end the upper bound of the range of message-boards messages (not inclusive)
13242             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13243             * @param retrieveFromCache whether to retrieve from the finder cache
13244             * @return the ordered range of matching message-boards messages
13245             */
13246            @Override
13247            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13248                    int status, int start, int end,
13249                    OrderByComparator<MBMessage> orderByComparator,
13250                    boolean retrieveFromCache) {
13251                    boolean pagination = true;
13252                    FinderPath finderPath = null;
13253                    Object[] finderArgs = null;
13254    
13255                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13256                                    (orderByComparator == null)) {
13257                            pagination = false;
13258                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13259                            finderArgs = new Object[] { groupId, categoryId, status };
13260                    }
13261                    else {
13262                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13263                            finderArgs = new Object[] {
13264                                            groupId, categoryId, status,
13265                                            
13266                                            start, end, orderByComparator
13267                                    };
13268                    }
13269    
13270                    List<MBMessage> list = null;
13271    
13272                    if (retrieveFromCache) {
13273                            list = (List<MBMessage>)finderCache.getResult(finderPath,
13274                                            finderArgs, this);
13275    
13276                            if ((list != null) && !list.isEmpty()) {
13277                                    for (MBMessage mbMessage : list) {
13278                                            if ((groupId != mbMessage.getGroupId()) ||
13279                                                            (categoryId != mbMessage.getCategoryId()) ||
13280                                                            (status != mbMessage.getStatus())) {
13281                                                    list = null;
13282    
13283                                                    break;
13284                                            }
13285                                    }
13286                            }
13287                    }
13288    
13289                    if (list == null) {
13290                            StringBundler query = null;
13291    
13292                            if (orderByComparator != null) {
13293                                    query = new StringBundler(5 +
13294                                                    (orderByComparator.getOrderByFields().length * 2));
13295                            }
13296                            else {
13297                                    query = new StringBundler(5);
13298                            }
13299    
13300                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13301    
13302                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13303    
13304                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13305    
13306                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13307    
13308                            if (orderByComparator != null) {
13309                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13310                                            orderByComparator);
13311                            }
13312                            else
13313                             if (pagination) {
13314                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13315                            }
13316    
13317                            String sql = query.toString();
13318    
13319                            Session session = null;
13320    
13321                            try {
13322                                    session = openSession();
13323    
13324                                    Query q = session.createQuery(sql);
13325    
13326                                    QueryPos qPos = QueryPos.getInstance(q);
13327    
13328                                    qPos.add(groupId);
13329    
13330                                    qPos.add(categoryId);
13331    
13332                                    qPos.add(status);
13333    
13334                                    if (!pagination) {
13335                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13336                                                            start, end, false);
13337    
13338                                            Collections.sort(list);
13339    
13340                                            list = Collections.unmodifiableList(list);
13341                                    }
13342                                    else {
13343                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13344                                                            start, end);
13345                                    }
13346    
13347                                    cacheResult(list);
13348    
13349                                    finderCache.putResult(finderPath, finderArgs, list);
13350                            }
13351                            catch (Exception e) {
13352                                    finderCache.removeResult(finderPath, finderArgs);
13353    
13354                                    throw processException(e);
13355                            }
13356                            finally {
13357                                    closeSession(session);
13358                            }
13359                    }
13360    
13361                    return list;
13362            }
13363    
13364            /**
13365             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13366             *
13367             * @param groupId the group ID
13368             * @param categoryId the category ID
13369             * @param status the status
13370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13371             * @return the first matching message-boards message
13372             * @throws NoSuchMessageException if a matching message-boards message could not be found
13373             */
13374            @Override
13375            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13376                    int status, OrderByComparator<MBMessage> orderByComparator)
13377                    throws NoSuchMessageException {
13378                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13379                                    orderByComparator);
13380    
13381                    if (mbMessage != null) {
13382                            return mbMessage;
13383                    }
13384    
13385                    StringBundler msg = new StringBundler(8);
13386    
13387                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13388    
13389                    msg.append("groupId=");
13390                    msg.append(groupId);
13391    
13392                    msg.append(", categoryId=");
13393                    msg.append(categoryId);
13394    
13395                    msg.append(", status=");
13396                    msg.append(status);
13397    
13398                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13399    
13400                    throw new NoSuchMessageException(msg.toString());
13401            }
13402    
13403            /**
13404             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13405             *
13406             * @param groupId the group ID
13407             * @param categoryId the category ID
13408             * @param status the status
13409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13410             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13411             */
13412            @Override
13413            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13414                    int status, OrderByComparator<MBMessage> orderByComparator) {
13415                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13416                                    orderByComparator);
13417    
13418                    if (!list.isEmpty()) {
13419                            return list.get(0);
13420                    }
13421    
13422                    return null;
13423            }
13424    
13425            /**
13426             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13427             *
13428             * @param groupId the group ID
13429             * @param categoryId the category ID
13430             * @param status the status
13431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13432             * @return the last matching message-boards message
13433             * @throws NoSuchMessageException if a matching message-boards message could not be found
13434             */
13435            @Override
13436            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13437                    int status, OrderByComparator<MBMessage> orderByComparator)
13438                    throws NoSuchMessageException {
13439                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13440                                    orderByComparator);
13441    
13442                    if (mbMessage != null) {
13443                            return mbMessage;
13444                    }
13445    
13446                    StringBundler msg = new StringBundler(8);
13447    
13448                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13449    
13450                    msg.append("groupId=");
13451                    msg.append(groupId);
13452    
13453                    msg.append(", categoryId=");
13454                    msg.append(categoryId);
13455    
13456                    msg.append(", status=");
13457                    msg.append(status);
13458    
13459                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13460    
13461                    throw new NoSuchMessageException(msg.toString());
13462            }
13463    
13464            /**
13465             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13466             *
13467             * @param groupId the group ID
13468             * @param categoryId the category ID
13469             * @param status the status
13470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13471             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13472             */
13473            @Override
13474            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13475                    int status, OrderByComparator<MBMessage> orderByComparator) {
13476                    int count = countByG_C_S(groupId, categoryId, status);
13477    
13478                    if (count == 0) {
13479                            return null;
13480                    }
13481    
13482                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13483                                    count - 1, count, orderByComparator);
13484    
13485                    if (!list.isEmpty()) {
13486                            return list.get(0);
13487                    }
13488    
13489                    return null;
13490            }
13491    
13492            /**
13493             * 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;.
13494             *
13495             * @param messageId the primary key of the current message-boards message
13496             * @param groupId the group ID
13497             * @param categoryId the category ID
13498             * @param status the status
13499             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13500             * @return the previous, current, and next message-boards message
13501             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13502             */
13503            @Override
13504            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13505                    long categoryId, int status,
13506                    OrderByComparator<MBMessage> orderByComparator)
13507                    throws NoSuchMessageException {
13508                    MBMessage mbMessage = findByPrimaryKey(messageId);
13509    
13510                    Session session = null;
13511    
13512                    try {
13513                            session = openSession();
13514    
13515                            MBMessage[] array = new MBMessageImpl[3];
13516    
13517                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13518                                            categoryId, status, orderByComparator, true);
13519    
13520                            array[1] = mbMessage;
13521    
13522                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13523                                            categoryId, status, orderByComparator, false);
13524    
13525                            return array;
13526                    }
13527                    catch (Exception e) {
13528                            throw processException(e);
13529                    }
13530                    finally {
13531                            closeSession(session);
13532                    }
13533            }
13534    
13535            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13536                    MBMessage mbMessage, long groupId, long categoryId, int status,
13537                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13538                    StringBundler query = null;
13539    
13540                    if (orderByComparator != null) {
13541                            query = new StringBundler(6 +
13542                                            (orderByComparator.getOrderByConditionFields().length * 3) +
13543                                            (orderByComparator.getOrderByFields().length * 3));
13544                    }
13545                    else {
13546                            query = new StringBundler(5);
13547                    }
13548    
13549                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13550    
13551                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13552    
13553                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13554    
13555                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13556    
13557                    if (orderByComparator != null) {
13558                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13559    
13560                            if (orderByConditionFields.length > 0) {
13561                                    query.append(WHERE_AND);
13562                            }
13563    
13564                            for (int i = 0; i < orderByConditionFields.length; i++) {
13565                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13566                                    query.append(orderByConditionFields[i]);
13567    
13568                                    if ((i + 1) < orderByConditionFields.length) {
13569                                            if (orderByComparator.isAscending() ^ previous) {
13570                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13571                                            }
13572                                            else {
13573                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13574                                            }
13575                                    }
13576                                    else {
13577                                            if (orderByComparator.isAscending() ^ previous) {
13578                                                    query.append(WHERE_GREATER_THAN);
13579                                            }
13580                                            else {
13581                                                    query.append(WHERE_LESSER_THAN);
13582                                            }
13583                                    }
13584                            }
13585    
13586                            query.append(ORDER_BY_CLAUSE);
13587    
13588                            String[] orderByFields = orderByComparator.getOrderByFields();
13589    
13590                            for (int i = 0; i < orderByFields.length; i++) {
13591                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13592                                    query.append(orderByFields[i]);
13593    
13594                                    if ((i + 1) < orderByFields.length) {
13595                                            if (orderByComparator.isAscending() ^ previous) {
13596                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13597                                            }
13598                                            else {
13599                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13600                                            }
13601                                    }
13602                                    else {
13603                                            if (orderByComparator.isAscending() ^ previous) {
13604                                                    query.append(ORDER_BY_ASC);
13605                                            }
13606                                            else {
13607                                                    query.append(ORDER_BY_DESC);
13608                                            }
13609                                    }
13610                            }
13611                    }
13612                    else {
13613                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13614                    }
13615    
13616                    String sql = query.toString();
13617    
13618                    Query q = session.createQuery(sql);
13619    
13620                    q.setFirstResult(0);
13621                    q.setMaxResults(2);
13622    
13623                    QueryPos qPos = QueryPos.getInstance(q);
13624    
13625                    qPos.add(groupId);
13626    
13627                    qPos.add(categoryId);
13628    
13629                    qPos.add(status);
13630    
13631                    if (orderByComparator != null) {
13632                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13633    
13634                            for (Object value : values) {
13635                                    qPos.add(value);
13636                            }
13637                    }
13638    
13639                    List<MBMessage> list = q.list();
13640    
13641                    if (list.size() == 2) {
13642                            return list.get(1);
13643                    }
13644                    else {
13645                            return null;
13646                    }
13647            }
13648    
13649            /**
13650             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13651             *
13652             * @param groupId the group ID
13653             * @param categoryId the category ID
13654             * @param status the status
13655             * @return the matching message-boards messages that the user has permission to view
13656             */
13657            @Override
13658            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13659                    int status) {
13660                    return filterFindByG_C_S(groupId, categoryId, status,
13661                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13662            }
13663    
13664            /**
13665             * 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;.
13666             *
13667             * <p>
13668             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13669             * </p>
13670             *
13671             * @param groupId the group ID
13672             * @param categoryId the category ID
13673             * @param status the status
13674             * @param start the lower bound of the range of message-boards messages
13675             * @param end the upper bound of the range of message-boards messages (not inclusive)
13676             * @return the range of matching message-boards messages that the user has permission to view
13677             */
13678            @Override
13679            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13680                    int status, int start, int end) {
13681                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13682            }
13683    
13684            /**
13685             * 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;.
13686             *
13687             * <p>
13688             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13689             * </p>
13690             *
13691             * @param groupId the group ID
13692             * @param categoryId the category ID
13693             * @param status the status
13694             * @param start the lower bound of the range of message-boards messages
13695             * @param end the upper bound of the range of message-boards messages (not inclusive)
13696             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13697             * @return the ordered range of matching message-boards messages that the user has permission to view
13698             */
13699            @Override
13700            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13701                    int status, int start, int end,
13702                    OrderByComparator<MBMessage> orderByComparator) {
13703                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13704                            return findByG_C_S(groupId, categoryId, status, start, end,
13705                                    orderByComparator);
13706                    }
13707    
13708                    StringBundler query = null;
13709    
13710                    if (orderByComparator != null) {
13711                            query = new StringBundler(5 +
13712                                            (orderByComparator.getOrderByFields().length * 2));
13713                    }
13714                    else {
13715                            query = new StringBundler(6);
13716                    }
13717    
13718                    if (getDB().isSupportsInlineDistinct()) {
13719                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13720                    }
13721                    else {
13722                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13723                    }
13724    
13725                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13726    
13727                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13728    
13729                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13730    
13731                    if (!getDB().isSupportsInlineDistinct()) {
13732                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13733                    }
13734    
13735                    if (orderByComparator != null) {
13736                            if (getDB().isSupportsInlineDistinct()) {
13737                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13738                                            orderByComparator, true);
13739                            }
13740                            else {
13741                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13742                                            orderByComparator, true);
13743                            }
13744                    }
13745                    else {
13746                            if (getDB().isSupportsInlineDistinct()) {
13747                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13748                            }
13749                            else {
13750                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13751                            }
13752                    }
13753    
13754                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13755                                    MBMessage.class.getName(),
13756                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13757    
13758                    Session session = null;
13759    
13760                    try {
13761                            session = openSession();
13762    
13763                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13764    
13765                            if (getDB().isSupportsInlineDistinct()) {
13766                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13767                            }
13768                            else {
13769                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13770                            }
13771    
13772                            QueryPos qPos = QueryPos.getInstance(q);
13773    
13774                            qPos.add(groupId);
13775    
13776                            qPos.add(categoryId);
13777    
13778                            qPos.add(status);
13779    
13780                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13781                    }
13782                    catch (Exception e) {
13783                            throw processException(e);
13784                    }
13785                    finally {
13786                            closeSession(session);
13787                    }
13788            }
13789    
13790            /**
13791             * 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;.
13792             *
13793             * @param messageId the primary key of the current message-boards message
13794             * @param groupId the group ID
13795             * @param categoryId the category ID
13796             * @param status the status
13797             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13798             * @return the previous, current, and next message-boards message
13799             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13800             */
13801            @Override
13802            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13803                    long groupId, long categoryId, int status,
13804                    OrderByComparator<MBMessage> orderByComparator)
13805                    throws NoSuchMessageException {
13806                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13807                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13808                                    status, orderByComparator);
13809                    }
13810    
13811                    MBMessage mbMessage = findByPrimaryKey(messageId);
13812    
13813                    Session session = null;
13814    
13815                    try {
13816                            session = openSession();
13817    
13818                            MBMessage[] array = new MBMessageImpl[3];
13819    
13820                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13821                                            groupId, categoryId, status, orderByComparator, true);
13822    
13823                            array[1] = mbMessage;
13824    
13825                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13826                                            groupId, categoryId, status, orderByComparator, false);
13827    
13828                            return array;
13829                    }
13830                    catch (Exception e) {
13831                            throw processException(e);
13832                    }
13833                    finally {
13834                            closeSession(session);
13835                    }
13836            }
13837    
13838            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13839                    MBMessage mbMessage, long groupId, long categoryId, int status,
13840                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13841                    StringBundler query = null;
13842    
13843                    if (orderByComparator != null) {
13844                            query = new StringBundler(7 +
13845                                            (orderByComparator.getOrderByConditionFields().length * 3) +
13846                                            (orderByComparator.getOrderByFields().length * 3));
13847                    }
13848                    else {
13849                            query = new StringBundler(6);
13850                    }
13851    
13852                    if (getDB().isSupportsInlineDistinct()) {
13853                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13854                    }
13855                    else {
13856                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13857                    }
13858    
13859                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13860    
13861                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13862    
13863                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13864    
13865                    if (!getDB().isSupportsInlineDistinct()) {
13866                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13867                    }
13868    
13869                    if (orderByComparator != null) {
13870                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13871    
13872                            if (orderByConditionFields.length > 0) {
13873                                    query.append(WHERE_AND);
13874                            }
13875    
13876                            for (int i = 0; i < orderByConditionFields.length; i++) {
13877                                    if (getDB().isSupportsInlineDistinct()) {
13878                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13879                                    }
13880                                    else {
13881                                            query.append(_ORDER_BY_ENTITY_TABLE);
13882                                    }
13883    
13884                                    query.append(orderByConditionFields[i]);
13885    
13886                                    if ((i + 1) < orderByConditionFields.length) {
13887                                            if (orderByComparator.isAscending() ^ previous) {
13888                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13889                                            }
13890                                            else {
13891                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13892                                            }
13893                                    }
13894                                    else {
13895                                            if (orderByComparator.isAscending() ^ previous) {
13896                                                    query.append(WHERE_GREATER_THAN);
13897                                            }
13898                                            else {
13899                                                    query.append(WHERE_LESSER_THAN);
13900                                            }
13901                                    }
13902                            }
13903    
13904                            query.append(ORDER_BY_CLAUSE);
13905    
13906                            String[] orderByFields = orderByComparator.getOrderByFields();
13907    
13908                            for (int i = 0; i < orderByFields.length; i++) {
13909                                    if (getDB().isSupportsInlineDistinct()) {
13910                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13911                                    }
13912                                    else {
13913                                            query.append(_ORDER_BY_ENTITY_TABLE);
13914                                    }
13915    
13916                                    query.append(orderByFields[i]);
13917    
13918                                    if ((i + 1) < orderByFields.length) {
13919                                            if (orderByComparator.isAscending() ^ previous) {
13920                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13921                                            }
13922                                            else {
13923                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13924                                            }
13925                                    }
13926                                    else {
13927                                            if (orderByComparator.isAscending() ^ previous) {
13928                                                    query.append(ORDER_BY_ASC);
13929                                            }
13930                                            else {
13931                                                    query.append(ORDER_BY_DESC);
13932                                            }
13933                                    }
13934                            }
13935                    }
13936                    else {
13937                            if (getDB().isSupportsInlineDistinct()) {
13938                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13939                            }
13940                            else {
13941                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13942                            }
13943                    }
13944    
13945                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13946                                    MBMessage.class.getName(),
13947                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13948    
13949                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13950    
13951                    q.setFirstResult(0);
13952                    q.setMaxResults(2);
13953    
13954                    if (getDB().isSupportsInlineDistinct()) {
13955                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13956                    }
13957                    else {
13958                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13959                    }
13960    
13961                    QueryPos qPos = QueryPos.getInstance(q);
13962    
13963                    qPos.add(groupId);
13964    
13965                    qPos.add(categoryId);
13966    
13967                    qPos.add(status);
13968    
13969                    if (orderByComparator != null) {
13970                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13971    
13972                            for (Object value : values) {
13973                                    qPos.add(value);
13974                            }
13975                    }
13976    
13977                    List<MBMessage> list = q.list();
13978    
13979                    if (list.size() == 2) {
13980                            return list.get(1);
13981                    }
13982                    else {
13983                            return null;
13984                    }
13985            }
13986    
13987            /**
13988             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13989             *
13990             * @param groupId the group ID
13991             * @param categoryId the category ID
13992             * @param status the status
13993             */
13994            @Override
13995            public void removeByG_C_S(long groupId, long categoryId, int status) {
13996                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13997                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13998                            remove(mbMessage);
13999                    }
14000            }
14001    
14002            /**
14003             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
14004             *
14005             * @param groupId the group ID
14006             * @param categoryId the category ID
14007             * @param status the status
14008             * @return the number of matching message-boards messages
14009             */
14010            @Override
14011            public int countByG_C_S(long groupId, long categoryId, int status) {
14012                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
14013    
14014                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
14015    
14016                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14017    
14018                    if (count == null) {
14019                            StringBundler query = new StringBundler(4);
14020    
14021                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14022    
14023                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14024    
14025                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14026    
14027                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14028    
14029                            String sql = query.toString();
14030    
14031                            Session session = null;
14032    
14033                            try {
14034                                    session = openSession();
14035    
14036                                    Query q = session.createQuery(sql);
14037    
14038                                    QueryPos qPos = QueryPos.getInstance(q);
14039    
14040                                    qPos.add(groupId);
14041    
14042                                    qPos.add(categoryId);
14043    
14044                                    qPos.add(status);
14045    
14046                                    count = (Long)q.uniqueResult();
14047    
14048                                    finderCache.putResult(finderPath, finderArgs, count);
14049                            }
14050                            catch (Exception e) {
14051                                    finderCache.removeResult(finderPath, finderArgs);
14052    
14053                                    throw processException(e);
14054                            }
14055                            finally {
14056                                    closeSession(session);
14057                            }
14058                    }
14059    
14060                    return count.intValue();
14061            }
14062    
14063            /**
14064             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
14065             *
14066             * @param groupId the group ID
14067             * @param categoryId the category ID
14068             * @param status the status
14069             * @return the number of matching message-boards messages that the user has permission to view
14070             */
14071            @Override
14072            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
14073                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14074                            return countByG_C_S(groupId, categoryId, status);
14075                    }
14076    
14077                    StringBundler query = new StringBundler(4);
14078    
14079                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
14080    
14081                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14082    
14083                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14084    
14085                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14086    
14087                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14088                                    MBMessage.class.getName(),
14089                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14090    
14091                    Session session = null;
14092    
14093                    try {
14094                            session = openSession();
14095    
14096                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
14097    
14098                            q.addScalar(COUNT_COLUMN_NAME,
14099                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14100    
14101                            QueryPos qPos = QueryPos.getInstance(q);
14102    
14103                            qPos.add(groupId);
14104    
14105                            qPos.add(categoryId);
14106    
14107                            qPos.add(status);
14108    
14109                            Long count = (Long)q.uniqueResult();
14110    
14111                            return count.intValue();
14112                    }
14113                    catch (Exception e) {
14114                            throw processException(e);
14115                    }
14116                    finally {
14117                            closeSession(session);
14118                    }
14119            }
14120    
14121            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
14122            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
14123            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
14124            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14125                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14126                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
14127                            new String[] {
14128                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14129                                    
14130                            Integer.class.getName(), Integer.class.getName(),
14131                                    OrderByComparator.class.getName()
14132                            });
14133            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14134                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
14136                            new String[] {
14137                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14138                            },
14139                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14140                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14141                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14142                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14143            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14144                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14145                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
14146                            new String[] {
14147                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14148                            });
14149    
14150            /**
14151             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14152             *
14153             * @param userId the user ID
14154             * @param classNameId the class name ID
14155             * @param classPK the class p k
14156             * @return the matching message-boards messages
14157             */
14158            @Override
14159            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14160                    long classPK) {
14161                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
14162                            QueryUtil.ALL_POS, null);
14163            }
14164    
14165            /**
14166             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14167             *
14168             * <p>
14169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14170             * </p>
14171             *
14172             * @param userId the user ID
14173             * @param classNameId the class name ID
14174             * @param classPK the class p k
14175             * @param start the lower bound of the range of message-boards messages
14176             * @param end the upper bound of the range of message-boards messages (not inclusive)
14177             * @return the range of matching message-boards messages
14178             */
14179            @Override
14180            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14181                    long classPK, int start, int end) {
14182                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
14183            }
14184    
14185            /**
14186             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14187             *
14188             * <p>
14189             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14190             * </p>
14191             *
14192             * @param userId the user ID
14193             * @param classNameId the class name ID
14194             * @param classPK the class p k
14195             * @param start the lower bound of the range of message-boards messages
14196             * @param end the upper bound of the range of message-boards messages (not inclusive)
14197             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14198             * @return the ordered range of matching message-boards messages
14199             */
14200            @Override
14201            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14202                    long classPK, int start, int end,
14203                    OrderByComparator<MBMessage> orderByComparator) {
14204                    return findByU_C_C(userId, classNameId, classPK, start, end,
14205                            orderByComparator, true);
14206            }
14207    
14208            /**
14209             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14210             *
14211             * <p>
14212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14213             * </p>
14214             *
14215             * @param userId the user ID
14216             * @param classNameId the class name ID
14217             * @param classPK the class p k
14218             * @param start the lower bound of the range of message-boards messages
14219             * @param end the upper bound of the range of message-boards messages (not inclusive)
14220             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14221             * @param retrieveFromCache whether to retrieve from the finder cache
14222             * @return the ordered range of matching message-boards messages
14223             */
14224            @Override
14225            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14226                    long classPK, int start, int end,
14227                    OrderByComparator<MBMessage> orderByComparator,
14228                    boolean retrieveFromCache) {
14229                    boolean pagination = true;
14230                    FinderPath finderPath = null;
14231                    Object[] finderArgs = null;
14232    
14233                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14234                                    (orderByComparator == null)) {
14235                            pagination = false;
14236                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
14237                            finderArgs = new Object[] { userId, classNameId, classPK };
14238                    }
14239                    else {
14240                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
14241                            finderArgs = new Object[] {
14242                                            userId, classNameId, classPK,
14243                                            
14244                                            start, end, orderByComparator
14245                                    };
14246                    }
14247    
14248                    List<MBMessage> list = null;
14249    
14250                    if (retrieveFromCache) {
14251                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14252                                            finderArgs, this);
14253    
14254                            if ((list != null) && !list.isEmpty()) {
14255                                    for (MBMessage mbMessage : list) {
14256                                            if ((userId != mbMessage.getUserId()) ||
14257                                                            (classNameId != mbMessage.getClassNameId()) ||
14258                                                            (classPK != mbMessage.getClassPK())) {
14259                                                    list = null;
14260    
14261                                                    break;
14262                                            }
14263                                    }
14264                            }
14265                    }
14266    
14267                    if (list == null) {
14268                            StringBundler query = null;
14269    
14270                            if (orderByComparator != null) {
14271                                    query = new StringBundler(5 +
14272                                                    (orderByComparator.getOrderByFields().length * 2));
14273                            }
14274                            else {
14275                                    query = new StringBundler(5);
14276                            }
14277    
14278                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14279    
14280                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14281    
14282                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14283    
14284                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14285    
14286                            if (orderByComparator != null) {
14287                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14288                                            orderByComparator);
14289                            }
14290                            else
14291                             if (pagination) {
14292                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14293                            }
14294    
14295                            String sql = query.toString();
14296    
14297                            Session session = null;
14298    
14299                            try {
14300                                    session = openSession();
14301    
14302                                    Query q = session.createQuery(sql);
14303    
14304                                    QueryPos qPos = QueryPos.getInstance(q);
14305    
14306                                    qPos.add(userId);
14307    
14308                                    qPos.add(classNameId);
14309    
14310                                    qPos.add(classPK);
14311    
14312                                    if (!pagination) {
14313                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14314                                                            start, end, false);
14315    
14316                                            Collections.sort(list);
14317    
14318                                            list = Collections.unmodifiableList(list);
14319                                    }
14320                                    else {
14321                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14322                                                            start, end);
14323                                    }
14324    
14325                                    cacheResult(list);
14326    
14327                                    finderCache.putResult(finderPath, finderArgs, list);
14328                            }
14329                            catch (Exception e) {
14330                                    finderCache.removeResult(finderPath, finderArgs);
14331    
14332                                    throw processException(e);
14333                            }
14334                            finally {
14335                                    closeSession(session);
14336                            }
14337                    }
14338    
14339                    return list;
14340            }
14341    
14342            /**
14343             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14344             *
14345             * @param userId the user ID
14346             * @param classNameId the class name ID
14347             * @param classPK the class p k
14348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14349             * @return the first matching message-boards message
14350             * @throws NoSuchMessageException if a matching message-boards message could not be found
14351             */
14352            @Override
14353            public MBMessage findByU_C_C_First(long userId, long classNameId,
14354                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14355                    throws NoSuchMessageException {
14356                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14357                                    orderByComparator);
14358    
14359                    if (mbMessage != null) {
14360                            return mbMessage;
14361                    }
14362    
14363                    StringBundler msg = new StringBundler(8);
14364    
14365                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14366    
14367                    msg.append("userId=");
14368                    msg.append(userId);
14369    
14370                    msg.append(", classNameId=");
14371                    msg.append(classNameId);
14372    
14373                    msg.append(", classPK=");
14374                    msg.append(classPK);
14375    
14376                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14377    
14378                    throw new NoSuchMessageException(msg.toString());
14379            }
14380    
14381            /**
14382             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14383             *
14384             * @param userId the user ID
14385             * @param classNameId the class name ID
14386             * @param classPK the class p k
14387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14388             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14389             */
14390            @Override
14391            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14392                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14393                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14394                                    orderByComparator);
14395    
14396                    if (!list.isEmpty()) {
14397                            return list.get(0);
14398                    }
14399    
14400                    return null;
14401            }
14402    
14403            /**
14404             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14405             *
14406             * @param userId the user ID
14407             * @param classNameId the class name ID
14408             * @param classPK the class p k
14409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14410             * @return the last matching message-boards message
14411             * @throws NoSuchMessageException if a matching message-boards message could not be found
14412             */
14413            @Override
14414            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14415                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14416                    throws NoSuchMessageException {
14417                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14418                                    orderByComparator);
14419    
14420                    if (mbMessage != null) {
14421                            return mbMessage;
14422                    }
14423    
14424                    StringBundler msg = new StringBundler(8);
14425    
14426                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14427    
14428                    msg.append("userId=");
14429                    msg.append(userId);
14430    
14431                    msg.append(", classNameId=");
14432                    msg.append(classNameId);
14433    
14434                    msg.append(", classPK=");
14435                    msg.append(classPK);
14436    
14437                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14438    
14439                    throw new NoSuchMessageException(msg.toString());
14440            }
14441    
14442            /**
14443             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14444             *
14445             * @param userId the user ID
14446             * @param classNameId the class name ID
14447             * @param classPK the class p k
14448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14449             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14450             */
14451            @Override
14452            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14453                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14454                    int count = countByU_C_C(userId, classNameId, classPK);
14455    
14456                    if (count == 0) {
14457                            return null;
14458                    }
14459    
14460                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14461                                    count - 1, count, orderByComparator);
14462    
14463                    if (!list.isEmpty()) {
14464                            return list.get(0);
14465                    }
14466    
14467                    return null;
14468            }
14469    
14470            /**
14471             * 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;.
14472             *
14473             * @param messageId the primary key of the current message-boards message
14474             * @param userId the user ID
14475             * @param classNameId the class name ID
14476             * @param classPK the class p k
14477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14478             * @return the previous, current, and next message-boards message
14479             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14480             */
14481            @Override
14482            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14483                    long classNameId, long classPK,
14484                    OrderByComparator<MBMessage> orderByComparator)
14485                    throws NoSuchMessageException {
14486                    MBMessage mbMessage = findByPrimaryKey(messageId);
14487    
14488                    Session session = null;
14489    
14490                    try {
14491                            session = openSession();
14492    
14493                            MBMessage[] array = new MBMessageImpl[3];
14494    
14495                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14496                                            classNameId, classPK, orderByComparator, true);
14497    
14498                            array[1] = mbMessage;
14499    
14500                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14501                                            classNameId, classPK, orderByComparator, false);
14502    
14503                            return array;
14504                    }
14505                    catch (Exception e) {
14506                            throw processException(e);
14507                    }
14508                    finally {
14509                            closeSession(session);
14510                    }
14511            }
14512    
14513            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14514                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14515                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14516                    StringBundler query = null;
14517    
14518                    if (orderByComparator != null) {
14519                            query = new StringBundler(6 +
14520                                            (orderByComparator.getOrderByConditionFields().length * 3) +
14521                                            (orderByComparator.getOrderByFields().length * 3));
14522                    }
14523                    else {
14524                            query = new StringBundler(5);
14525                    }
14526    
14527                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14528    
14529                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14530    
14531                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14532    
14533                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14534    
14535                    if (orderByComparator != null) {
14536                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14537    
14538                            if (orderByConditionFields.length > 0) {
14539                                    query.append(WHERE_AND);
14540                            }
14541    
14542                            for (int i = 0; i < orderByConditionFields.length; i++) {
14543                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14544                                    query.append(orderByConditionFields[i]);
14545    
14546                                    if ((i + 1) < orderByConditionFields.length) {
14547                                            if (orderByComparator.isAscending() ^ previous) {
14548                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14549                                            }
14550                                            else {
14551                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14552                                            }
14553                                    }
14554                                    else {
14555                                            if (orderByComparator.isAscending() ^ previous) {
14556                                                    query.append(WHERE_GREATER_THAN);
14557                                            }
14558                                            else {
14559                                                    query.append(WHERE_LESSER_THAN);
14560                                            }
14561                                    }
14562                            }
14563    
14564                            query.append(ORDER_BY_CLAUSE);
14565    
14566                            String[] orderByFields = orderByComparator.getOrderByFields();
14567    
14568                            for (int i = 0; i < orderByFields.length; i++) {
14569                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14570                                    query.append(orderByFields[i]);
14571    
14572                                    if ((i + 1) < orderByFields.length) {
14573                                            if (orderByComparator.isAscending() ^ previous) {
14574                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14575                                            }
14576                                            else {
14577                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14578                                            }
14579                                    }
14580                                    else {
14581                                            if (orderByComparator.isAscending() ^ previous) {
14582                                                    query.append(ORDER_BY_ASC);
14583                                            }
14584                                            else {
14585                                                    query.append(ORDER_BY_DESC);
14586                                            }
14587                                    }
14588                            }
14589                    }
14590                    else {
14591                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14592                    }
14593    
14594                    String sql = query.toString();
14595    
14596                    Query q = session.createQuery(sql);
14597    
14598                    q.setFirstResult(0);
14599                    q.setMaxResults(2);
14600    
14601                    QueryPos qPos = QueryPos.getInstance(q);
14602    
14603                    qPos.add(userId);
14604    
14605                    qPos.add(classNameId);
14606    
14607                    qPos.add(classPK);
14608    
14609                    if (orderByComparator != null) {
14610                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14611    
14612                            for (Object value : values) {
14613                                    qPos.add(value);
14614                            }
14615                    }
14616    
14617                    List<MBMessage> list = q.list();
14618    
14619                    if (list.size() == 2) {
14620                            return list.get(1);
14621                    }
14622                    else {
14623                            return null;
14624                    }
14625            }
14626    
14627            /**
14628             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14629             *
14630             * @param userId the user ID
14631             * @param classNameId the class name ID
14632             * @param classPK the class p k
14633             */
14634            @Override
14635            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14636                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14637                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14638                            remove(mbMessage);
14639                    }
14640            }
14641    
14642            /**
14643             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14644             *
14645             * @param userId the user ID
14646             * @param classNameId the class name ID
14647             * @param classPK the class p k
14648             * @return the number of matching message-boards messages
14649             */
14650            @Override
14651            public int countByU_C_C(long userId, long classNameId, long classPK) {
14652                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14653    
14654                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14655    
14656                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14657    
14658                    if (count == null) {
14659                            StringBundler query = new StringBundler(4);
14660    
14661                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14662    
14663                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14664    
14665                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14666    
14667                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14668    
14669                            String sql = query.toString();
14670    
14671                            Session session = null;
14672    
14673                            try {
14674                                    session = openSession();
14675    
14676                                    Query q = session.createQuery(sql);
14677    
14678                                    QueryPos qPos = QueryPos.getInstance(q);
14679    
14680                                    qPos.add(userId);
14681    
14682                                    qPos.add(classNameId);
14683    
14684                                    qPos.add(classPK);
14685    
14686                                    count = (Long)q.uniqueResult();
14687    
14688                                    finderCache.putResult(finderPath, finderArgs, count);
14689                            }
14690                            catch (Exception e) {
14691                                    finderCache.removeResult(finderPath, finderArgs);
14692    
14693                                    throw processException(e);
14694                            }
14695                            finally {
14696                                    closeSession(session);
14697                            }
14698                    }
14699    
14700                    return count.intValue();
14701            }
14702    
14703            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14704            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14705            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14706            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14707                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14708                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14709                            new String[] {
14710                                    Long.class.getName(), Long.class.getName(),
14711                                    Integer.class.getName(),
14712                                    
14713                            Integer.class.getName(), Integer.class.getName(),
14714                                    OrderByComparator.class.getName()
14715                            });
14716            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14717                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14718                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14719                            new String[] {
14720                                    Long.class.getName(), Long.class.getName(),
14721                                    Integer.class.getName()
14722                            },
14723                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14724                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14725                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14726                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14727            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14728                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14729                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14730                            new String[] {
14731                                    Long.class.getName(), Long.class.getName(),
14732                                    Integer.class.getName()
14733                            });
14734            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14735                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14736                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14737                            new String[] {
14738                                    Long.class.getName(), Long.class.getName(),
14739                                    Integer.class.getName()
14740                            });
14741    
14742            /**
14743             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14744             *
14745             * @param userId the user ID
14746             * @param classNameId the class name ID
14747             * @param status the status
14748             * @return the matching message-boards messages
14749             */
14750            @Override
14751            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14752                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14753                            QueryUtil.ALL_POS, null);
14754            }
14755    
14756            /**
14757             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14758             *
14759             * <p>
14760             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14761             * </p>
14762             *
14763             * @param userId the user ID
14764             * @param classNameId the class name ID
14765             * @param status the status
14766             * @param start the lower bound of the range of message-boards messages
14767             * @param end the upper bound of the range of message-boards messages (not inclusive)
14768             * @return the range of matching message-boards messages
14769             */
14770            @Override
14771            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14772                    int status, int start, int end) {
14773                    return findByU_C_S(userId, classNameId, status, start, end, null);
14774            }
14775    
14776            /**
14777             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14778             *
14779             * <p>
14780             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14781             * </p>
14782             *
14783             * @param userId the user ID
14784             * @param classNameId the class name ID
14785             * @param status the status
14786             * @param start the lower bound of the range of message-boards messages
14787             * @param end the upper bound of the range of message-boards messages (not inclusive)
14788             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14789             * @return the ordered range of matching message-boards messages
14790             */
14791            @Override
14792            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14793                    int status, int start, int end,
14794                    OrderByComparator<MBMessage> orderByComparator) {
14795                    return findByU_C_S(userId, classNameId, status, start, end,
14796                            orderByComparator, true);
14797            }
14798    
14799            /**
14800             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14801             *
14802             * <p>
14803             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14804             * </p>
14805             *
14806             * @param userId the user ID
14807             * @param classNameId the class name ID
14808             * @param status the status
14809             * @param start the lower bound of the range of message-boards messages
14810             * @param end the upper bound of the range of message-boards messages (not inclusive)
14811             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14812             * @param retrieveFromCache whether to retrieve from the finder cache
14813             * @return the ordered range of matching message-boards messages
14814             */
14815            @Override
14816            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14817                    int status, int start, int end,
14818                    OrderByComparator<MBMessage> orderByComparator,
14819                    boolean retrieveFromCache) {
14820                    boolean pagination = true;
14821                    FinderPath finderPath = null;
14822                    Object[] finderArgs = null;
14823    
14824                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14825                                    (orderByComparator == null)) {
14826                            pagination = false;
14827                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14828                            finderArgs = new Object[] { userId, classNameId, status };
14829                    }
14830                    else {
14831                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14832                            finderArgs = new Object[] {
14833                                            userId, classNameId, status,
14834                                            
14835                                            start, end, orderByComparator
14836                                    };
14837                    }
14838    
14839                    List<MBMessage> list = null;
14840    
14841                    if (retrieveFromCache) {
14842                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14843                                            finderArgs, this);
14844    
14845                            if ((list != null) && !list.isEmpty()) {
14846                                    for (MBMessage mbMessage : list) {
14847                                            if ((userId != mbMessage.getUserId()) ||
14848                                                            (classNameId != mbMessage.getClassNameId()) ||
14849                                                            (status != mbMessage.getStatus())) {
14850                                                    list = null;
14851    
14852                                                    break;
14853                                            }
14854                                    }
14855                            }
14856                    }
14857    
14858                    if (list == null) {
14859                            StringBundler query = null;
14860    
14861                            if (orderByComparator != null) {
14862                                    query = new StringBundler(5 +
14863                                                    (orderByComparator.getOrderByFields().length * 2));
14864                            }
14865                            else {
14866                                    query = new StringBundler(5);
14867                            }
14868    
14869                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14870    
14871                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14872    
14873                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14874    
14875                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14876    
14877                            if (orderByComparator != null) {
14878                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14879                                            orderByComparator);
14880                            }
14881                            else
14882                             if (pagination) {
14883                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14884                            }
14885    
14886                            String sql = query.toString();
14887    
14888                            Session session = null;
14889    
14890                            try {
14891                                    session = openSession();
14892    
14893                                    Query q = session.createQuery(sql);
14894    
14895                                    QueryPos qPos = QueryPos.getInstance(q);
14896    
14897                                    qPos.add(userId);
14898    
14899                                    qPos.add(classNameId);
14900    
14901                                    qPos.add(status);
14902    
14903                                    if (!pagination) {
14904                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14905                                                            start, end, false);
14906    
14907                                            Collections.sort(list);
14908    
14909                                            list = Collections.unmodifiableList(list);
14910                                    }
14911                                    else {
14912                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14913                                                            start, end);
14914                                    }
14915    
14916                                    cacheResult(list);
14917    
14918                                    finderCache.putResult(finderPath, finderArgs, list);
14919                            }
14920                            catch (Exception e) {
14921                                    finderCache.removeResult(finderPath, finderArgs);
14922    
14923                                    throw processException(e);
14924                            }
14925                            finally {
14926                                    closeSession(session);
14927                            }
14928                    }
14929    
14930                    return list;
14931            }
14932    
14933            /**
14934             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14935             *
14936             * @param userId the user ID
14937             * @param classNameId the class name ID
14938             * @param status the status
14939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14940             * @return the first matching message-boards message
14941             * @throws NoSuchMessageException if a matching message-boards message could not be found
14942             */
14943            @Override
14944            public MBMessage findByU_C_S_First(long userId, long classNameId,
14945                    int status, OrderByComparator<MBMessage> orderByComparator)
14946                    throws NoSuchMessageException {
14947                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14948                                    orderByComparator);
14949    
14950                    if (mbMessage != null) {
14951                            return mbMessage;
14952                    }
14953    
14954                    StringBundler msg = new StringBundler(8);
14955    
14956                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14957    
14958                    msg.append("userId=");
14959                    msg.append(userId);
14960    
14961                    msg.append(", classNameId=");
14962                    msg.append(classNameId);
14963    
14964                    msg.append(", status=");
14965                    msg.append(status);
14966    
14967                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14968    
14969                    throw new NoSuchMessageException(msg.toString());
14970            }
14971    
14972            /**
14973             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14974             *
14975             * @param userId the user ID
14976             * @param classNameId the class name ID
14977             * @param status the status
14978             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14979             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14980             */
14981            @Override
14982            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14983                    int status, OrderByComparator<MBMessage> orderByComparator) {
14984                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14985                                    orderByComparator);
14986    
14987                    if (!list.isEmpty()) {
14988                            return list.get(0);
14989                    }
14990    
14991                    return null;
14992            }
14993    
14994            /**
14995             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14996             *
14997             * @param userId the user ID
14998             * @param classNameId the class name ID
14999             * @param status the status
15000             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15001             * @return the last matching message-boards message
15002             * @throws NoSuchMessageException if a matching message-boards message could not be found
15003             */
15004            @Override
15005            public MBMessage findByU_C_S_Last(long userId, long classNameId,
15006                    int status, OrderByComparator<MBMessage> orderByComparator)
15007                    throws NoSuchMessageException {
15008                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
15009                                    orderByComparator);
15010    
15011                    if (mbMessage != null) {
15012                            return mbMessage;
15013                    }
15014    
15015                    StringBundler msg = new StringBundler(8);
15016    
15017                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15018    
15019                    msg.append("userId=");
15020                    msg.append(userId);
15021    
15022                    msg.append(", classNameId=");
15023                    msg.append(classNameId);
15024    
15025                    msg.append(", status=");
15026                    msg.append(status);
15027    
15028                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15029    
15030                    throw new NoSuchMessageException(msg.toString());
15031            }
15032    
15033            /**
15034             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
15035             *
15036             * @param userId the user ID
15037             * @param classNameId the class name ID
15038             * @param status the status
15039             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15040             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15041             */
15042            @Override
15043            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
15044                    int status, OrderByComparator<MBMessage> orderByComparator) {
15045                    int count = countByU_C_S(userId, classNameId, status);
15046    
15047                    if (count == 0) {
15048                            return null;
15049                    }
15050    
15051                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
15052                                    count - 1, count, orderByComparator);
15053    
15054                    if (!list.isEmpty()) {
15055                            return list.get(0);
15056                    }
15057    
15058                    return null;
15059            }
15060    
15061            /**
15062             * 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;.
15063             *
15064             * @param messageId the primary key of the current message-boards message
15065             * @param userId the user ID
15066             * @param classNameId the class name ID
15067             * @param status the status
15068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15069             * @return the previous, current, and next message-boards message
15070             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15071             */
15072            @Override
15073            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
15074                    long classNameId, int status,
15075                    OrderByComparator<MBMessage> orderByComparator)
15076                    throws NoSuchMessageException {
15077                    MBMessage mbMessage = findByPrimaryKey(messageId);
15078    
15079                    Session session = null;
15080    
15081                    try {
15082                            session = openSession();
15083    
15084                            MBMessage[] array = new MBMessageImpl[3];
15085    
15086                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15087                                            classNameId, status, orderByComparator, true);
15088    
15089                            array[1] = mbMessage;
15090    
15091                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15092                                            classNameId, status, orderByComparator, false);
15093    
15094                            return array;
15095                    }
15096                    catch (Exception e) {
15097                            throw processException(e);
15098                    }
15099                    finally {
15100                            closeSession(session);
15101                    }
15102            }
15103    
15104            protected MBMessage getByU_C_S_PrevAndNext(Session session,
15105                    MBMessage mbMessage, long userId, long classNameId, int status,
15106                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15107                    StringBundler query = null;
15108    
15109                    if (orderByComparator != null) {
15110                            query = new StringBundler(6 +
15111                                            (orderByComparator.getOrderByConditionFields().length * 3) +
15112                                            (orderByComparator.getOrderByFields().length * 3));
15113                    }
15114                    else {
15115                            query = new StringBundler(5);
15116                    }
15117    
15118                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15119    
15120                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15121    
15122                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15123    
15124                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15125    
15126                    if (orderByComparator != null) {
15127                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15128    
15129                            if (orderByConditionFields.length > 0) {
15130                                    query.append(WHERE_AND);
15131                            }
15132    
15133                            for (int i = 0; i < orderByConditionFields.length; i++) {
15134                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15135                                    query.append(orderByConditionFields[i]);
15136    
15137                                    if ((i + 1) < orderByConditionFields.length) {
15138                                            if (orderByComparator.isAscending() ^ previous) {
15139                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15140                                            }
15141                                            else {
15142                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15143                                            }
15144                                    }
15145                                    else {
15146                                            if (orderByComparator.isAscending() ^ previous) {
15147                                                    query.append(WHERE_GREATER_THAN);
15148                                            }
15149                                            else {
15150                                                    query.append(WHERE_LESSER_THAN);
15151                                            }
15152                                    }
15153                            }
15154    
15155                            query.append(ORDER_BY_CLAUSE);
15156    
15157                            String[] orderByFields = orderByComparator.getOrderByFields();
15158    
15159                            for (int i = 0; i < orderByFields.length; i++) {
15160                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15161                                    query.append(orderByFields[i]);
15162    
15163                                    if ((i + 1) < orderByFields.length) {
15164                                            if (orderByComparator.isAscending() ^ previous) {
15165                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15166                                            }
15167                                            else {
15168                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15169                                            }
15170                                    }
15171                                    else {
15172                                            if (orderByComparator.isAscending() ^ previous) {
15173                                                    query.append(ORDER_BY_ASC);
15174                                            }
15175                                            else {
15176                                                    query.append(ORDER_BY_DESC);
15177                                            }
15178                                    }
15179                            }
15180                    }
15181                    else {
15182                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15183                    }
15184    
15185                    String sql = query.toString();
15186    
15187                    Query q = session.createQuery(sql);
15188    
15189                    q.setFirstResult(0);
15190                    q.setMaxResults(2);
15191    
15192                    QueryPos qPos = QueryPos.getInstance(q);
15193    
15194                    qPos.add(userId);
15195    
15196                    qPos.add(classNameId);
15197    
15198                    qPos.add(status);
15199    
15200                    if (orderByComparator != null) {
15201                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15202    
15203                            for (Object value : values) {
15204                                    qPos.add(value);
15205                            }
15206                    }
15207    
15208                    List<MBMessage> list = q.list();
15209    
15210                    if (list.size() == 2) {
15211                            return list.get(1);
15212                    }
15213                    else {
15214                            return null;
15215                    }
15216            }
15217    
15218            /**
15219             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15220             *
15221             * <p>
15222             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15223             * </p>
15224             *
15225             * @param userId the user ID
15226             * @param classNameIds the class name IDs
15227             * @param status the status
15228             * @return the matching message-boards messages
15229             */
15230            @Override
15231            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15232                    int status) {
15233                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
15234                            QueryUtil.ALL_POS, null);
15235            }
15236    
15237            /**
15238             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15239             *
15240             * <p>
15241             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15242             * </p>
15243             *
15244             * @param userId the user ID
15245             * @param classNameIds the class name IDs
15246             * @param status the status
15247             * @param start the lower bound of the range of message-boards messages
15248             * @param end the upper bound of the range of message-boards messages (not inclusive)
15249             * @return the range of matching message-boards messages
15250             */
15251            @Override
15252            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15253                    int status, int start, int end) {
15254                    return findByU_C_S(userId, classNameIds, status, start, end, null);
15255            }
15256    
15257            /**
15258             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15259             *
15260             * <p>
15261             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15262             * </p>
15263             *
15264             * @param userId the user ID
15265             * @param classNameIds the class name IDs
15266             * @param status the status
15267             * @param start the lower bound of the range of message-boards messages
15268             * @param end the upper bound of the range of message-boards messages (not inclusive)
15269             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15270             * @return the ordered range of matching message-boards messages
15271             */
15272            @Override
15273            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15274                    int status, int start, int end,
15275                    OrderByComparator<MBMessage> orderByComparator) {
15276                    return findByU_C_S(userId, classNameIds, status, start, end,
15277                            orderByComparator, true);
15278            }
15279    
15280            /**
15281             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;, optionally using the finder cache.
15282             *
15283             * <p>
15284             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15285             * </p>
15286             *
15287             * @param userId the user ID
15288             * @param classNameId the class name ID
15289             * @param status the status
15290             * @param start the lower bound of the range of message-boards messages
15291             * @param end the upper bound of the range of message-boards messages (not inclusive)
15292             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15293             * @param retrieveFromCache whether to retrieve from the finder cache
15294             * @return the ordered range of matching message-boards messages
15295             */
15296            @Override
15297            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15298                    int status, int start, int end,
15299                    OrderByComparator<MBMessage> orderByComparator,
15300                    boolean retrieveFromCache) {
15301                    if (classNameIds == null) {
15302                            classNameIds = new long[0];
15303                    }
15304                    else if (classNameIds.length > 1) {
15305                            classNameIds = ArrayUtil.unique(classNameIds);
15306    
15307                            Arrays.sort(classNameIds);
15308                    }
15309    
15310                    if (classNameIds.length == 1) {
15311                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15312                                    orderByComparator);
15313                    }
15314    
15315                    boolean pagination = true;
15316                    Object[] finderArgs = null;
15317    
15318                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15319                                    (orderByComparator == null)) {
15320                            pagination = false;
15321                            finderArgs = new Object[] {
15322                                            userId, StringUtil.merge(classNameIds), status
15323                                    };
15324                    }
15325                    else {
15326                            finderArgs = new Object[] {
15327                                            userId, StringUtil.merge(classNameIds), status,
15328                                            
15329                                            start, end, orderByComparator
15330                                    };
15331                    }
15332    
15333                    List<MBMessage> list = null;
15334    
15335                    if (retrieveFromCache) {
15336                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15337                                            finderArgs, this);
15338    
15339                            if ((list != null) && !list.isEmpty()) {
15340                                    for (MBMessage mbMessage : list) {
15341                                            if ((userId != mbMessage.getUserId()) ||
15342                                                            !ArrayUtil.contains(classNameIds,
15343                                                                    mbMessage.getClassNameId()) ||
15344                                                            (status != mbMessage.getStatus())) {
15345                                                    list = null;
15346    
15347                                                    break;
15348                                            }
15349                                    }
15350                            }
15351                    }
15352    
15353                    if (list == null) {
15354                            StringBundler query = new StringBundler();
15355    
15356                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15357    
15358                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15359    
15360                            if (classNameIds.length > 0) {
15361                                    query.append(StringPool.OPEN_PARENTHESIS);
15362    
15363                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15364    
15365                                    query.append(StringUtil.merge(classNameIds));
15366    
15367                                    query.append(StringPool.CLOSE_PARENTHESIS);
15368    
15369                                    query.append(StringPool.CLOSE_PARENTHESIS);
15370    
15371                                    query.append(WHERE_AND);
15372                            }
15373    
15374                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15375    
15376                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15377                                                    1)), query.index() - 1);
15378    
15379                            if (orderByComparator != null) {
15380                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15381                                            orderByComparator);
15382                            }
15383                            else
15384                             if (pagination) {
15385                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15386                            }
15387    
15388                            String sql = query.toString();
15389    
15390                            Session session = null;
15391    
15392                            try {
15393                                    session = openSession();
15394    
15395                                    Query q = session.createQuery(sql);
15396    
15397                                    QueryPos qPos = QueryPos.getInstance(q);
15398    
15399                                    qPos.add(userId);
15400    
15401                                    qPos.add(status);
15402    
15403                                    if (!pagination) {
15404                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15405                                                            start, end, false);
15406    
15407                                            Collections.sort(list);
15408    
15409                                            list = Collections.unmodifiableList(list);
15410                                    }
15411                                    else {
15412                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15413                                                            start, end);
15414                                    }
15415    
15416                                    cacheResult(list);
15417    
15418                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15419                                            finderArgs, list);
15420                            }
15421                            catch (Exception e) {
15422                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15423                                            finderArgs);
15424    
15425                                    throw processException(e);
15426                            }
15427                            finally {
15428                                    closeSession(session);
15429                            }
15430                    }
15431    
15432                    return list;
15433            }
15434    
15435            /**
15436             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15437             *
15438             * @param userId the user ID
15439             * @param classNameId the class name ID
15440             * @param status the status
15441             */
15442            @Override
15443            public void removeByU_C_S(long userId, long classNameId, int status) {
15444                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15445                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15446                            remove(mbMessage);
15447                    }
15448            }
15449    
15450            /**
15451             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15452             *
15453             * @param userId the user ID
15454             * @param classNameId the class name ID
15455             * @param status the status
15456             * @return the number of matching message-boards messages
15457             */
15458            @Override
15459            public int countByU_C_S(long userId, long classNameId, int status) {
15460                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15461    
15462                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15463    
15464                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
15465    
15466                    if (count == null) {
15467                            StringBundler query = new StringBundler(4);
15468    
15469                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15470    
15471                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15472    
15473                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15474    
15475                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15476    
15477                            String sql = query.toString();
15478    
15479                            Session session = null;
15480    
15481                            try {
15482                                    session = openSession();
15483    
15484                                    Query q = session.createQuery(sql);
15485    
15486                                    QueryPos qPos = QueryPos.getInstance(q);
15487    
15488                                    qPos.add(userId);
15489    
15490                                    qPos.add(classNameId);
15491    
15492                                    qPos.add(status);
15493    
15494                                    count = (Long)q.uniqueResult();
15495    
15496                                    finderCache.putResult(finderPath, finderArgs, count);
15497                            }
15498                            catch (Exception e) {
15499                                    finderCache.removeResult(finderPath, finderArgs);
15500    
15501                                    throw processException(e);
15502                            }
15503                            finally {
15504                                    closeSession(session);
15505                            }
15506                    }
15507    
15508                    return count.intValue();
15509            }
15510    
15511            /**
15512             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15513             *
15514             * @param userId the user ID
15515             * @param classNameIds the class name IDs
15516             * @param status the status
15517             * @return the number of matching message-boards messages
15518             */
15519            @Override
15520            public int countByU_C_S(long userId, long[] classNameIds, int status) {
15521                    if (classNameIds == null) {
15522                            classNameIds = new long[0];
15523                    }
15524                    else if (classNameIds.length > 1) {
15525                            classNameIds = ArrayUtil.unique(classNameIds);
15526    
15527                            Arrays.sort(classNameIds);
15528                    }
15529    
15530                    Object[] finderArgs = new Object[] {
15531                                    userId, StringUtil.merge(classNameIds), status
15532                            };
15533    
15534                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15535                                    finderArgs, this);
15536    
15537                    if (count == null) {
15538                            StringBundler query = new StringBundler();
15539    
15540                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15541    
15542                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15543    
15544                            if (classNameIds.length > 0) {
15545                                    query.append(StringPool.OPEN_PARENTHESIS);
15546    
15547                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15548    
15549                                    query.append(StringUtil.merge(classNameIds));
15550    
15551                                    query.append(StringPool.CLOSE_PARENTHESIS);
15552    
15553                                    query.append(StringPool.CLOSE_PARENTHESIS);
15554    
15555                                    query.append(WHERE_AND);
15556                            }
15557    
15558                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15559    
15560                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15561                                                    1)), query.index() - 1);
15562    
15563                            String sql = query.toString();
15564    
15565                            Session session = null;
15566    
15567                            try {
15568                                    session = openSession();
15569    
15570                                    Query q = session.createQuery(sql);
15571    
15572                                    QueryPos qPos = QueryPos.getInstance(q);
15573    
15574                                    qPos.add(userId);
15575    
15576                                    qPos.add(status);
15577    
15578                                    count = (Long)q.uniqueResult();
15579    
15580                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15581                                            finderArgs, count);
15582                            }
15583                            catch (Exception e) {
15584                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15585                                            finderArgs);
15586    
15587                                    throw processException(e);
15588                            }
15589                            finally {
15590                                    closeSession(session);
15591                            }
15592                    }
15593    
15594                    return count.intValue();
15595            }
15596    
15597            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15598            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15599            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
15600            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15601            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15602                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15603                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15604                            new String[] {
15605                                    Long.class.getName(), Long.class.getName(),
15606                                    Integer.class.getName(),
15607                                    
15608                            Integer.class.getName(), Integer.class.getName(),
15609                                    OrderByComparator.class.getName()
15610                            });
15611            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15612                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15613                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15614                            new String[] {
15615                                    Long.class.getName(), Long.class.getName(),
15616                                    Integer.class.getName()
15617                            },
15618                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15619                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15620                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15621                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15622            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15623                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15624                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15625                            new String[] {
15626                                    Long.class.getName(), Long.class.getName(),
15627                                    Integer.class.getName()
15628                            });
15629    
15630            /**
15631             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15632             *
15633             * @param classNameId the class name ID
15634             * @param classPK the class p k
15635             * @param status the status
15636             * @return the matching message-boards messages
15637             */
15638            @Override
15639            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15640                    int status) {
15641                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15642                            QueryUtil.ALL_POS, null);
15643            }
15644    
15645            /**
15646             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15647             *
15648             * <p>
15649             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15650             * </p>
15651             *
15652             * @param classNameId the class name ID
15653             * @param classPK the class p k
15654             * @param status the status
15655             * @param start the lower bound of the range of message-boards messages
15656             * @param end the upper bound of the range of message-boards messages (not inclusive)
15657             * @return the range of matching message-boards messages
15658             */
15659            @Override
15660            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15661                    int status, int start, int end) {
15662                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15663            }
15664    
15665            /**
15666             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15667             *
15668             * <p>
15669             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15670             * </p>
15671             *
15672             * @param classNameId the class name ID
15673             * @param classPK the class p k
15674             * @param status the status
15675             * @param start the lower bound of the range of message-boards messages
15676             * @param end the upper bound of the range of message-boards messages (not inclusive)
15677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15678             * @return the ordered range of matching message-boards messages
15679             */
15680            @Override
15681            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15682                    int status, int start, int end,
15683                    OrderByComparator<MBMessage> orderByComparator) {
15684                    return findByC_C_S(classNameId, classPK, status, start, end,
15685                            orderByComparator, true);
15686            }
15687    
15688            /**
15689             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15690             *
15691             * <p>
15692             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15693             * </p>
15694             *
15695             * @param classNameId the class name ID
15696             * @param classPK the class p k
15697             * @param status the status
15698             * @param start the lower bound of the range of message-boards messages
15699             * @param end the upper bound of the range of message-boards messages (not inclusive)
15700             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15701             * @param retrieveFromCache whether to retrieve from the finder cache
15702             * @return the ordered range of matching message-boards messages
15703             */
15704            @Override
15705            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15706                    int status, int start, int end,
15707                    OrderByComparator<MBMessage> orderByComparator,
15708                    boolean retrieveFromCache) {
15709                    boolean pagination = true;
15710                    FinderPath finderPath = null;
15711                    Object[] finderArgs = null;
15712    
15713                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15714                                    (orderByComparator == null)) {
15715                            pagination = false;
15716                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15717                            finderArgs = new Object[] { classNameId, classPK, status };
15718                    }
15719                    else {
15720                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15721                            finderArgs = new Object[] {
15722                                            classNameId, classPK, status,
15723                                            
15724                                            start, end, orderByComparator
15725                                    };
15726                    }
15727    
15728                    List<MBMessage> list = null;
15729    
15730                    if (retrieveFromCache) {
15731                            list = (List<MBMessage>)finderCache.getResult(finderPath,
15732                                            finderArgs, this);
15733    
15734                            if ((list != null) && !list.isEmpty()) {
15735                                    for (MBMessage mbMessage : list) {
15736                                            if ((classNameId != mbMessage.getClassNameId()) ||
15737                                                            (classPK != mbMessage.getClassPK()) ||
15738                                                            (status != mbMessage.getStatus())) {
15739                                                    list = null;
15740    
15741                                                    break;
15742                                            }
15743                                    }
15744                            }
15745                    }
15746    
15747                    if (list == null) {
15748                            StringBundler query = null;
15749    
15750                            if (orderByComparator != null) {
15751                                    query = new StringBundler(5 +
15752                                                    (orderByComparator.getOrderByFields().length * 2));
15753                            }
15754                            else {
15755                                    query = new StringBundler(5);
15756                            }
15757    
15758                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15759    
15760                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15761    
15762                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15763    
15764                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15765    
15766                            if (orderByComparator != null) {
15767                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15768                                            orderByComparator);
15769                            }
15770                            else
15771                             if (pagination) {
15772                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15773                            }
15774    
15775                            String sql = query.toString();
15776    
15777                            Session session = null;
15778    
15779                            try {
15780                                    session = openSession();
15781    
15782                                    Query q = session.createQuery(sql);
15783    
15784                                    QueryPos qPos = QueryPos.getInstance(q);
15785    
15786                                    qPos.add(classNameId);
15787    
15788                                    qPos.add(classPK);
15789    
15790                                    qPos.add(status);
15791    
15792                                    if (!pagination) {
15793                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15794                                                            start, end, false);
15795    
15796                                            Collections.sort(list);
15797    
15798                                            list = Collections.unmodifiableList(list);
15799                                    }
15800                                    else {
15801                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15802                                                            start, end);
15803                                    }
15804    
15805                                    cacheResult(list);
15806    
15807                                    finderCache.putResult(finderPath, finderArgs, list);
15808                            }
15809                            catch (Exception e) {
15810                                    finderCache.removeResult(finderPath, finderArgs);
15811    
15812                                    throw processException(e);
15813                            }
15814                            finally {
15815                                    closeSession(session);
15816                            }
15817                    }
15818    
15819                    return list;
15820            }
15821    
15822            /**
15823             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15824             *
15825             * @param classNameId the class name ID
15826             * @param classPK the class p k
15827             * @param status the status
15828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15829             * @return the first matching message-boards message
15830             * @throws NoSuchMessageException if a matching message-boards message could not be found
15831             */
15832            @Override
15833            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15834                    int status, OrderByComparator<MBMessage> orderByComparator)
15835                    throws NoSuchMessageException {
15836                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15837                                    orderByComparator);
15838    
15839                    if (mbMessage != null) {
15840                            return mbMessage;
15841                    }
15842    
15843                    StringBundler msg = new StringBundler(8);
15844    
15845                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15846    
15847                    msg.append("classNameId=");
15848                    msg.append(classNameId);
15849    
15850                    msg.append(", classPK=");
15851                    msg.append(classPK);
15852    
15853                    msg.append(", status=");
15854                    msg.append(status);
15855    
15856                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15857    
15858                    throw new NoSuchMessageException(msg.toString());
15859            }
15860    
15861            /**
15862             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15863             *
15864             * @param classNameId the class name ID
15865             * @param classPK the class p k
15866             * @param status the status
15867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15868             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15869             */
15870            @Override
15871            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15872                    int status, OrderByComparator<MBMessage> orderByComparator) {
15873                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15874                                    orderByComparator);
15875    
15876                    if (!list.isEmpty()) {
15877                            return list.get(0);
15878                    }
15879    
15880                    return null;
15881            }
15882    
15883            /**
15884             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15885             *
15886             * @param classNameId the class name ID
15887             * @param classPK the class p k
15888             * @param status the status
15889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15890             * @return the last matching message-boards message
15891             * @throws NoSuchMessageException if a matching message-boards message could not be found
15892             */
15893            @Override
15894            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15895                    int status, OrderByComparator<MBMessage> orderByComparator)
15896                    throws NoSuchMessageException {
15897                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15898                                    orderByComparator);
15899    
15900                    if (mbMessage != null) {
15901                            return mbMessage;
15902                    }
15903    
15904                    StringBundler msg = new StringBundler(8);
15905    
15906                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15907    
15908                    msg.append("classNameId=");
15909                    msg.append(classNameId);
15910    
15911                    msg.append(", classPK=");
15912                    msg.append(classPK);
15913    
15914                    msg.append(", status=");
15915                    msg.append(status);
15916    
15917                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15918    
15919                    throw new NoSuchMessageException(msg.toString());
15920            }
15921    
15922            /**
15923             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15924             *
15925             * @param classNameId the class name ID
15926             * @param classPK the class p k
15927             * @param status the status
15928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15929             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15930             */
15931            @Override
15932            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15933                    int status, OrderByComparator<MBMessage> orderByComparator) {
15934                    int count = countByC_C_S(classNameId, classPK, status);
15935    
15936                    if (count == 0) {
15937                            return null;
15938                    }
15939    
15940                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15941                                    count - 1, count, orderByComparator);
15942    
15943                    if (!list.isEmpty()) {
15944                            return list.get(0);
15945                    }
15946    
15947                    return null;
15948            }
15949    
15950            /**
15951             * 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;.
15952             *
15953             * @param messageId the primary key of the current message-boards message
15954             * @param classNameId the class name ID
15955             * @param classPK the class p k
15956             * @param status the status
15957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15958             * @return the previous, current, and next message-boards message
15959             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15960             */
15961            @Override
15962            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15963                    long classNameId, long classPK, int status,
15964                    OrderByComparator<MBMessage> orderByComparator)
15965                    throws NoSuchMessageException {
15966                    MBMessage mbMessage = findByPrimaryKey(messageId);
15967    
15968                    Session session = null;
15969    
15970                    try {
15971                            session = openSession();
15972    
15973                            MBMessage[] array = new MBMessageImpl[3];
15974    
15975                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15976                                            classPK, status, orderByComparator, true);
15977    
15978                            array[1] = mbMessage;
15979    
15980                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15981                                            classPK, status, orderByComparator, false);
15982    
15983                            return array;
15984                    }
15985                    catch (Exception e) {
15986                            throw processException(e);
15987                    }
15988                    finally {
15989                            closeSession(session);
15990                    }
15991            }
15992    
15993            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15994                    MBMessage mbMessage, long classNameId, long classPK, int status,
15995                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15996                    StringBundler query = null;
15997    
15998                    if (orderByComparator != null) {
15999                            query = new StringBundler(6 +
16000                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16001                                            (orderByComparator.getOrderByFields().length * 3));
16002                    }
16003                    else {
16004                            query = new StringBundler(5);
16005                    }
16006    
16007                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16008    
16009                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16010    
16011                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16012    
16013                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16014    
16015                    if (orderByComparator != null) {
16016                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16017    
16018                            if (orderByConditionFields.length > 0) {
16019                                    query.append(WHERE_AND);
16020                            }
16021    
16022                            for (int i = 0; i < orderByConditionFields.length; i++) {
16023                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16024                                    query.append(orderByConditionFields[i]);
16025    
16026                                    if ((i + 1) < orderByConditionFields.length) {
16027                                            if (orderByComparator.isAscending() ^ previous) {
16028                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16029                                            }
16030                                            else {
16031                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16032                                            }
16033                                    }
16034                                    else {
16035                                            if (orderByComparator.isAscending() ^ previous) {
16036                                                    query.append(WHERE_GREATER_THAN);
16037                                            }
16038                                            else {
16039                                                    query.append(WHERE_LESSER_THAN);
16040                                            }
16041                                    }
16042                            }
16043    
16044                            query.append(ORDER_BY_CLAUSE);
16045    
16046                            String[] orderByFields = orderByComparator.getOrderByFields();
16047    
16048                            for (int i = 0; i < orderByFields.length; i++) {
16049                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16050                                    query.append(orderByFields[i]);
16051    
16052                                    if ((i + 1) < orderByFields.length) {
16053                                            if (orderByComparator.isAscending() ^ previous) {
16054                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16055                                            }
16056                                            else {
16057                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16058                                            }
16059                                    }
16060                                    else {
16061                                            if (orderByComparator.isAscending() ^ previous) {
16062                                                    query.append(ORDER_BY_ASC);
16063                                            }
16064                                            else {
16065                                                    query.append(ORDER_BY_DESC);
16066                                            }
16067                                    }
16068                            }
16069                    }
16070                    else {
16071                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16072                    }
16073    
16074                    String sql = query.toString();
16075    
16076                    Query q = session.createQuery(sql);
16077    
16078                    q.setFirstResult(0);
16079                    q.setMaxResults(2);
16080    
16081                    QueryPos qPos = QueryPos.getInstance(q);
16082    
16083                    qPos.add(classNameId);
16084    
16085                    qPos.add(classPK);
16086    
16087                    qPos.add(status);
16088    
16089                    if (orderByComparator != null) {
16090                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16091    
16092                            for (Object value : values) {
16093                                    qPos.add(value);
16094                            }
16095                    }
16096    
16097                    List<MBMessage> list = q.list();
16098    
16099                    if (list.size() == 2) {
16100                            return list.get(1);
16101                    }
16102                    else {
16103                            return null;
16104                    }
16105            }
16106    
16107            /**
16108             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16109             *
16110             * @param classNameId the class name ID
16111             * @param classPK the class p k
16112             * @param status the status
16113             */
16114            @Override
16115            public void removeByC_C_S(long classNameId, long classPK, int status) {
16116                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
16117                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16118                            remove(mbMessage);
16119                    }
16120            }
16121    
16122            /**
16123             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16124             *
16125             * @param classNameId the class name ID
16126             * @param classPK the class p k
16127             * @param status the status
16128             * @return the number of matching message-boards messages
16129             */
16130            @Override
16131            public int countByC_C_S(long classNameId, long classPK, int status) {
16132                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
16133    
16134                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16135    
16136                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
16137    
16138                    if (count == null) {
16139                            StringBundler query = new StringBundler(4);
16140    
16141                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16142    
16143                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16144    
16145                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16146    
16147                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16148    
16149                            String sql = query.toString();
16150    
16151                            Session session = null;
16152    
16153                            try {
16154                                    session = openSession();
16155    
16156                                    Query q = session.createQuery(sql);
16157    
16158                                    QueryPos qPos = QueryPos.getInstance(q);
16159    
16160                                    qPos.add(classNameId);
16161    
16162                                    qPos.add(classPK);
16163    
16164                                    qPos.add(status);
16165    
16166                                    count = (Long)q.uniqueResult();
16167    
16168                                    finderCache.putResult(finderPath, finderArgs, count);
16169                            }
16170                            catch (Exception e) {
16171                                    finderCache.removeResult(finderPath, finderArgs);
16172    
16173                                    throw processException(e);
16174                            }
16175                            finally {
16176                                    closeSession(session);
16177                            }
16178                    }
16179    
16180                    return count.intValue();
16181            }
16182    
16183            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
16184            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
16185            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
16186            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16187                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16188                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
16189                            new String[] {
16190                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16191                                    Boolean.class.getName(),
16192                                    
16193                            Integer.class.getName(), Integer.class.getName(),
16194                                    OrderByComparator.class.getName()
16195                            });
16196            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
16197                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16199                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
16200                            new String[] {
16201                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16202                                    Boolean.class.getName()
16203                            },
16204                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16205                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16206                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16207                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
16208                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16209            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16210                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16211                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
16212                            new String[] {
16213                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16214                                    Boolean.class.getName()
16215                            });
16216    
16217            /**
16218             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16219             *
16220             * @param groupId the group ID
16221             * @param categoryId the category ID
16222             * @param threadId the thread ID
16223             * @param answer the answer
16224             * @return the matching message-boards messages
16225             */
16226            @Override
16227            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16228                    long threadId, boolean answer) {
16229                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
16230                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16231            }
16232    
16233            /**
16234             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16235             *
16236             * <p>
16237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16238             * </p>
16239             *
16240             * @param groupId the group ID
16241             * @param categoryId the category ID
16242             * @param threadId the thread ID
16243             * @param answer the answer
16244             * @param start the lower bound of the range of message-boards messages
16245             * @param end the upper bound of the range of message-boards messages (not inclusive)
16246             * @return the range of matching message-boards messages
16247             */
16248            @Override
16249            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16250                    long threadId, boolean answer, int start, int end) {
16251                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16252                            null);
16253            }
16254    
16255            /**
16256             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16257             *
16258             * <p>
16259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16260             * </p>
16261             *
16262             * @param groupId the group ID
16263             * @param categoryId the category ID
16264             * @param threadId the thread ID
16265             * @param answer the answer
16266             * @param start the lower bound of the range of message-boards messages
16267             * @param end the upper bound of the range of message-boards messages (not inclusive)
16268             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16269             * @return the ordered range of matching message-boards messages
16270             */
16271            @Override
16272            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16273                    long threadId, boolean answer, int start, int end,
16274                    OrderByComparator<MBMessage> orderByComparator) {
16275                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16276                            orderByComparator, true);
16277            }
16278    
16279            /**
16280             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16281             *
16282             * <p>
16283             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16284             * </p>
16285             *
16286             * @param groupId the group ID
16287             * @param categoryId the category ID
16288             * @param threadId the thread ID
16289             * @param answer the answer
16290             * @param start the lower bound of the range of message-boards messages
16291             * @param end the upper bound of the range of message-boards messages (not inclusive)
16292             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16293             * @param retrieveFromCache whether to retrieve from the finder cache
16294             * @return the ordered range of matching message-boards messages
16295             */
16296            @Override
16297            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16298                    long threadId, boolean answer, int start, int end,
16299                    OrderByComparator<MBMessage> orderByComparator,
16300                    boolean retrieveFromCache) {
16301                    boolean pagination = true;
16302                    FinderPath finderPath = null;
16303                    Object[] finderArgs = null;
16304    
16305                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16306                                    (orderByComparator == null)) {
16307                            pagination = false;
16308                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16309                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16310                    }
16311                    else {
16312                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16313                            finderArgs = new Object[] {
16314                                            groupId, categoryId, threadId, answer,
16315                                            
16316                                            start, end, orderByComparator
16317                                    };
16318                    }
16319    
16320                    List<MBMessage> list = null;
16321    
16322                    if (retrieveFromCache) {
16323                            list = (List<MBMessage>)finderCache.getResult(finderPath,
16324                                            finderArgs, this);
16325    
16326                            if ((list != null) && !list.isEmpty()) {
16327                                    for (MBMessage mbMessage : list) {
16328                                            if ((groupId != mbMessage.getGroupId()) ||
16329                                                            (categoryId != mbMessage.getCategoryId()) ||
16330                                                            (threadId != mbMessage.getThreadId()) ||
16331                                                            (answer != mbMessage.getAnswer())) {
16332                                                    list = null;
16333    
16334                                                    break;
16335                                            }
16336                                    }
16337                            }
16338                    }
16339    
16340                    if (list == null) {
16341                            StringBundler query = null;
16342    
16343                            if (orderByComparator != null) {
16344                                    query = new StringBundler(6 +
16345                                                    (orderByComparator.getOrderByFields().length * 2));
16346                            }
16347                            else {
16348                                    query = new StringBundler(6);
16349                            }
16350    
16351                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16352    
16353                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16354    
16355                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16356    
16357                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16358    
16359                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16360    
16361                            if (orderByComparator != null) {
16362                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16363                                            orderByComparator);
16364                            }
16365                            else
16366                             if (pagination) {
16367                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16368                            }
16369    
16370                            String sql = query.toString();
16371    
16372                            Session session = null;
16373    
16374                            try {
16375                                    session = openSession();
16376    
16377                                    Query q = session.createQuery(sql);
16378    
16379                                    QueryPos qPos = QueryPos.getInstance(q);
16380    
16381                                    qPos.add(groupId);
16382    
16383                                    qPos.add(categoryId);
16384    
16385                                    qPos.add(threadId);
16386    
16387                                    qPos.add(answer);
16388    
16389                                    if (!pagination) {
16390                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16391                                                            start, end, false);
16392    
16393                                            Collections.sort(list);
16394    
16395                                            list = Collections.unmodifiableList(list);
16396                                    }
16397                                    else {
16398                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16399                                                            start, end);
16400                                    }
16401    
16402                                    cacheResult(list);
16403    
16404                                    finderCache.putResult(finderPath, finderArgs, list);
16405                            }
16406                            catch (Exception e) {
16407                                    finderCache.removeResult(finderPath, finderArgs);
16408    
16409                                    throw processException(e);
16410                            }
16411                            finally {
16412                                    closeSession(session);
16413                            }
16414                    }
16415    
16416                    return list;
16417            }
16418    
16419            /**
16420             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16421             *
16422             * @param groupId the group ID
16423             * @param categoryId the category ID
16424             * @param threadId the thread ID
16425             * @param answer the answer
16426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16427             * @return the first matching message-boards message
16428             * @throws NoSuchMessageException if a matching message-boards message could not be found
16429             */
16430            @Override
16431            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16432                    long threadId, boolean answer,
16433                    OrderByComparator<MBMessage> orderByComparator)
16434                    throws NoSuchMessageException {
16435                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16436                                    threadId, answer, orderByComparator);
16437    
16438                    if (mbMessage != null) {
16439                            return mbMessage;
16440                    }
16441    
16442                    StringBundler msg = new StringBundler(10);
16443    
16444                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16445    
16446                    msg.append("groupId=");
16447                    msg.append(groupId);
16448    
16449                    msg.append(", categoryId=");
16450                    msg.append(categoryId);
16451    
16452                    msg.append(", threadId=");
16453                    msg.append(threadId);
16454    
16455                    msg.append(", answer=");
16456                    msg.append(answer);
16457    
16458                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16459    
16460                    throw new NoSuchMessageException(msg.toString());
16461            }
16462    
16463            /**
16464             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16465             *
16466             * @param groupId the group ID
16467             * @param categoryId the category ID
16468             * @param threadId the thread ID
16469             * @param answer the answer
16470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16471             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16472             */
16473            @Override
16474            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16475                    long threadId, boolean answer,
16476                    OrderByComparator<MBMessage> orderByComparator) {
16477                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16478                                    answer, 0, 1, orderByComparator);
16479    
16480                    if (!list.isEmpty()) {
16481                            return list.get(0);
16482                    }
16483    
16484                    return null;
16485            }
16486    
16487            /**
16488             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16489             *
16490             * @param groupId the group ID
16491             * @param categoryId the category ID
16492             * @param threadId the thread ID
16493             * @param answer the answer
16494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16495             * @return the last matching message-boards message
16496             * @throws NoSuchMessageException if a matching message-boards message could not be found
16497             */
16498            @Override
16499            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16500                    long threadId, boolean answer,
16501                    OrderByComparator<MBMessage> orderByComparator)
16502                    throws NoSuchMessageException {
16503                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16504                                    threadId, answer, orderByComparator);
16505    
16506                    if (mbMessage != null) {
16507                            return mbMessage;
16508                    }
16509    
16510                    StringBundler msg = new StringBundler(10);
16511    
16512                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16513    
16514                    msg.append("groupId=");
16515                    msg.append(groupId);
16516    
16517                    msg.append(", categoryId=");
16518                    msg.append(categoryId);
16519    
16520                    msg.append(", threadId=");
16521                    msg.append(threadId);
16522    
16523                    msg.append(", answer=");
16524                    msg.append(answer);
16525    
16526                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16527    
16528                    throw new NoSuchMessageException(msg.toString());
16529            }
16530    
16531            /**
16532             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16533             *
16534             * @param groupId the group ID
16535             * @param categoryId the category ID
16536             * @param threadId the thread ID
16537             * @param answer the answer
16538             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16539             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16540             */
16541            @Override
16542            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16543                    long threadId, boolean answer,
16544                    OrderByComparator<MBMessage> orderByComparator) {
16545                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16546    
16547                    if (count == 0) {
16548                            return null;
16549                    }
16550    
16551                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16552                                    answer, count - 1, count, orderByComparator);
16553    
16554                    if (!list.isEmpty()) {
16555                            return list.get(0);
16556                    }
16557    
16558                    return null;
16559            }
16560    
16561            /**
16562             * 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;.
16563             *
16564             * @param messageId the primary key of the current message-boards message
16565             * @param groupId the group ID
16566             * @param categoryId the category ID
16567             * @param threadId the thread ID
16568             * @param answer the answer
16569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16570             * @return the previous, current, and next message-boards message
16571             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16572             */
16573            @Override
16574            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16575                    long categoryId, long threadId, boolean answer,
16576                    OrderByComparator<MBMessage> orderByComparator)
16577                    throws NoSuchMessageException {
16578                    MBMessage mbMessage = findByPrimaryKey(messageId);
16579    
16580                    Session session = null;
16581    
16582                    try {
16583                            session = openSession();
16584    
16585                            MBMessage[] array = new MBMessageImpl[3];
16586    
16587                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16588                                            categoryId, threadId, answer, orderByComparator, true);
16589    
16590                            array[1] = mbMessage;
16591    
16592                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16593                                            categoryId, threadId, answer, orderByComparator, false);
16594    
16595                            return array;
16596                    }
16597                    catch (Exception e) {
16598                            throw processException(e);
16599                    }
16600                    finally {
16601                            closeSession(session);
16602                    }
16603            }
16604    
16605            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16606                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16607                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16608                    boolean previous) {
16609                    StringBundler query = null;
16610    
16611                    if (orderByComparator != null) {
16612                            query = new StringBundler(7 +
16613                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16614                                            (orderByComparator.getOrderByFields().length * 3));
16615                    }
16616                    else {
16617                            query = new StringBundler(6);
16618                    }
16619    
16620                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16621    
16622                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16623    
16624                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16625    
16626                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16627    
16628                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16629    
16630                    if (orderByComparator != null) {
16631                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16632    
16633                            if (orderByConditionFields.length > 0) {
16634                                    query.append(WHERE_AND);
16635                            }
16636    
16637                            for (int i = 0; i < orderByConditionFields.length; i++) {
16638                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16639                                    query.append(orderByConditionFields[i]);
16640    
16641                                    if ((i + 1) < orderByConditionFields.length) {
16642                                            if (orderByComparator.isAscending() ^ previous) {
16643                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16644                                            }
16645                                            else {
16646                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16647                                            }
16648                                    }
16649                                    else {
16650                                            if (orderByComparator.isAscending() ^ previous) {
16651                                                    query.append(WHERE_GREATER_THAN);
16652                                            }
16653                                            else {
16654                                                    query.append(WHERE_LESSER_THAN);
16655                                            }
16656                                    }
16657                            }
16658    
16659                            query.append(ORDER_BY_CLAUSE);
16660    
16661                            String[] orderByFields = orderByComparator.getOrderByFields();
16662    
16663                            for (int i = 0; i < orderByFields.length; i++) {
16664                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16665                                    query.append(orderByFields[i]);
16666    
16667                                    if ((i + 1) < orderByFields.length) {
16668                                            if (orderByComparator.isAscending() ^ previous) {
16669                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16670                                            }
16671                                            else {
16672                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16673                                            }
16674                                    }
16675                                    else {
16676                                            if (orderByComparator.isAscending() ^ previous) {
16677                                                    query.append(ORDER_BY_ASC);
16678                                            }
16679                                            else {
16680                                                    query.append(ORDER_BY_DESC);
16681                                            }
16682                                    }
16683                            }
16684                    }
16685                    else {
16686                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16687                    }
16688    
16689                    String sql = query.toString();
16690    
16691                    Query q = session.createQuery(sql);
16692    
16693                    q.setFirstResult(0);
16694                    q.setMaxResults(2);
16695    
16696                    QueryPos qPos = QueryPos.getInstance(q);
16697    
16698                    qPos.add(groupId);
16699    
16700                    qPos.add(categoryId);
16701    
16702                    qPos.add(threadId);
16703    
16704                    qPos.add(answer);
16705    
16706                    if (orderByComparator != null) {
16707                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16708    
16709                            for (Object value : values) {
16710                                    qPos.add(value);
16711                            }
16712                    }
16713    
16714                    List<MBMessage> list = q.list();
16715    
16716                    if (list.size() == 2) {
16717                            return list.get(1);
16718                    }
16719                    else {
16720                            return null;
16721                    }
16722            }
16723    
16724            /**
16725             * 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;.
16726             *
16727             * @param groupId the group ID
16728             * @param categoryId the category ID
16729             * @param threadId the thread ID
16730             * @param answer the answer
16731             * @return the matching message-boards messages that the user has permission to view
16732             */
16733            @Override
16734            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16735                    long threadId, boolean answer) {
16736                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16737                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16738            }
16739    
16740            /**
16741             * 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;.
16742             *
16743             * <p>
16744             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16745             * </p>
16746             *
16747             * @param groupId the group ID
16748             * @param categoryId the category ID
16749             * @param threadId the thread ID
16750             * @param answer the answer
16751             * @param start the lower bound of the range of message-boards messages
16752             * @param end the upper bound of the range of message-boards messages (not inclusive)
16753             * @return the range of matching message-boards messages that the user has permission to view
16754             */
16755            @Override
16756            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16757                    long threadId, boolean answer, int start, int end) {
16758                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16759                            start, end, null);
16760            }
16761    
16762            /**
16763             * 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;.
16764             *
16765             * <p>
16766             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16767             * </p>
16768             *
16769             * @param groupId the group ID
16770             * @param categoryId the category ID
16771             * @param threadId the thread ID
16772             * @param answer the answer
16773             * @param start the lower bound of the range of message-boards messages
16774             * @param end the upper bound of the range of message-boards messages (not inclusive)
16775             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16776             * @return the ordered range of matching message-boards messages that the user has permission to view
16777             */
16778            @Override
16779            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16780                    long threadId, boolean answer, int start, int end,
16781                    OrderByComparator<MBMessage> orderByComparator) {
16782                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16783                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16784                                    end, orderByComparator);
16785                    }
16786    
16787                    StringBundler query = null;
16788    
16789                    if (orderByComparator != null) {
16790                            query = new StringBundler(6 +
16791                                            (orderByComparator.getOrderByFields().length * 2));
16792                    }
16793                    else {
16794                            query = new StringBundler(7);
16795                    }
16796    
16797                    if (getDB().isSupportsInlineDistinct()) {
16798                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16799                    }
16800                    else {
16801                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16802                    }
16803    
16804                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16805    
16806                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16807    
16808                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16809    
16810                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16811    
16812                    if (!getDB().isSupportsInlineDistinct()) {
16813                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16814                    }
16815    
16816                    if (orderByComparator != null) {
16817                            if (getDB().isSupportsInlineDistinct()) {
16818                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16819                                            orderByComparator, true);
16820                            }
16821                            else {
16822                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16823                                            orderByComparator, true);
16824                            }
16825                    }
16826                    else {
16827                            if (getDB().isSupportsInlineDistinct()) {
16828                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16829                            }
16830                            else {
16831                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16832                            }
16833                    }
16834    
16835                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16836                                    MBMessage.class.getName(),
16837                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16838    
16839                    Session session = null;
16840    
16841                    try {
16842                            session = openSession();
16843    
16844                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16845    
16846                            if (getDB().isSupportsInlineDistinct()) {
16847                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16848                            }
16849                            else {
16850                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16851                            }
16852    
16853                            QueryPos qPos = QueryPos.getInstance(q);
16854    
16855                            qPos.add(groupId);
16856    
16857                            qPos.add(categoryId);
16858    
16859                            qPos.add(threadId);
16860    
16861                            qPos.add(answer);
16862    
16863                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16864                    }
16865                    catch (Exception e) {
16866                            throw processException(e);
16867                    }
16868                    finally {
16869                            closeSession(session);
16870                    }
16871            }
16872    
16873            /**
16874             * 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;.
16875             *
16876             * @param messageId the primary key of the current message-boards message
16877             * @param groupId the group ID
16878             * @param categoryId the category ID
16879             * @param threadId the thread ID
16880             * @param answer the answer
16881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16882             * @return the previous, current, and next message-boards message
16883             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16884             */
16885            @Override
16886            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16887                    long groupId, long categoryId, long threadId, boolean answer,
16888                    OrderByComparator<MBMessage> orderByComparator)
16889                    throws NoSuchMessageException {
16890                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16891                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16892                                    threadId, answer, orderByComparator);
16893                    }
16894    
16895                    MBMessage mbMessage = findByPrimaryKey(messageId);
16896    
16897                    Session session = null;
16898    
16899                    try {
16900                            session = openSession();
16901    
16902                            MBMessage[] array = new MBMessageImpl[3];
16903    
16904                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16905                                            groupId, categoryId, threadId, answer, orderByComparator,
16906                                            true);
16907    
16908                            array[1] = mbMessage;
16909    
16910                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16911                                            groupId, categoryId, threadId, answer, orderByComparator,
16912                                            false);
16913    
16914                            return array;
16915                    }
16916                    catch (Exception e) {
16917                            throw processException(e);
16918                    }
16919                    finally {
16920                            closeSession(session);
16921                    }
16922            }
16923    
16924            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16925                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16926                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16927                    boolean previous) {
16928                    StringBundler query = null;
16929    
16930                    if (orderByComparator != null) {
16931                            query = new StringBundler(8 +
16932                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16933                                            (orderByComparator.getOrderByFields().length * 3));
16934                    }
16935                    else {
16936                            query = new StringBundler(7);
16937                    }
16938    
16939                    if (getDB().isSupportsInlineDistinct()) {
16940                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16941                    }
16942                    else {
16943                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16944                    }
16945    
16946                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16947    
16948                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16949    
16950                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16951    
16952                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16953    
16954                    if (!getDB().isSupportsInlineDistinct()) {
16955                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16956                    }
16957    
16958                    if (orderByComparator != null) {
16959                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16960    
16961                            if (orderByConditionFields.length > 0) {
16962                                    query.append(WHERE_AND);
16963                            }
16964    
16965                            for (int i = 0; i < orderByConditionFields.length; i++) {
16966                                    if (getDB().isSupportsInlineDistinct()) {
16967                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16968                                    }
16969                                    else {
16970                                            query.append(_ORDER_BY_ENTITY_TABLE);
16971                                    }
16972    
16973                                    query.append(orderByConditionFields[i]);
16974    
16975                                    if ((i + 1) < orderByConditionFields.length) {
16976                                            if (orderByComparator.isAscending() ^ previous) {
16977                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16978                                            }
16979                                            else {
16980                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16981                                            }
16982                                    }
16983                                    else {
16984                                            if (orderByComparator.isAscending() ^ previous) {
16985                                                    query.append(WHERE_GREATER_THAN);
16986                                            }
16987                                            else {
16988                                                    query.append(WHERE_LESSER_THAN);
16989                                            }
16990                                    }
16991                            }
16992    
16993                            query.append(ORDER_BY_CLAUSE);
16994    
16995                            String[] orderByFields = orderByComparator.getOrderByFields();
16996    
16997                            for (int i = 0; i < orderByFields.length; i++) {
16998                                    if (getDB().isSupportsInlineDistinct()) {
16999                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17000                                    }
17001                                    else {
17002                                            query.append(_ORDER_BY_ENTITY_TABLE);
17003                                    }
17004    
17005                                    query.append(orderByFields[i]);
17006    
17007                                    if ((i + 1) < orderByFields.length) {
17008                                            if (orderByComparator.isAscending() ^ previous) {
17009                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17010                                            }
17011                                            else {
17012                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17013                                            }
17014                                    }
17015                                    else {
17016                                            if (orderByComparator.isAscending() ^ previous) {
17017                                                    query.append(ORDER_BY_ASC);
17018                                            }
17019                                            else {
17020                                                    query.append(ORDER_BY_DESC);
17021                                            }
17022                                    }
17023                            }
17024                    }
17025                    else {
17026                            if (getDB().isSupportsInlineDistinct()) {
17027                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17028                            }
17029                            else {
17030                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17031                            }
17032                    }
17033    
17034                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17035                                    MBMessage.class.getName(),
17036                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17037    
17038                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17039    
17040                    q.setFirstResult(0);
17041                    q.setMaxResults(2);
17042    
17043                    if (getDB().isSupportsInlineDistinct()) {
17044                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17045                    }
17046                    else {
17047                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17048                    }
17049    
17050                    QueryPos qPos = QueryPos.getInstance(q);
17051    
17052                    qPos.add(groupId);
17053    
17054                    qPos.add(categoryId);
17055    
17056                    qPos.add(threadId);
17057    
17058                    qPos.add(answer);
17059    
17060                    if (orderByComparator != null) {
17061                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17062    
17063                            for (Object value : values) {
17064                                    qPos.add(value);
17065                            }
17066                    }
17067    
17068                    List<MBMessage> list = q.list();
17069    
17070                    if (list.size() == 2) {
17071                            return list.get(1);
17072                    }
17073                    else {
17074                            return null;
17075                    }
17076            }
17077    
17078            /**
17079             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
17080             *
17081             * @param groupId the group ID
17082             * @param categoryId the category ID
17083             * @param threadId the thread ID
17084             * @param answer the answer
17085             */
17086            @Override
17087            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
17088                    boolean answer) {
17089                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
17090                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17091                            remove(mbMessage);
17092                    }
17093            }
17094    
17095            /**
17096             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17097             *
17098             * @param groupId the group ID
17099             * @param categoryId the category ID
17100             * @param threadId the thread ID
17101             * @param answer the answer
17102             * @return the number of matching message-boards messages
17103             */
17104            @Override
17105            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17106                    boolean answer) {
17107                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
17108    
17109                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17110    
17111                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
17112    
17113                    if (count == null) {
17114                            StringBundler query = new StringBundler(5);
17115    
17116                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17117    
17118                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17119    
17120                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17121    
17122                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17123    
17124                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17125    
17126                            String sql = query.toString();
17127    
17128                            Session session = null;
17129    
17130                            try {
17131                                    session = openSession();
17132    
17133                                    Query q = session.createQuery(sql);
17134    
17135                                    QueryPos qPos = QueryPos.getInstance(q);
17136    
17137                                    qPos.add(groupId);
17138    
17139                                    qPos.add(categoryId);
17140    
17141                                    qPos.add(threadId);
17142    
17143                                    qPos.add(answer);
17144    
17145                                    count = (Long)q.uniqueResult();
17146    
17147                                    finderCache.putResult(finderPath, finderArgs, count);
17148                            }
17149                            catch (Exception e) {
17150                                    finderCache.removeResult(finderPath, finderArgs);
17151    
17152                                    throw processException(e);
17153                            }
17154                            finally {
17155                                    closeSession(session);
17156                            }
17157                    }
17158    
17159                    return count.intValue();
17160            }
17161    
17162            /**
17163             * 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;.
17164             *
17165             * @param groupId the group ID
17166             * @param categoryId the category ID
17167             * @param threadId the thread ID
17168             * @param answer the answer
17169             * @return the number of matching message-boards messages that the user has permission to view
17170             */
17171            @Override
17172            public int filterCountByG_C_T_A(long groupId, long categoryId,
17173                    long threadId, boolean answer) {
17174                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17175                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17176                    }
17177    
17178                    StringBundler query = new StringBundler(5);
17179    
17180                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17181    
17182                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17183    
17184                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17185    
17186                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17187    
17188                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17189    
17190                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17191                                    MBMessage.class.getName(),
17192                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17193    
17194                    Session session = null;
17195    
17196                    try {
17197                            session = openSession();
17198    
17199                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17200    
17201                            q.addScalar(COUNT_COLUMN_NAME,
17202                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17203    
17204                            QueryPos qPos = QueryPos.getInstance(q);
17205    
17206                            qPos.add(groupId);
17207    
17208                            qPos.add(categoryId);
17209    
17210                            qPos.add(threadId);
17211    
17212                            qPos.add(answer);
17213    
17214                            Long count = (Long)q.uniqueResult();
17215    
17216                            return count.intValue();
17217                    }
17218                    catch (Exception e) {
17219                            throw processException(e);
17220                    }
17221                    finally {
17222                            closeSession(session);
17223                    }
17224            }
17225    
17226            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17227            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17228            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17229            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17230            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17231                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17232                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
17233                            new String[] {
17234                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17235                                    Integer.class.getName(),
17236                                    
17237                            Integer.class.getName(), Integer.class.getName(),
17238                                    OrderByComparator.class.getName()
17239                            });
17240            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
17241                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17242                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17243                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
17244                            new String[] {
17245                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17246                                    Integer.class.getName()
17247                            },
17248                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17249                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17250                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17251                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17252                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17253            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17254                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17255                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
17256                            new String[] {
17257                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17258                                    Integer.class.getName()
17259                            });
17260    
17261            /**
17262             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17263             *
17264             * @param groupId the group ID
17265             * @param categoryId the category ID
17266             * @param threadId the thread ID
17267             * @param status the status
17268             * @return the matching message-boards messages
17269             */
17270            @Override
17271            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17272                    long threadId, int status) {
17273                    return findByG_C_T_S(groupId, categoryId, threadId, status,
17274                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17275            }
17276    
17277            /**
17278             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17279             *
17280             * <p>
17281             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17282             * </p>
17283             *
17284             * @param groupId the group ID
17285             * @param categoryId the category ID
17286             * @param threadId the thread ID
17287             * @param status the status
17288             * @param start the lower bound of the range of message-boards messages
17289             * @param end the upper bound of the range of message-boards messages (not inclusive)
17290             * @return the range of matching message-boards messages
17291             */
17292            @Override
17293            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17294                    long threadId, int status, int start, int end) {
17295                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17296                            null);
17297            }
17298    
17299            /**
17300             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17301             *
17302             * <p>
17303             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17304             * </p>
17305             *
17306             * @param groupId the group ID
17307             * @param categoryId the category ID
17308             * @param threadId the thread ID
17309             * @param status the status
17310             * @param start the lower bound of the range of message-boards messages
17311             * @param end the upper bound of the range of message-boards messages (not inclusive)
17312             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17313             * @return the ordered range of matching message-boards messages
17314             */
17315            @Override
17316            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17317                    long threadId, int status, int start, int end,
17318                    OrderByComparator<MBMessage> orderByComparator) {
17319                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17320                            orderByComparator, true);
17321            }
17322    
17323            /**
17324             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17325             *
17326             * <p>
17327             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17328             * </p>
17329             *
17330             * @param groupId the group ID
17331             * @param categoryId the category ID
17332             * @param threadId the thread ID
17333             * @param status the status
17334             * @param start the lower bound of the range of message-boards messages
17335             * @param end the upper bound of the range of message-boards messages (not inclusive)
17336             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17337             * @param retrieveFromCache whether to retrieve from the finder cache
17338             * @return the ordered range of matching message-boards messages
17339             */
17340            @Override
17341            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17342                    long threadId, int status, int start, int end,
17343                    OrderByComparator<MBMessage> orderByComparator,
17344                    boolean retrieveFromCache) {
17345                    boolean pagination = true;
17346                    FinderPath finderPath = null;
17347                    Object[] finderArgs = null;
17348    
17349                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17350                                    (orderByComparator == null)) {
17351                            pagination = false;
17352                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17353                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17354                    }
17355                    else {
17356                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17357                            finderArgs = new Object[] {
17358                                            groupId, categoryId, threadId, status,
17359                                            
17360                                            start, end, orderByComparator
17361                                    };
17362                    }
17363    
17364                    List<MBMessage> list = null;
17365    
17366                    if (retrieveFromCache) {
17367                            list = (List<MBMessage>)finderCache.getResult(finderPath,
17368                                            finderArgs, this);
17369    
17370                            if ((list != null) && !list.isEmpty()) {
17371                                    for (MBMessage mbMessage : list) {
17372                                            if ((groupId != mbMessage.getGroupId()) ||
17373                                                            (categoryId != mbMessage.getCategoryId()) ||
17374                                                            (threadId != mbMessage.getThreadId()) ||
17375                                                            (status != mbMessage.getStatus())) {
17376                                                    list = null;
17377    
17378                                                    break;
17379                                            }
17380                                    }
17381                            }
17382                    }
17383    
17384                    if (list == null) {
17385                            StringBundler query = null;
17386    
17387                            if (orderByComparator != null) {
17388                                    query = new StringBundler(6 +
17389                                                    (orderByComparator.getOrderByFields().length * 2));
17390                            }
17391                            else {
17392                                    query = new StringBundler(6);
17393                            }
17394    
17395                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17396    
17397                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17398    
17399                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17400    
17401                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17402    
17403                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17404    
17405                            if (orderByComparator != null) {
17406                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17407                                            orderByComparator);
17408                            }
17409                            else
17410                             if (pagination) {
17411                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17412                            }
17413    
17414                            String sql = query.toString();
17415    
17416                            Session session = null;
17417    
17418                            try {
17419                                    session = openSession();
17420    
17421                                    Query q = session.createQuery(sql);
17422    
17423                                    QueryPos qPos = QueryPos.getInstance(q);
17424    
17425                                    qPos.add(groupId);
17426    
17427                                    qPos.add(categoryId);
17428    
17429                                    qPos.add(threadId);
17430    
17431                                    qPos.add(status);
17432    
17433                                    if (!pagination) {
17434                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17435                                                            start, end, false);
17436    
17437                                            Collections.sort(list);
17438    
17439                                            list = Collections.unmodifiableList(list);
17440                                    }
17441                                    else {
17442                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17443                                                            start, end);
17444                                    }
17445    
17446                                    cacheResult(list);
17447    
17448                                    finderCache.putResult(finderPath, finderArgs, list);
17449                            }
17450                            catch (Exception e) {
17451                                    finderCache.removeResult(finderPath, finderArgs);
17452    
17453                                    throw processException(e);
17454                            }
17455                            finally {
17456                                    closeSession(session);
17457                            }
17458                    }
17459    
17460                    return list;
17461            }
17462    
17463            /**
17464             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17465             *
17466             * @param groupId the group ID
17467             * @param categoryId the category ID
17468             * @param threadId the thread ID
17469             * @param status the status
17470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17471             * @return the first matching message-boards message
17472             * @throws NoSuchMessageException if a matching message-boards message could not be found
17473             */
17474            @Override
17475            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17476                    long threadId, int status,
17477                    OrderByComparator<MBMessage> orderByComparator)
17478                    throws NoSuchMessageException {
17479                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17480                                    threadId, status, orderByComparator);
17481    
17482                    if (mbMessage != null) {
17483                            return mbMessage;
17484                    }
17485    
17486                    StringBundler msg = new StringBundler(10);
17487    
17488                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17489    
17490                    msg.append("groupId=");
17491                    msg.append(groupId);
17492    
17493                    msg.append(", categoryId=");
17494                    msg.append(categoryId);
17495    
17496                    msg.append(", threadId=");
17497                    msg.append(threadId);
17498    
17499                    msg.append(", status=");
17500                    msg.append(status);
17501    
17502                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17503    
17504                    throw new NoSuchMessageException(msg.toString());
17505            }
17506    
17507            /**
17508             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17509             *
17510             * @param groupId the group ID
17511             * @param categoryId the category ID
17512             * @param threadId the thread ID
17513             * @param status the status
17514             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17515             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17516             */
17517            @Override
17518            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17519                    long threadId, int status,
17520                    OrderByComparator<MBMessage> orderByComparator) {
17521                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17522                                    status, 0, 1, orderByComparator);
17523    
17524                    if (!list.isEmpty()) {
17525                            return list.get(0);
17526                    }
17527    
17528                    return null;
17529            }
17530    
17531            /**
17532             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17533             *
17534             * @param groupId the group ID
17535             * @param categoryId the category ID
17536             * @param threadId the thread ID
17537             * @param status the status
17538             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17539             * @return the last matching message-boards message
17540             * @throws NoSuchMessageException if a matching message-boards message could not be found
17541             */
17542            @Override
17543            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17544                    long threadId, int status,
17545                    OrderByComparator<MBMessage> orderByComparator)
17546                    throws NoSuchMessageException {
17547                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17548                                    threadId, status, orderByComparator);
17549    
17550                    if (mbMessage != null) {
17551                            return mbMessage;
17552                    }
17553    
17554                    StringBundler msg = new StringBundler(10);
17555    
17556                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17557    
17558                    msg.append("groupId=");
17559                    msg.append(groupId);
17560    
17561                    msg.append(", categoryId=");
17562                    msg.append(categoryId);
17563    
17564                    msg.append(", threadId=");
17565                    msg.append(threadId);
17566    
17567                    msg.append(", status=");
17568                    msg.append(status);
17569    
17570                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17571    
17572                    throw new NoSuchMessageException(msg.toString());
17573            }
17574    
17575            /**
17576             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17577             *
17578             * @param groupId the group ID
17579             * @param categoryId the category ID
17580             * @param threadId the thread ID
17581             * @param status the status
17582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17583             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17584             */
17585            @Override
17586            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17587                    long threadId, int status,
17588                    OrderByComparator<MBMessage> orderByComparator) {
17589                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17590    
17591                    if (count == 0) {
17592                            return null;
17593                    }
17594    
17595                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17596                                    status, count - 1, count, orderByComparator);
17597    
17598                    if (!list.isEmpty()) {
17599                            return list.get(0);
17600                    }
17601    
17602                    return null;
17603            }
17604    
17605            /**
17606             * 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;.
17607             *
17608             * @param messageId the primary key of the current message-boards message
17609             * @param groupId the group ID
17610             * @param categoryId the category ID
17611             * @param threadId the thread ID
17612             * @param status the status
17613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17614             * @return the previous, current, and next message-boards message
17615             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17616             */
17617            @Override
17618            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17619                    long categoryId, long threadId, int status,
17620                    OrderByComparator<MBMessage> orderByComparator)
17621                    throws NoSuchMessageException {
17622                    MBMessage mbMessage = findByPrimaryKey(messageId);
17623    
17624                    Session session = null;
17625    
17626                    try {
17627                            session = openSession();
17628    
17629                            MBMessage[] array = new MBMessageImpl[3];
17630    
17631                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17632                                            categoryId, threadId, status, orderByComparator, true);
17633    
17634                            array[1] = mbMessage;
17635    
17636                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17637                                            categoryId, threadId, status, orderByComparator, false);
17638    
17639                            return array;
17640                    }
17641                    catch (Exception e) {
17642                            throw processException(e);
17643                    }
17644                    finally {
17645                            closeSession(session);
17646                    }
17647            }
17648    
17649            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17650                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17651                    int status, OrderByComparator<MBMessage> orderByComparator,
17652                    boolean previous) {
17653                    StringBundler query = null;
17654    
17655                    if (orderByComparator != null) {
17656                            query = new StringBundler(7 +
17657                                            (orderByComparator.getOrderByConditionFields().length * 3) +
17658                                            (orderByComparator.getOrderByFields().length * 3));
17659                    }
17660                    else {
17661                            query = new StringBundler(6);
17662                    }
17663    
17664                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17665    
17666                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17667    
17668                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17669    
17670                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17671    
17672                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17673    
17674                    if (orderByComparator != null) {
17675                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17676    
17677                            if (orderByConditionFields.length > 0) {
17678                                    query.append(WHERE_AND);
17679                            }
17680    
17681                            for (int i = 0; i < orderByConditionFields.length; i++) {
17682                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17683                                    query.append(orderByConditionFields[i]);
17684    
17685                                    if ((i + 1) < orderByConditionFields.length) {
17686                                            if (orderByComparator.isAscending() ^ previous) {
17687                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17688                                            }
17689                                            else {
17690                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17691                                            }
17692                                    }
17693                                    else {
17694                                            if (orderByComparator.isAscending() ^ previous) {
17695                                                    query.append(WHERE_GREATER_THAN);
17696                                            }
17697                                            else {
17698                                                    query.append(WHERE_LESSER_THAN);
17699                                            }
17700                                    }
17701                            }
17702    
17703                            query.append(ORDER_BY_CLAUSE);
17704    
17705                            String[] orderByFields = orderByComparator.getOrderByFields();
17706    
17707                            for (int i = 0; i < orderByFields.length; i++) {
17708                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17709                                    query.append(orderByFields[i]);
17710    
17711                                    if ((i + 1) < orderByFields.length) {
17712                                            if (orderByComparator.isAscending() ^ previous) {
17713                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17714                                            }
17715                                            else {
17716                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17717                                            }
17718                                    }
17719                                    else {
17720                                            if (orderByComparator.isAscending() ^ previous) {
17721                                                    query.append(ORDER_BY_ASC);
17722                                            }
17723                                            else {
17724                                                    query.append(ORDER_BY_DESC);
17725                                            }
17726                                    }
17727                            }
17728                    }
17729                    else {
17730                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17731                    }
17732    
17733                    String sql = query.toString();
17734    
17735                    Query q = session.createQuery(sql);
17736    
17737                    q.setFirstResult(0);
17738                    q.setMaxResults(2);
17739    
17740                    QueryPos qPos = QueryPos.getInstance(q);
17741    
17742                    qPos.add(groupId);
17743    
17744                    qPos.add(categoryId);
17745    
17746                    qPos.add(threadId);
17747    
17748                    qPos.add(status);
17749    
17750                    if (orderByComparator != null) {
17751                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17752    
17753                            for (Object value : values) {
17754                                    qPos.add(value);
17755                            }
17756                    }
17757    
17758                    List<MBMessage> list = q.list();
17759    
17760                    if (list.size() == 2) {
17761                            return list.get(1);
17762                    }
17763                    else {
17764                            return null;
17765                    }
17766            }
17767    
17768            /**
17769             * 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;.
17770             *
17771             * @param groupId the group ID
17772             * @param categoryId the category ID
17773             * @param threadId the thread ID
17774             * @param status the status
17775             * @return the matching message-boards messages that the user has permission to view
17776             */
17777            @Override
17778            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17779                    long threadId, int status) {
17780                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17781                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17782            }
17783    
17784            /**
17785             * 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;.
17786             *
17787             * <p>
17788             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17789             * </p>
17790             *
17791             * @param groupId the group ID
17792             * @param categoryId the category ID
17793             * @param threadId the thread ID
17794             * @param status the status
17795             * @param start the lower bound of the range of message-boards messages
17796             * @param end the upper bound of the range of message-boards messages (not inclusive)
17797             * @return the range of matching message-boards messages that the user has permission to view
17798             */
17799            @Override
17800            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17801                    long threadId, int status, int start, int end) {
17802                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17803                            start, end, null);
17804            }
17805    
17806            /**
17807             * 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;.
17808             *
17809             * <p>
17810             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17811             * </p>
17812             *
17813             * @param groupId the group ID
17814             * @param categoryId the category ID
17815             * @param threadId the thread ID
17816             * @param status the status
17817             * @param start the lower bound of the range of message-boards messages
17818             * @param end the upper bound of the range of message-boards messages (not inclusive)
17819             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17820             * @return the ordered range of matching message-boards messages that the user has permission to view
17821             */
17822            @Override
17823            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17824                    long threadId, int status, int start, int end,
17825                    OrderByComparator<MBMessage> orderByComparator) {
17826                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17827                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17828                                    end, orderByComparator);
17829                    }
17830    
17831                    StringBundler query = null;
17832    
17833                    if (orderByComparator != null) {
17834                            query = new StringBundler(6 +
17835                                            (orderByComparator.getOrderByFields().length * 2));
17836                    }
17837                    else {
17838                            query = new StringBundler(7);
17839                    }
17840    
17841                    if (getDB().isSupportsInlineDistinct()) {
17842                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17843                    }
17844                    else {
17845                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17846                    }
17847    
17848                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17849    
17850                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17851    
17852                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17853    
17854                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17855    
17856                    if (!getDB().isSupportsInlineDistinct()) {
17857                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17858                    }
17859    
17860                    if (orderByComparator != null) {
17861                            if (getDB().isSupportsInlineDistinct()) {
17862                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17863                                            orderByComparator, true);
17864                            }
17865                            else {
17866                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17867                                            orderByComparator, true);
17868                            }
17869                    }
17870                    else {
17871                            if (getDB().isSupportsInlineDistinct()) {
17872                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17873                            }
17874                            else {
17875                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17876                            }
17877                    }
17878    
17879                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17880                                    MBMessage.class.getName(),
17881                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17882    
17883                    Session session = null;
17884    
17885                    try {
17886                            session = openSession();
17887    
17888                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17889    
17890                            if (getDB().isSupportsInlineDistinct()) {
17891                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17892                            }
17893                            else {
17894                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17895                            }
17896    
17897                            QueryPos qPos = QueryPos.getInstance(q);
17898    
17899                            qPos.add(groupId);
17900    
17901                            qPos.add(categoryId);
17902    
17903                            qPos.add(threadId);
17904    
17905                            qPos.add(status);
17906    
17907                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17908                    }
17909                    catch (Exception e) {
17910                            throw processException(e);
17911                    }
17912                    finally {
17913                            closeSession(session);
17914                    }
17915            }
17916    
17917            /**
17918             * 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;.
17919             *
17920             * @param messageId the primary key of the current message-boards message
17921             * @param groupId the group ID
17922             * @param categoryId the category ID
17923             * @param threadId the thread ID
17924             * @param status the status
17925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17926             * @return the previous, current, and next message-boards message
17927             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17928             */
17929            @Override
17930            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17931                    long groupId, long categoryId, long threadId, int status,
17932                    OrderByComparator<MBMessage> orderByComparator)
17933                    throws NoSuchMessageException {
17934                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17935                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17936                                    threadId, status, orderByComparator);
17937                    }
17938    
17939                    MBMessage mbMessage = findByPrimaryKey(messageId);
17940    
17941                    Session session = null;
17942    
17943                    try {
17944                            session = openSession();
17945    
17946                            MBMessage[] array = new MBMessageImpl[3];
17947    
17948                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17949                                            groupId, categoryId, threadId, status, orderByComparator,
17950                                            true);
17951    
17952                            array[1] = mbMessage;
17953    
17954                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17955                                            groupId, categoryId, threadId, status, orderByComparator,
17956                                            false);
17957    
17958                            return array;
17959                    }
17960                    catch (Exception e) {
17961                            throw processException(e);
17962                    }
17963                    finally {
17964                            closeSession(session);
17965                    }
17966            }
17967    
17968            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17969                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17970                    int status, OrderByComparator<MBMessage> orderByComparator,
17971                    boolean previous) {
17972                    StringBundler query = null;
17973    
17974                    if (orderByComparator != null) {
17975                            query = new StringBundler(8 +
17976                                            (orderByComparator.getOrderByConditionFields().length * 3) +
17977                                            (orderByComparator.getOrderByFields().length * 3));
17978                    }
17979                    else {
17980                            query = new StringBundler(7);
17981                    }
17982    
17983                    if (getDB().isSupportsInlineDistinct()) {
17984                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17985                    }
17986                    else {
17987                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17988                    }
17989    
17990                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17991    
17992                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17993    
17994                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17995    
17996                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17997    
17998                    if (!getDB().isSupportsInlineDistinct()) {
17999                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
18000                    }
18001    
18002                    if (orderByComparator != null) {
18003                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18004    
18005                            if (orderByConditionFields.length > 0) {
18006                                    query.append(WHERE_AND);
18007                            }
18008    
18009                            for (int i = 0; i < orderByConditionFields.length; i++) {
18010                                    if (getDB().isSupportsInlineDistinct()) {
18011                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18012                                    }
18013                                    else {
18014                                            query.append(_ORDER_BY_ENTITY_TABLE);
18015                                    }
18016    
18017                                    query.append(orderByConditionFields[i]);
18018    
18019                                    if ((i + 1) < orderByConditionFields.length) {
18020                                            if (orderByComparator.isAscending() ^ previous) {
18021                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18022                                            }
18023                                            else {
18024                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18025                                            }
18026                                    }
18027                                    else {
18028                                            if (orderByComparator.isAscending() ^ previous) {
18029                                                    query.append(WHERE_GREATER_THAN);
18030                                            }
18031                                            else {
18032                                                    query.append(WHERE_LESSER_THAN);
18033                                            }
18034                                    }
18035                            }
18036    
18037                            query.append(ORDER_BY_CLAUSE);
18038    
18039                            String[] orderByFields = orderByComparator.getOrderByFields();
18040    
18041                            for (int i = 0; i < orderByFields.length; i++) {
18042                                    if (getDB().isSupportsInlineDistinct()) {
18043                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18044                                    }
18045                                    else {
18046                                            query.append(_ORDER_BY_ENTITY_TABLE);
18047                                    }
18048    
18049                                    query.append(orderByFields[i]);
18050    
18051                                    if ((i + 1) < orderByFields.length) {
18052                                            if (orderByComparator.isAscending() ^ previous) {
18053                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18054                                            }
18055                                            else {
18056                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18057                                            }
18058                                    }
18059                                    else {
18060                                            if (orderByComparator.isAscending() ^ previous) {
18061                                                    query.append(ORDER_BY_ASC);
18062                                            }
18063                                            else {
18064                                                    query.append(ORDER_BY_DESC);
18065                                            }
18066                                    }
18067                            }
18068                    }
18069                    else {
18070                            if (getDB().isSupportsInlineDistinct()) {
18071                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18072                            }
18073                            else {
18074                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18075                            }
18076                    }
18077    
18078                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18079                                    MBMessage.class.getName(),
18080                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18081    
18082                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
18083    
18084                    q.setFirstResult(0);
18085                    q.setMaxResults(2);
18086    
18087                    if (getDB().isSupportsInlineDistinct()) {
18088                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18089                    }
18090                    else {
18091                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18092                    }
18093    
18094                    QueryPos qPos = QueryPos.getInstance(q);
18095    
18096                    qPos.add(groupId);
18097    
18098                    qPos.add(categoryId);
18099    
18100                    qPos.add(threadId);
18101    
18102                    qPos.add(status);
18103    
18104                    if (orderByComparator != null) {
18105                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18106    
18107                            for (Object value : values) {
18108                                    qPos.add(value);
18109                            }
18110                    }
18111    
18112                    List<MBMessage> list = q.list();
18113    
18114                    if (list.size() == 2) {
18115                            return list.get(1);
18116                    }
18117                    else {
18118                            return null;
18119                    }
18120            }
18121    
18122            /**
18123             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
18124             *
18125             * @param groupId the group ID
18126             * @param categoryId the category ID
18127             * @param threadId the thread ID
18128             * @param status the status
18129             */
18130            @Override
18131            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
18132                    int status) {
18133                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
18134                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18135                            remove(mbMessage);
18136                    }
18137            }
18138    
18139            /**
18140             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18141             *
18142             * @param groupId the group ID
18143             * @param categoryId the category ID
18144             * @param threadId the thread ID
18145             * @param status the status
18146             * @return the number of matching message-boards messages
18147             */
18148            @Override
18149            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18150                    int status) {
18151                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
18152    
18153                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18154    
18155                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18156    
18157                    if (count == null) {
18158                            StringBundler query = new StringBundler(5);
18159    
18160                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18161    
18162                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18163    
18164                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18165    
18166                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18167    
18168                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18169    
18170                            String sql = query.toString();
18171    
18172                            Session session = null;
18173    
18174                            try {
18175                                    session = openSession();
18176    
18177                                    Query q = session.createQuery(sql);
18178    
18179                                    QueryPos qPos = QueryPos.getInstance(q);
18180    
18181                                    qPos.add(groupId);
18182    
18183                                    qPos.add(categoryId);
18184    
18185                                    qPos.add(threadId);
18186    
18187                                    qPos.add(status);
18188    
18189                                    count = (Long)q.uniqueResult();
18190    
18191                                    finderCache.putResult(finderPath, finderArgs, count);
18192                            }
18193                            catch (Exception e) {
18194                                    finderCache.removeResult(finderPath, finderArgs);
18195    
18196                                    throw processException(e);
18197                            }
18198                            finally {
18199                                    closeSession(session);
18200                            }
18201                    }
18202    
18203                    return count.intValue();
18204            }
18205    
18206            /**
18207             * 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;.
18208             *
18209             * @param groupId the group ID
18210             * @param categoryId the category ID
18211             * @param threadId the thread ID
18212             * @param status the status
18213             * @return the number of matching message-boards messages that the user has permission to view
18214             */
18215            @Override
18216            public int filterCountByG_C_T_S(long groupId, long categoryId,
18217                    long threadId, int status) {
18218                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18219                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18220                    }
18221    
18222                    StringBundler query = new StringBundler(5);
18223    
18224                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18225    
18226                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18227    
18228                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18229    
18230                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18231    
18232                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18233    
18234                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18235                                    MBMessage.class.getName(),
18236                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18237    
18238                    Session session = null;
18239    
18240                    try {
18241                            session = openSession();
18242    
18243                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
18244    
18245                            q.addScalar(COUNT_COLUMN_NAME,
18246                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18247    
18248                            QueryPos qPos = QueryPos.getInstance(q);
18249    
18250                            qPos.add(groupId);
18251    
18252                            qPos.add(categoryId);
18253    
18254                            qPos.add(threadId);
18255    
18256                            qPos.add(status);
18257    
18258                            Long count = (Long)q.uniqueResult();
18259    
18260                            return count.intValue();
18261                    }
18262                    catch (Exception e) {
18263                            throw processException(e);
18264                    }
18265                    finally {
18266                            closeSession(session);
18267                    }
18268            }
18269    
18270            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18271            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18272            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18273            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18274            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18275                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18276                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
18277                            new String[] {
18278                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18279                                    Integer.class.getName(),
18280                                    
18281                            Integer.class.getName(), Integer.class.getName(),
18282                                    OrderByComparator.class.getName()
18283                            });
18284            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
18285                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18286                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18287                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
18288                            new String[] {
18289                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18290                                    Integer.class.getName()
18291                            },
18292                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
18293                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
18294                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
18295                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18296                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18297            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18298                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18299                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
18300                            new String[] {
18301                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18302                                    Integer.class.getName()
18303                            });
18304    
18305            /**
18306             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18307             *
18308             * @param userId the user ID
18309             * @param classNameId the class name ID
18310             * @param classPK the class p k
18311             * @param status the status
18312             * @return the matching message-boards messages
18313             */
18314            @Override
18315            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18316                    long classPK, int status) {
18317                    return findByU_C_C_S(userId, classNameId, classPK, status,
18318                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18319            }
18320    
18321            /**
18322             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18323             *
18324             * <p>
18325             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18326             * </p>
18327             *
18328             * @param userId the user ID
18329             * @param classNameId the class name ID
18330             * @param classPK the class p k
18331             * @param status the status
18332             * @param start the lower bound of the range of message-boards messages
18333             * @param end the upper bound of the range of message-boards messages (not inclusive)
18334             * @return the range of matching message-boards messages
18335             */
18336            @Override
18337            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18338                    long classPK, int status, int start, int end) {
18339                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18340                            null);
18341            }
18342    
18343            /**
18344             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18345             *
18346             * <p>
18347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18348             * </p>
18349             *
18350             * @param userId the user ID
18351             * @param classNameId the class name ID
18352             * @param classPK the class p k
18353             * @param status the status
18354             * @param start the lower bound of the range of message-boards messages
18355             * @param end the upper bound of the range of message-boards messages (not inclusive)
18356             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18357             * @return the ordered range of matching message-boards messages
18358             */
18359            @Override
18360            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18361                    long classPK, int status, int start, int end,
18362                    OrderByComparator<MBMessage> orderByComparator) {
18363                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18364                            orderByComparator, true);
18365            }
18366    
18367            /**
18368             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18369             *
18370             * <p>
18371             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18372             * </p>
18373             *
18374             * @param userId the user ID
18375             * @param classNameId the class name ID
18376             * @param classPK the class p k
18377             * @param status the status
18378             * @param start the lower bound of the range of message-boards messages
18379             * @param end the upper bound of the range of message-boards messages (not inclusive)
18380             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18381             * @param retrieveFromCache whether to retrieve from the finder cache
18382             * @return the ordered range of matching message-boards messages
18383             */
18384            @Override
18385            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18386                    long classPK, int status, int start, int end,
18387                    OrderByComparator<MBMessage> orderByComparator,
18388                    boolean retrieveFromCache) {
18389                    boolean pagination = true;
18390                    FinderPath finderPath = null;
18391                    Object[] finderArgs = null;
18392    
18393                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18394                                    (orderByComparator == null)) {
18395                            pagination = false;
18396                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18397                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18398                    }
18399                    else {
18400                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18401                            finderArgs = new Object[] {
18402                                            userId, classNameId, classPK, status,
18403                                            
18404                                            start, end, orderByComparator
18405                                    };
18406                    }
18407    
18408                    List<MBMessage> list = null;
18409    
18410                    if (retrieveFromCache) {
18411                            list = (List<MBMessage>)finderCache.getResult(finderPath,
18412                                            finderArgs, this);
18413    
18414                            if ((list != null) && !list.isEmpty()) {
18415                                    for (MBMessage mbMessage : list) {
18416                                            if ((userId != mbMessage.getUserId()) ||
18417                                                            (classNameId != mbMessage.getClassNameId()) ||
18418                                                            (classPK != mbMessage.getClassPK()) ||
18419                                                            (status != mbMessage.getStatus())) {
18420                                                    list = null;
18421    
18422                                                    break;
18423                                            }
18424                                    }
18425                            }
18426                    }
18427    
18428                    if (list == null) {
18429                            StringBundler query = null;
18430    
18431                            if (orderByComparator != null) {
18432                                    query = new StringBundler(6 +
18433                                                    (orderByComparator.getOrderByFields().length * 2));
18434                            }
18435                            else {
18436                                    query = new StringBundler(6);
18437                            }
18438    
18439                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18440    
18441                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18442    
18443                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18444    
18445                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18446    
18447                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18448    
18449                            if (orderByComparator != null) {
18450                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18451                                            orderByComparator);
18452                            }
18453                            else
18454                             if (pagination) {
18455                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18456                            }
18457    
18458                            String sql = query.toString();
18459    
18460                            Session session = null;
18461    
18462                            try {
18463                                    session = openSession();
18464    
18465                                    Query q = session.createQuery(sql);
18466    
18467                                    QueryPos qPos = QueryPos.getInstance(q);
18468    
18469                                    qPos.add(userId);
18470    
18471                                    qPos.add(classNameId);
18472    
18473                                    qPos.add(classPK);
18474    
18475                                    qPos.add(status);
18476    
18477                                    if (!pagination) {
18478                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18479                                                            start, end, false);
18480    
18481                                            Collections.sort(list);
18482    
18483                                            list = Collections.unmodifiableList(list);
18484                                    }
18485                                    else {
18486                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18487                                                            start, end);
18488                                    }
18489    
18490                                    cacheResult(list);
18491    
18492                                    finderCache.putResult(finderPath, finderArgs, list);
18493                            }
18494                            catch (Exception e) {
18495                                    finderCache.removeResult(finderPath, finderArgs);
18496    
18497                                    throw processException(e);
18498                            }
18499                            finally {
18500                                    closeSession(session);
18501                            }
18502                    }
18503    
18504                    return list;
18505            }
18506    
18507            /**
18508             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18509             *
18510             * @param userId the user ID
18511             * @param classNameId the class name ID
18512             * @param classPK the class p k
18513             * @param status the status
18514             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18515             * @return the first matching message-boards message
18516             * @throws NoSuchMessageException if a matching message-boards message could not be found
18517             */
18518            @Override
18519            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18520                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18521                    throws NoSuchMessageException {
18522                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18523                                    classPK, status, orderByComparator);
18524    
18525                    if (mbMessage != null) {
18526                            return mbMessage;
18527                    }
18528    
18529                    StringBundler msg = new StringBundler(10);
18530    
18531                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18532    
18533                    msg.append("userId=");
18534                    msg.append(userId);
18535    
18536                    msg.append(", classNameId=");
18537                    msg.append(classNameId);
18538    
18539                    msg.append(", classPK=");
18540                    msg.append(classPK);
18541    
18542                    msg.append(", status=");
18543                    msg.append(status);
18544    
18545                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18546    
18547                    throw new NoSuchMessageException(msg.toString());
18548            }
18549    
18550            /**
18551             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18552             *
18553             * @param userId the user ID
18554             * @param classNameId the class name ID
18555             * @param classPK the class p k
18556             * @param status the status
18557             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18558             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18559             */
18560            @Override
18561            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18562                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18563                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18564                                    status, 0, 1, orderByComparator);
18565    
18566                    if (!list.isEmpty()) {
18567                            return list.get(0);
18568                    }
18569    
18570                    return null;
18571            }
18572    
18573            /**
18574             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18575             *
18576             * @param userId the user ID
18577             * @param classNameId the class name ID
18578             * @param classPK the class p k
18579             * @param status the status
18580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18581             * @return the last matching message-boards message
18582             * @throws NoSuchMessageException if a matching message-boards message could not be found
18583             */
18584            @Override
18585            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18586                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18587                    throws NoSuchMessageException {
18588                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18589                                    status, orderByComparator);
18590    
18591                    if (mbMessage != null) {
18592                            return mbMessage;
18593                    }
18594    
18595                    StringBundler msg = new StringBundler(10);
18596    
18597                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18598    
18599                    msg.append("userId=");
18600                    msg.append(userId);
18601    
18602                    msg.append(", classNameId=");
18603                    msg.append(classNameId);
18604    
18605                    msg.append(", classPK=");
18606                    msg.append(classPK);
18607    
18608                    msg.append(", status=");
18609                    msg.append(status);
18610    
18611                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18612    
18613                    throw new NoSuchMessageException(msg.toString());
18614            }
18615    
18616            /**
18617             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18618             *
18619             * @param userId the user ID
18620             * @param classNameId the class name ID
18621             * @param classPK the class p k
18622             * @param status the status
18623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18624             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18625             */
18626            @Override
18627            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18628                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18629                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18630    
18631                    if (count == 0) {
18632                            return null;
18633                    }
18634    
18635                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18636                                    status, count - 1, count, orderByComparator);
18637    
18638                    if (!list.isEmpty()) {
18639                            return list.get(0);
18640                    }
18641    
18642                    return null;
18643            }
18644    
18645            /**
18646             * 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;.
18647             *
18648             * @param messageId the primary key of the current message-boards message
18649             * @param userId the user ID
18650             * @param classNameId the class name ID
18651             * @param classPK the class p k
18652             * @param status the status
18653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18654             * @return the previous, current, and next message-boards message
18655             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18656             */
18657            @Override
18658            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18659                    long classNameId, long classPK, int status,
18660                    OrderByComparator<MBMessage> orderByComparator)
18661                    throws NoSuchMessageException {
18662                    MBMessage mbMessage = findByPrimaryKey(messageId);
18663    
18664                    Session session = null;
18665    
18666                    try {
18667                            session = openSession();
18668    
18669                            MBMessage[] array = new MBMessageImpl[3];
18670    
18671                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18672                                            classNameId, classPK, status, orderByComparator, true);
18673    
18674                            array[1] = mbMessage;
18675    
18676                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18677                                            classNameId, classPK, status, orderByComparator, false);
18678    
18679                            return array;
18680                    }
18681                    catch (Exception e) {
18682                            throw processException(e);
18683                    }
18684                    finally {
18685                            closeSession(session);
18686                    }
18687            }
18688    
18689            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18690                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18691                    int status, OrderByComparator<MBMessage> orderByComparator,
18692                    boolean previous) {
18693                    StringBundler query = null;
18694    
18695                    if (orderByComparator != null) {
18696                            query = new StringBundler(7 +
18697                                            (orderByComparator.getOrderByConditionFields().length * 3) +
18698                                            (orderByComparator.getOrderByFields().length * 3));
18699                    }
18700                    else {
18701                            query = new StringBundler(6);
18702                    }
18703    
18704                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18705    
18706                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18707    
18708                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18709    
18710                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18711    
18712                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18713    
18714                    if (orderByComparator != null) {
18715                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18716    
18717                            if (orderByConditionFields.length > 0) {
18718                                    query.append(WHERE_AND);
18719                            }
18720    
18721                            for (int i = 0; i < orderByConditionFields.length; i++) {
18722                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18723                                    query.append(orderByConditionFields[i]);
18724    
18725                                    if ((i + 1) < orderByConditionFields.length) {
18726                                            if (orderByComparator.isAscending() ^ previous) {
18727                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18728                                            }
18729                                            else {
18730                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18731                                            }
18732                                    }
18733                                    else {
18734                                            if (orderByComparator.isAscending() ^ previous) {
18735                                                    query.append(WHERE_GREATER_THAN);
18736                                            }
18737                                            else {
18738                                                    query.append(WHERE_LESSER_THAN);
18739                                            }
18740                                    }
18741                            }
18742    
18743                            query.append(ORDER_BY_CLAUSE);
18744    
18745                            String[] orderByFields = orderByComparator.getOrderByFields();
18746    
18747                            for (int i = 0; i < orderByFields.length; i++) {
18748                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18749                                    query.append(orderByFields[i]);
18750    
18751                                    if ((i + 1) < orderByFields.length) {
18752                                            if (orderByComparator.isAscending() ^ previous) {
18753                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18754                                            }
18755                                            else {
18756                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18757                                            }
18758                                    }
18759                                    else {
18760                                            if (orderByComparator.isAscending() ^ previous) {
18761                                                    query.append(ORDER_BY_ASC);
18762                                            }
18763                                            else {
18764                                                    query.append(ORDER_BY_DESC);
18765                                            }
18766                                    }
18767                            }
18768                    }
18769                    else {
18770                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18771                    }
18772    
18773                    String sql = query.toString();
18774    
18775                    Query q = session.createQuery(sql);
18776    
18777                    q.setFirstResult(0);
18778                    q.setMaxResults(2);
18779    
18780                    QueryPos qPos = QueryPos.getInstance(q);
18781    
18782                    qPos.add(userId);
18783    
18784                    qPos.add(classNameId);
18785    
18786                    qPos.add(classPK);
18787    
18788                    qPos.add(status);
18789    
18790                    if (orderByComparator != null) {
18791                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18792    
18793                            for (Object value : values) {
18794                                    qPos.add(value);
18795                            }
18796                    }
18797    
18798                    List<MBMessage> list = q.list();
18799    
18800                    if (list.size() == 2) {
18801                            return list.get(1);
18802                    }
18803                    else {
18804                            return null;
18805                    }
18806            }
18807    
18808            /**
18809             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18810             *
18811             * @param userId the user ID
18812             * @param classNameId the class name ID
18813             * @param classPK the class p k
18814             * @param status the status
18815             */
18816            @Override
18817            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18818                    int status) {
18819                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18820                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18821                            remove(mbMessage);
18822                    }
18823            }
18824    
18825            /**
18826             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18827             *
18828             * @param userId the user ID
18829             * @param classNameId the class name ID
18830             * @param classPK the class p k
18831             * @param status the status
18832             * @return the number of matching message-boards messages
18833             */
18834            @Override
18835            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18836                    int status) {
18837                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18838    
18839                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18840    
18841                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18842    
18843                    if (count == null) {
18844                            StringBundler query = new StringBundler(5);
18845    
18846                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18847    
18848                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18849    
18850                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18851    
18852                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18853    
18854                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18855    
18856                            String sql = query.toString();
18857    
18858                            Session session = null;
18859    
18860                            try {
18861                                    session = openSession();
18862    
18863                                    Query q = session.createQuery(sql);
18864    
18865                                    QueryPos qPos = QueryPos.getInstance(q);
18866    
18867                                    qPos.add(userId);
18868    
18869                                    qPos.add(classNameId);
18870    
18871                                    qPos.add(classPK);
18872    
18873                                    qPos.add(status);
18874    
18875                                    count = (Long)q.uniqueResult();
18876    
18877                                    finderCache.putResult(finderPath, finderArgs, count);
18878                            }
18879                            catch (Exception e) {
18880                                    finderCache.removeResult(finderPath, finderArgs);
18881    
18882                                    throw processException(e);
18883                            }
18884                            finally {
18885                                    closeSession(session);
18886                            }
18887                    }
18888    
18889                    return count.intValue();
18890            }
18891    
18892            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18893            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18894            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18895            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18896    
18897            public MBMessagePersistenceImpl() {
18898                    setModelClass(MBMessage.class);
18899            }
18900    
18901            /**
18902             * Caches the message-boards message in the entity cache if it is enabled.
18903             *
18904             * @param mbMessage the message-boards message
18905             */
18906            @Override
18907            public void cacheResult(MBMessage mbMessage) {
18908                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18909                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18910    
18911                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18912                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18913                            mbMessage);
18914    
18915                    mbMessage.resetOriginalValues();
18916            }
18917    
18918            /**
18919             * Caches the message-boards messages in the entity cache if it is enabled.
18920             *
18921             * @param mbMessages the message-boards messages
18922             */
18923            @Override
18924            public void cacheResult(List<MBMessage> mbMessages) {
18925                    for (MBMessage mbMessage : mbMessages) {
18926                            if (entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18927                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18928                                    cacheResult(mbMessage);
18929                            }
18930                            else {
18931                                    mbMessage.resetOriginalValues();
18932                            }
18933                    }
18934            }
18935    
18936            /**
18937             * Clears the cache for all message-boards messages.
18938             *
18939             * <p>
18940             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18941             * </p>
18942             */
18943            @Override
18944            public void clearCache() {
18945                    entityCache.clearCache(MBMessageImpl.class);
18946    
18947                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
18948                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18949                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18950            }
18951    
18952            /**
18953             * Clears the cache for the message-boards message.
18954             *
18955             * <p>
18956             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18957             * </p>
18958             */
18959            @Override
18960            public void clearCache(MBMessage mbMessage) {
18961                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18962                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18963    
18964                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18965                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18966    
18967                    clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18968            }
18969    
18970            @Override
18971            public void clearCache(List<MBMessage> mbMessages) {
18972                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18973                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18974    
18975                    for (MBMessage mbMessage : mbMessages) {
18976                            entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18977                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18978    
18979                            clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18980                    }
18981            }
18982    
18983            protected void cacheUniqueFindersCache(
18984                    MBMessageModelImpl mbMessageModelImpl, boolean isNew) {
18985                    if (isNew) {
18986                            Object[] args = new Object[] {
18987                                            mbMessageModelImpl.getUuid(),
18988                                            mbMessageModelImpl.getGroupId()
18989                                    };
18990    
18991                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18992                                    Long.valueOf(1));
18993                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18994                                    mbMessageModelImpl);
18995                    }
18996                    else {
18997                            if ((mbMessageModelImpl.getColumnBitmask() &
18998                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18999                                    Object[] args = new Object[] {
19000                                                    mbMessageModelImpl.getUuid(),
19001                                                    mbMessageModelImpl.getGroupId()
19002                                            };
19003    
19004                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
19005                                            Long.valueOf(1));
19006                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
19007                                            mbMessageModelImpl);
19008                            }
19009                    }
19010            }
19011    
19012            protected void clearUniqueFindersCache(
19013                    MBMessageModelImpl mbMessageModelImpl) {
19014                    Object[] args = new Object[] {
19015                                    mbMessageModelImpl.getUuid(), mbMessageModelImpl.getGroupId()
19016                            };
19017    
19018                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19019                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19020    
19021                    if ((mbMessageModelImpl.getColumnBitmask() &
19022                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
19023                            args = new Object[] {
19024                                            mbMessageModelImpl.getOriginalUuid(),
19025                                            mbMessageModelImpl.getOriginalGroupId()
19026                                    };
19027    
19028                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19029                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19030                    }
19031            }
19032    
19033            /**
19034             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
19035             *
19036             * @param messageId the primary key for the new message-boards message
19037             * @return the new message-boards message
19038             */
19039            @Override
19040            public MBMessage create(long messageId) {
19041                    MBMessage mbMessage = new MBMessageImpl();
19042    
19043                    mbMessage.setNew(true);
19044                    mbMessage.setPrimaryKey(messageId);
19045    
19046                    String uuid = PortalUUIDUtil.generate();
19047    
19048                    mbMessage.setUuid(uuid);
19049    
19050                    mbMessage.setCompanyId(companyProvider.getCompanyId());
19051    
19052                    return mbMessage;
19053            }
19054    
19055            /**
19056             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19057             *
19058             * @param messageId the primary key of the message-boards message
19059             * @return the message-boards message that was removed
19060             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19061             */
19062            @Override
19063            public MBMessage remove(long messageId) throws NoSuchMessageException {
19064                    return remove((Serializable)messageId);
19065            }
19066    
19067            /**
19068             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19069             *
19070             * @param primaryKey the primary key of the message-boards message
19071             * @return the message-boards message that was removed
19072             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19073             */
19074            @Override
19075            public MBMessage remove(Serializable primaryKey)
19076                    throws NoSuchMessageException {
19077                    Session session = null;
19078    
19079                    try {
19080                            session = openSession();
19081    
19082                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19083                                            primaryKey);
19084    
19085                            if (mbMessage == null) {
19086                                    if (_log.isDebugEnabled()) {
19087                                            _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19088                                    }
19089    
19090                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19091                                            primaryKey);
19092                            }
19093    
19094                            return remove(mbMessage);
19095                    }
19096                    catch (NoSuchMessageException nsee) {
19097                            throw nsee;
19098                    }
19099                    catch (Exception e) {
19100                            throw processException(e);
19101                    }
19102                    finally {
19103                            closeSession(session);
19104                    }
19105            }
19106    
19107            @Override
19108            protected MBMessage removeImpl(MBMessage mbMessage) {
19109                    mbMessage = toUnwrappedModel(mbMessage);
19110    
19111                    Session session = null;
19112    
19113                    try {
19114                            session = openSession();
19115    
19116                            if (!session.contains(mbMessage)) {
19117                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19118                                                    mbMessage.getPrimaryKeyObj());
19119                            }
19120    
19121                            if (mbMessage != null) {
19122                                    session.delete(mbMessage);
19123                            }
19124                    }
19125                    catch (Exception e) {
19126                            throw processException(e);
19127                    }
19128                    finally {
19129                            closeSession(session);
19130                    }
19131    
19132                    if (mbMessage != null) {
19133                            clearCache(mbMessage);
19134                    }
19135    
19136                    return mbMessage;
19137            }
19138    
19139            @Override
19140            public MBMessage updateImpl(MBMessage mbMessage) {
19141                    mbMessage = toUnwrappedModel(mbMessage);
19142    
19143                    boolean isNew = mbMessage.isNew();
19144    
19145                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19146    
19147                    if (Validator.isNull(mbMessage.getUuid())) {
19148                            String uuid = PortalUUIDUtil.generate();
19149    
19150                            mbMessage.setUuid(uuid);
19151                    }
19152    
19153                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
19154    
19155                    Date now = new Date();
19156    
19157                    if (isNew && (mbMessage.getCreateDate() == null)) {
19158                            if (serviceContext == null) {
19159                                    mbMessage.setCreateDate(now);
19160                            }
19161                            else {
19162                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
19163                            }
19164                    }
19165    
19166                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
19167                            if (serviceContext == null) {
19168                                    mbMessage.setModifiedDate(now);
19169                            }
19170                            else {
19171                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
19172                            }
19173                    }
19174    
19175                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
19176    
19177                    if (userId > 0) {
19178                            long companyId = mbMessage.getCompanyId();
19179    
19180                            long groupId = mbMessage.getGroupId();
19181    
19182                            long messageId = 0;
19183    
19184                            if (!isNew) {
19185                                    messageId = mbMessage.getPrimaryKey();
19186                            }
19187    
19188                            try {
19189                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
19190                                                    userId, MBMessage.class.getName(), messageId,
19191                                                    ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
19192                                                    mbMessage.getSubject(), null));
19193                            }
19194                            catch (SanitizerException se) {
19195                                    throw new SystemException(se);
19196                            }
19197                    }
19198    
19199                    Session session = null;
19200    
19201                    try {
19202                            session = openSession();
19203    
19204                            if (mbMessage.isNew()) {
19205                                    session.save(mbMessage);
19206    
19207                                    mbMessage.setNew(false);
19208                            }
19209                            else {
19210                                    mbMessage = (MBMessage)session.merge(mbMessage);
19211                            }
19212                    }
19213                    catch (Exception e) {
19214                            throw processException(e);
19215                    }
19216                    finally {
19217                            closeSession(session);
19218                    }
19219    
19220                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19221    
19222                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
19223                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19224                    }
19225    
19226                    else {
19227                            if ((mbMessageModelImpl.getColumnBitmask() &
19228                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
19229                                    Object[] args = new Object[] {
19230                                                    mbMessageModelImpl.getOriginalUuid()
19231                                            };
19232    
19233                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19234                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19235                                            args);
19236    
19237                                    args = new Object[] { mbMessageModelImpl.getUuid() };
19238    
19239                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19240                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19241                                            args);
19242                            }
19243    
19244                            if ((mbMessageModelImpl.getColumnBitmask() &
19245                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
19246                                    Object[] args = new Object[] {
19247                                                    mbMessageModelImpl.getOriginalUuid(),
19248                                                    mbMessageModelImpl.getOriginalCompanyId()
19249                                            };
19250    
19251                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19252                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19253                                            args);
19254    
19255                                    args = new Object[] {
19256                                                    mbMessageModelImpl.getUuid(),
19257                                                    mbMessageModelImpl.getCompanyId()
19258                                            };
19259    
19260                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19261                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19262                                            args);
19263                            }
19264    
19265                            if ((mbMessageModelImpl.getColumnBitmask() &
19266                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
19267                                    Object[] args = new Object[] {
19268                                                    mbMessageModelImpl.getOriginalGroupId()
19269                                            };
19270    
19271                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19272                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19273                                            args);
19274    
19275                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
19276    
19277                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19278                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19279                                            args);
19280                            }
19281    
19282                            if ((mbMessageModelImpl.getColumnBitmask() &
19283                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
19284                                    Object[] args = new Object[] {
19285                                                    mbMessageModelImpl.getOriginalCompanyId()
19286                                            };
19287    
19288                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19289                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19290                                            args);
19291    
19292                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
19293    
19294                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19295                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19296                                            args);
19297                            }
19298    
19299                            if ((mbMessageModelImpl.getColumnBitmask() &
19300                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
19301                                    Object[] args = new Object[] {
19302                                                    mbMessageModelImpl.getOriginalUserId()
19303                                            };
19304    
19305                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19306                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19307                                            args);
19308    
19309                                    args = new Object[] { mbMessageModelImpl.getUserId() };
19310    
19311                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19312                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19313                                            args);
19314                            }
19315    
19316                            if ((mbMessageModelImpl.getColumnBitmask() &
19317                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
19318                                    Object[] args = new Object[] {
19319                                                    mbMessageModelImpl.getOriginalThreadId()
19320                                            };
19321    
19322                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19323                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19324                                            args);
19325    
19326                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19327    
19328                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19329                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19330                                            args);
19331                            }
19332    
19333                            if ((mbMessageModelImpl.getColumnBitmask() &
19334                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
19335                                    Object[] args = new Object[] {
19336                                                    mbMessageModelImpl.getOriginalThreadId()
19337                                            };
19338    
19339                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19340                                            args);
19341                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19342                                            args);
19343    
19344                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19345    
19346                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19347                                            args);
19348                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19349                                            args);
19350                            }
19351    
19352                            if ((mbMessageModelImpl.getColumnBitmask() &
19353                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19354                                    Object[] args = new Object[] {
19355                                                    mbMessageModelImpl.getOriginalGroupId(),
19356                                                    mbMessageModelImpl.getOriginalUserId()
19357                                            };
19358    
19359                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19360                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19361                                            args);
19362    
19363                                    args = new Object[] {
19364                                                    mbMessageModelImpl.getGroupId(),
19365                                                    mbMessageModelImpl.getUserId()
19366                                            };
19367    
19368                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19369                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19370                                            args);
19371                            }
19372    
19373                            if ((mbMessageModelImpl.getColumnBitmask() &
19374                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19375                                    Object[] args = new Object[] {
19376                                                    mbMessageModelImpl.getOriginalGroupId(),
19377                                                    mbMessageModelImpl.getOriginalCategoryId()
19378                                            };
19379    
19380                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19381                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19382                                            args);
19383    
19384                                    args = new Object[] {
19385                                                    mbMessageModelImpl.getGroupId(),
19386                                                    mbMessageModelImpl.getCategoryId()
19387                                            };
19388    
19389                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19390                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19391                                            args);
19392                            }
19393    
19394                            if ((mbMessageModelImpl.getColumnBitmask() &
19395                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19396                                    Object[] args = new Object[] {
19397                                                    mbMessageModelImpl.getOriginalGroupId(),
19398                                                    mbMessageModelImpl.getOriginalStatus()
19399                                            };
19400    
19401                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19402                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19403                                            args);
19404    
19405                                    args = new Object[] {
19406                                                    mbMessageModelImpl.getGroupId(),
19407                                                    mbMessageModelImpl.getStatus()
19408                                            };
19409    
19410                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19411                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19412                                            args);
19413                            }
19414    
19415                            if ((mbMessageModelImpl.getColumnBitmask() &
19416                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19417                                    Object[] args = new Object[] {
19418                                                    mbMessageModelImpl.getOriginalCompanyId(),
19419                                                    mbMessageModelImpl.getOriginalStatus()
19420                                            };
19421    
19422                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19423                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19424                                            args);
19425    
19426                                    args = new Object[] {
19427                                                    mbMessageModelImpl.getCompanyId(),
19428                                                    mbMessageModelImpl.getStatus()
19429                                            };
19430    
19431                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19432                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19433                                            args);
19434                            }
19435    
19436                            if ((mbMessageModelImpl.getColumnBitmask() &
19437                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19438                                    Object[] args = new Object[] {
19439                                                    mbMessageModelImpl.getOriginalUserId(),
19440                                                    mbMessageModelImpl.getOriginalClassNameId()
19441                                            };
19442    
19443                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19444                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19445                                            args);
19446    
19447                                    args = new Object[] {
19448                                                    mbMessageModelImpl.getUserId(),
19449                                                    mbMessageModelImpl.getClassNameId()
19450                                            };
19451    
19452                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19453                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19454                                            args);
19455                            }
19456    
19457                            if ((mbMessageModelImpl.getColumnBitmask() &
19458                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19459                                    Object[] args = new Object[] {
19460                                                    mbMessageModelImpl.getOriginalClassNameId(),
19461                                                    mbMessageModelImpl.getOriginalClassPK()
19462                                            };
19463    
19464                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19465                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19466                                            args);
19467    
19468                                    args = new Object[] {
19469                                                    mbMessageModelImpl.getClassNameId(),
19470                                                    mbMessageModelImpl.getClassPK()
19471                                            };
19472    
19473                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19474                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19475                                            args);
19476                            }
19477    
19478                            if ((mbMessageModelImpl.getColumnBitmask() &
19479                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19480                                    Object[] args = new Object[] {
19481                                                    mbMessageModelImpl.getOriginalThreadId(),
19482                                                    mbMessageModelImpl.getOriginalParentMessageId()
19483                                            };
19484    
19485                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19486                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19487                                            args);
19488    
19489                                    args = new Object[] {
19490                                                    mbMessageModelImpl.getThreadId(),
19491                                                    mbMessageModelImpl.getParentMessageId()
19492                                            };
19493    
19494                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19495                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19496                                            args);
19497                            }
19498    
19499                            if ((mbMessageModelImpl.getColumnBitmask() &
19500                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19501                                    Object[] args = new Object[] {
19502                                                    mbMessageModelImpl.getOriginalThreadId(),
19503                                                    mbMessageModelImpl.getOriginalAnswer()
19504                                            };
19505    
19506                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19507                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19508                                            args);
19509    
19510                                    args = new Object[] {
19511                                                    mbMessageModelImpl.getThreadId(),
19512                                                    mbMessageModelImpl.getAnswer()
19513                                            };
19514    
19515                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19516                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19517                                            args);
19518                            }
19519    
19520                            if ((mbMessageModelImpl.getColumnBitmask() &
19521                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19522                                    Object[] args = new Object[] {
19523                                                    mbMessageModelImpl.getOriginalThreadId(),
19524                                                    mbMessageModelImpl.getOriginalStatus()
19525                                            };
19526    
19527                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19528                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19529                                            args);
19530    
19531                                    args = new Object[] {
19532                                                    mbMessageModelImpl.getThreadId(),
19533                                                    mbMessageModelImpl.getStatus()
19534                                            };
19535    
19536                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19537                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19538                                            args);
19539                            }
19540    
19541                            if ((mbMessageModelImpl.getColumnBitmask() &
19542                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19543                                    Object[] args = new Object[] {
19544                                                    mbMessageModelImpl.getOriginalThreadId(),
19545                                                    mbMessageModelImpl.getOriginalStatus()
19546                                            };
19547    
19548                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19549                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19550                                            args);
19551    
19552                                    args = new Object[] {
19553                                                    mbMessageModelImpl.getThreadId(),
19554                                                    mbMessageModelImpl.getStatus()
19555                                            };
19556    
19557                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19558                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19559                                            args);
19560                            }
19561    
19562                            if ((mbMessageModelImpl.getColumnBitmask() &
19563                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19564                                    Object[] args = new Object[] {
19565                                                    mbMessageModelImpl.getOriginalGroupId(),
19566                                                    mbMessageModelImpl.getOriginalUserId(),
19567                                                    mbMessageModelImpl.getOriginalStatus()
19568                                            };
19569    
19570                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19571                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19572                                            args);
19573    
19574                                    args = new Object[] {
19575                                                    mbMessageModelImpl.getGroupId(),
19576                                                    mbMessageModelImpl.getUserId(),
19577                                                    mbMessageModelImpl.getStatus()
19578                                            };
19579    
19580                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19581                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19582                                            args);
19583                            }
19584    
19585                            if ((mbMessageModelImpl.getColumnBitmask() &
19586                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19587                                    Object[] args = new Object[] {
19588                                                    mbMessageModelImpl.getOriginalGroupId(),
19589                                                    mbMessageModelImpl.getOriginalCategoryId(),
19590                                                    mbMessageModelImpl.getOriginalThreadId()
19591                                            };
19592    
19593                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19594                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19595                                            args);
19596    
19597                                    args = new Object[] {
19598                                                    mbMessageModelImpl.getGroupId(),
19599                                                    mbMessageModelImpl.getCategoryId(),
19600                                                    mbMessageModelImpl.getThreadId()
19601                                            };
19602    
19603                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19604                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19605                                            args);
19606                            }
19607    
19608                            if ((mbMessageModelImpl.getColumnBitmask() &
19609                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19610                                    Object[] args = new Object[] {
19611                                                    mbMessageModelImpl.getOriginalGroupId(),
19612                                                    mbMessageModelImpl.getOriginalCategoryId(),
19613                                                    mbMessageModelImpl.getOriginalStatus()
19614                                            };
19615    
19616                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19617                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19618                                            args);
19619    
19620                                    args = new Object[] {
19621                                                    mbMessageModelImpl.getGroupId(),
19622                                                    mbMessageModelImpl.getCategoryId(),
19623                                                    mbMessageModelImpl.getStatus()
19624                                            };
19625    
19626                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19627                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19628                                            args);
19629                            }
19630    
19631                            if ((mbMessageModelImpl.getColumnBitmask() &
19632                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19633                                    Object[] args = new Object[] {
19634                                                    mbMessageModelImpl.getOriginalUserId(),
19635                                                    mbMessageModelImpl.getOriginalClassNameId(),
19636                                                    mbMessageModelImpl.getOriginalClassPK()
19637                                            };
19638    
19639                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19640                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19641                                            args);
19642    
19643                                    args = new Object[] {
19644                                                    mbMessageModelImpl.getUserId(),
19645                                                    mbMessageModelImpl.getClassNameId(),
19646                                                    mbMessageModelImpl.getClassPK()
19647                                            };
19648    
19649                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19650                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19651                                            args);
19652                            }
19653    
19654                            if ((mbMessageModelImpl.getColumnBitmask() &
19655                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19656                                    Object[] args = new Object[] {
19657                                                    mbMessageModelImpl.getOriginalUserId(),
19658                                                    mbMessageModelImpl.getOriginalClassNameId(),
19659                                                    mbMessageModelImpl.getOriginalStatus()
19660                                            };
19661    
19662                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19663                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19664                                            args);
19665    
19666                                    args = new Object[] {
19667                                                    mbMessageModelImpl.getUserId(),
19668                                                    mbMessageModelImpl.getClassNameId(),
19669                                                    mbMessageModelImpl.getStatus()
19670                                            };
19671    
19672                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19673                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19674                                            args);
19675                            }
19676    
19677                            if ((mbMessageModelImpl.getColumnBitmask() &
19678                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19679                                    Object[] args = new Object[] {
19680                                                    mbMessageModelImpl.getOriginalClassNameId(),
19681                                                    mbMessageModelImpl.getOriginalClassPK(),
19682                                                    mbMessageModelImpl.getOriginalStatus()
19683                                            };
19684    
19685                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19686                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19687                                            args);
19688    
19689                                    args = new Object[] {
19690                                                    mbMessageModelImpl.getClassNameId(),
19691                                                    mbMessageModelImpl.getClassPK(),
19692                                                    mbMessageModelImpl.getStatus()
19693                                            };
19694    
19695                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19696                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19697                                            args);
19698                            }
19699    
19700                            if ((mbMessageModelImpl.getColumnBitmask() &
19701                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19702                                    Object[] args = new Object[] {
19703                                                    mbMessageModelImpl.getOriginalGroupId(),
19704                                                    mbMessageModelImpl.getOriginalCategoryId(),
19705                                                    mbMessageModelImpl.getOriginalThreadId(),
19706                                                    mbMessageModelImpl.getOriginalAnswer()
19707                                            };
19708    
19709                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19710                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19711                                            args);
19712    
19713                                    args = new Object[] {
19714                                                    mbMessageModelImpl.getGroupId(),
19715                                                    mbMessageModelImpl.getCategoryId(),
19716                                                    mbMessageModelImpl.getThreadId(),
19717                                                    mbMessageModelImpl.getAnswer()
19718                                            };
19719    
19720                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19721                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19722                                            args);
19723                            }
19724    
19725                            if ((mbMessageModelImpl.getColumnBitmask() &
19726                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19727                                    Object[] args = new Object[] {
19728                                                    mbMessageModelImpl.getOriginalGroupId(),
19729                                                    mbMessageModelImpl.getOriginalCategoryId(),
19730                                                    mbMessageModelImpl.getOriginalThreadId(),
19731                                                    mbMessageModelImpl.getOriginalStatus()
19732                                            };
19733    
19734                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19735                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19736                                            args);
19737    
19738                                    args = new Object[] {
19739                                                    mbMessageModelImpl.getGroupId(),
19740                                                    mbMessageModelImpl.getCategoryId(),
19741                                                    mbMessageModelImpl.getThreadId(),
19742                                                    mbMessageModelImpl.getStatus()
19743                                            };
19744    
19745                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19746                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19747                                            args);
19748                            }
19749    
19750                            if ((mbMessageModelImpl.getColumnBitmask() &
19751                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19752                                    Object[] args = new Object[] {
19753                                                    mbMessageModelImpl.getOriginalUserId(),
19754                                                    mbMessageModelImpl.getOriginalClassNameId(),
19755                                                    mbMessageModelImpl.getOriginalClassPK(),
19756                                                    mbMessageModelImpl.getOriginalStatus()
19757                                            };
19758    
19759                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19760                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19761                                            args);
19762    
19763                                    args = new Object[] {
19764                                                    mbMessageModelImpl.getUserId(),
19765                                                    mbMessageModelImpl.getClassNameId(),
19766                                                    mbMessageModelImpl.getClassPK(),
19767                                                    mbMessageModelImpl.getStatus()
19768                                            };
19769    
19770                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19771                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19772                                            args);
19773                            }
19774                    }
19775    
19776                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19777                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
19778    
19779                    clearUniqueFindersCache(mbMessageModelImpl);
19780                    cacheUniqueFindersCache(mbMessageModelImpl, isNew);
19781    
19782                    mbMessage.resetOriginalValues();
19783    
19784                    return mbMessage;
19785            }
19786    
19787            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19788                    if (mbMessage instanceof MBMessageImpl) {
19789                            return mbMessage;
19790                    }
19791    
19792                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19793    
19794                    mbMessageImpl.setNew(mbMessage.isNew());
19795                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19796    
19797                    mbMessageImpl.setUuid(mbMessage.getUuid());
19798                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19799                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19800                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19801                    mbMessageImpl.setUserId(mbMessage.getUserId());
19802                    mbMessageImpl.setUserName(mbMessage.getUserName());
19803                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19804                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19805                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19806                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19807                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19808                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19809                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19810                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19811                    mbMessageImpl.setSubject(mbMessage.getSubject());
19812                    mbMessageImpl.setBody(mbMessage.getBody());
19813                    mbMessageImpl.setFormat(mbMessage.getFormat());
19814                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19815                    mbMessageImpl.setPriority(mbMessage.getPriority());
19816                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19817                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19818                    mbMessageImpl.setLastPublishDate(mbMessage.getLastPublishDate());
19819                    mbMessageImpl.setStatus(mbMessage.getStatus());
19820                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19821                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19822                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19823    
19824                    return mbMessageImpl;
19825            }
19826    
19827            /**
19828             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
19829             *
19830             * @param primaryKey the primary key of the message-boards message
19831             * @return the message-boards message
19832             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19833             */
19834            @Override
19835            public MBMessage findByPrimaryKey(Serializable primaryKey)
19836                    throws NoSuchMessageException {
19837                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19838    
19839                    if (mbMessage == null) {
19840                            if (_log.isDebugEnabled()) {
19841                                    _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19842                            }
19843    
19844                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19845                                    primaryKey);
19846                    }
19847    
19848                    return mbMessage;
19849            }
19850    
19851            /**
19852             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19853             *
19854             * @param messageId the primary key of the message-boards message
19855             * @return the message-boards message
19856             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19857             */
19858            @Override
19859            public MBMessage findByPrimaryKey(long messageId)
19860                    throws NoSuchMessageException {
19861                    return findByPrimaryKey((Serializable)messageId);
19862            }
19863    
19864            /**
19865             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19866             *
19867             * @param primaryKey the primary key of the message-boards message
19868             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19869             */
19870            @Override
19871            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19872                    MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19873                                    MBMessageImpl.class, primaryKey);
19874    
19875                    if (mbMessage == _nullMBMessage) {
19876                            return null;
19877                    }
19878    
19879                    if (mbMessage == null) {
19880                            Session session = null;
19881    
19882                            try {
19883                                    session = openSession();
19884    
19885                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19886                                                    primaryKey);
19887    
19888                                    if (mbMessage != null) {
19889                                            cacheResult(mbMessage);
19890                                    }
19891                                    else {
19892                                            entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19893                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19894                                    }
19895                            }
19896                            catch (Exception e) {
19897                                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19898                                            MBMessageImpl.class, primaryKey);
19899    
19900                                    throw processException(e);
19901                            }
19902                            finally {
19903                                    closeSession(session);
19904                            }
19905                    }
19906    
19907                    return mbMessage;
19908            }
19909    
19910            /**
19911             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19912             *
19913             * @param messageId the primary key of the message-boards message
19914             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19915             */
19916            @Override
19917            public MBMessage fetchByPrimaryKey(long messageId) {
19918                    return fetchByPrimaryKey((Serializable)messageId);
19919            }
19920    
19921            @Override
19922            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19923                    Set<Serializable> primaryKeys) {
19924                    if (primaryKeys.isEmpty()) {
19925                            return Collections.emptyMap();
19926                    }
19927    
19928                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19929    
19930                    if (primaryKeys.size() == 1) {
19931                            Iterator<Serializable> iterator = primaryKeys.iterator();
19932    
19933                            Serializable primaryKey = iterator.next();
19934    
19935                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19936    
19937                            if (mbMessage != null) {
19938                                    map.put(primaryKey, mbMessage);
19939                            }
19940    
19941                            return map;
19942                    }
19943    
19944                    Set<Serializable> uncachedPrimaryKeys = null;
19945    
19946                    for (Serializable primaryKey : primaryKeys) {
19947                            MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19948                                            MBMessageImpl.class, primaryKey);
19949    
19950                            if (mbMessage == null) {
19951                                    if (uncachedPrimaryKeys == null) {
19952                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19953                                    }
19954    
19955                                    uncachedPrimaryKeys.add(primaryKey);
19956                            }
19957                            else {
19958                                    map.put(primaryKey, mbMessage);
19959                            }
19960                    }
19961    
19962                    if (uncachedPrimaryKeys == null) {
19963                            return map;
19964                    }
19965    
19966                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19967                                    1);
19968    
19969                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19970    
19971                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19972                            query.append(String.valueOf(primaryKey));
19973    
19974                            query.append(StringPool.COMMA);
19975                    }
19976    
19977                    query.setIndex(query.index() - 1);
19978    
19979                    query.append(StringPool.CLOSE_PARENTHESIS);
19980    
19981                    String sql = query.toString();
19982    
19983                    Session session = null;
19984    
19985                    try {
19986                            session = openSession();
19987    
19988                            Query q = session.createQuery(sql);
19989    
19990                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19991                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19992    
19993                                    cacheResult(mbMessage);
19994    
19995                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19996                            }
19997    
19998                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19999                                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20000                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
20001                            }
20002                    }
20003                    catch (Exception e) {
20004                            throw processException(e);
20005                    }
20006                    finally {
20007                            closeSession(session);
20008                    }
20009    
20010                    return map;
20011            }
20012    
20013            /**
20014             * Returns all the message-boards messages.
20015             *
20016             * @return the message-boards messages
20017             */
20018            @Override
20019            public List<MBMessage> findAll() {
20020                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20021            }
20022    
20023            /**
20024             * Returns a range of all the message-boards messages.
20025             *
20026             * <p>
20027             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20028             * </p>
20029             *
20030             * @param start the lower bound of the range of message-boards messages
20031             * @param end the upper bound of the range of message-boards messages (not inclusive)
20032             * @return the range of message-boards messages
20033             */
20034            @Override
20035            public List<MBMessage> findAll(int start, int end) {
20036                    return findAll(start, end, null);
20037            }
20038    
20039            /**
20040             * Returns an ordered range of all the message-boards messages.
20041             *
20042             * <p>
20043             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20044             * </p>
20045             *
20046             * @param start the lower bound of the range of message-boards messages
20047             * @param end the upper bound of the range of message-boards messages (not inclusive)
20048             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20049             * @return the ordered range of message-boards messages
20050             */
20051            @Override
20052            public List<MBMessage> findAll(int start, int end,
20053                    OrderByComparator<MBMessage> orderByComparator) {
20054                    return findAll(start, end, orderByComparator, true);
20055            }
20056    
20057            /**
20058             * Returns an ordered range of all the message-boards messages.
20059             *
20060             * <p>
20061             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20062             * </p>
20063             *
20064             * @param start the lower bound of the range of message-boards messages
20065             * @param end the upper bound of the range of message-boards messages (not inclusive)
20066             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20067             * @param retrieveFromCache whether to retrieve from the finder cache
20068             * @return the ordered range of message-boards messages
20069             */
20070            @Override
20071            public List<MBMessage> findAll(int start, int end,
20072                    OrderByComparator<MBMessage> orderByComparator,
20073                    boolean retrieveFromCache) {
20074                    boolean pagination = true;
20075                    FinderPath finderPath = null;
20076                    Object[] finderArgs = null;
20077    
20078                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20079                                    (orderByComparator == null)) {
20080                            pagination = false;
20081                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20082                            finderArgs = FINDER_ARGS_EMPTY;
20083                    }
20084                    else {
20085                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20086                            finderArgs = new Object[] { start, end, orderByComparator };
20087                    }
20088    
20089                    List<MBMessage> list = null;
20090    
20091                    if (retrieveFromCache) {
20092                            list = (List<MBMessage>)finderCache.getResult(finderPath,
20093                                            finderArgs, this);
20094                    }
20095    
20096                    if (list == null) {
20097                            StringBundler query = null;
20098                            String sql = null;
20099    
20100                            if (orderByComparator != null) {
20101                                    query = new StringBundler(2 +
20102                                                    (orderByComparator.getOrderByFields().length * 2));
20103    
20104                                    query.append(_SQL_SELECT_MBMESSAGE);
20105    
20106                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20107                                            orderByComparator);
20108    
20109                                    sql = query.toString();
20110                            }
20111                            else {
20112                                    sql = _SQL_SELECT_MBMESSAGE;
20113    
20114                                    if (pagination) {
20115                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20116                                    }
20117                            }
20118    
20119                            Session session = null;
20120    
20121                            try {
20122                                    session = openSession();
20123    
20124                                    Query q = session.createQuery(sql);
20125    
20126                                    if (!pagination) {
20127                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20128                                                            start, end, false);
20129    
20130                                            Collections.sort(list);
20131    
20132                                            list = Collections.unmodifiableList(list);
20133                                    }
20134                                    else {
20135                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20136                                                            start, end);
20137                                    }
20138    
20139                                    cacheResult(list);
20140    
20141                                    finderCache.putResult(finderPath, finderArgs, list);
20142                            }
20143                            catch (Exception e) {
20144                                    finderCache.removeResult(finderPath, finderArgs);
20145    
20146                                    throw processException(e);
20147                            }
20148                            finally {
20149                                    closeSession(session);
20150                            }
20151                    }
20152    
20153                    return list;
20154            }
20155    
20156            /**
20157             * Removes all the message-boards messages from the database.
20158             *
20159             */
20160            @Override
20161            public void removeAll() {
20162                    for (MBMessage mbMessage : findAll()) {
20163                            remove(mbMessage);
20164                    }
20165            }
20166    
20167            /**
20168             * Returns the number of message-boards messages.
20169             *
20170             * @return the number of message-boards messages
20171             */
20172            @Override
20173            public int countAll() {
20174                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
20175                                    FINDER_ARGS_EMPTY, this);
20176    
20177                    if (count == null) {
20178                            Session session = null;
20179    
20180                            try {
20181                                    session = openSession();
20182    
20183                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20184    
20185                                    count = (Long)q.uniqueResult();
20186    
20187                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
20188                                            count);
20189                            }
20190                            catch (Exception e) {
20191                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
20192                                            FINDER_ARGS_EMPTY);
20193    
20194                                    throw processException(e);
20195                            }
20196                            finally {
20197                                    closeSession(session);
20198                            }
20199                    }
20200    
20201                    return count.intValue();
20202            }
20203    
20204            @Override
20205            public Set<String> getBadColumnNames() {
20206                    return _badColumnNames;
20207            }
20208    
20209            @Override
20210            protected Map<String, Integer> getTableColumnsMap() {
20211                    return MBMessageModelImpl.TABLE_COLUMNS_MAP;
20212            }
20213    
20214            /**
20215             * Initializes the message-boards message persistence.
20216             */
20217            public void afterPropertiesSet() {
20218            }
20219    
20220            public void destroy() {
20221                    entityCache.removeCache(MBMessageImpl.class.getName());
20222                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
20223                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20224                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20225            }
20226    
20227            @BeanReference(type = CompanyProviderWrapper.class)
20228            protected CompanyProvider companyProvider;
20229            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
20230            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
20231            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
20232            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
20233            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
20234            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
20235            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
20236            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
20237            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
20238            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
20239                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
20240            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
20241                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
20242            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
20243            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
20244            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
20245            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
20246            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
20247            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
20248            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
20249            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
20250            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
20251                                    "uuid"
20252                            });
20253            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
20254                            @Override
20255                            public Object clone() {
20256                                    return this;
20257                            }
20258    
20259                            @Override
20260                            public CacheModel<MBMessage> toCacheModel() {
20261                                    return _nullMBMessageCacheModel;
20262                            }
20263                    };
20264    
20265            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
20266                            @Override
20267                            public MBMessage toEntityModel() {
20268                                    return _nullMBMessage;
20269                            }
20270                    };
20271    }