001    /**
002     * Copyright (c) 2000-2010 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.CompanyPersistence;
043    import com.liferay.portal.service.persistence.GroupPersistence;
044    import com.liferay.portal.service.persistence.LockPersistence;
045    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
046    import com.liferay.portal.service.persistence.ResourcePersistence;
047    import com.liferay.portal.service.persistence.SubscriptionPersistence;
048    import com.liferay.portal.service.persistence.UserPersistence;
049    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
050    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051    
052    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
053    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
054    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
055    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
056    import com.liferay.portlet.messageboards.NoSuchMessageException;
057    import com.liferay.portlet.messageboards.model.MBMessage;
058    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
059    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
060    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
061    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
062    import com.liferay.portlet.social.service.persistence.SocialEquityLogPersistence;
063    
064    import java.io.Serializable;
065    
066    import java.util.ArrayList;
067    import java.util.Collections;
068    import java.util.List;
069    
070    /**
071     * The persistence implementation for the message-boards message service.
072     *
073     * <p>
074     * 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.
075     * </p>
076     *
077     * <p>
078     * Caching information and settings can be found in <code>portal.properties</code>
079     * </p>
080     *
081     * @author Brian Wing Shun Chan
082     * @see MBMessagePersistence
083     * @see MBMessageUtil
084     * @generated
085     */
086    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
087            implements MBMessagePersistence {
088            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
089            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
090                    ".List";
091            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
092                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            "java.lang.Integer", "java.lang.Integer",
098                                    "com.liferay.portal.kernel.util.OrderByComparator"
099                            });
100            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
101                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "countByUuid", new String[] { String.class.getName() });
103            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
105                            "fetchByUUID_G",
106                            new String[] { String.class.getName(), Long.class.getName() });
107            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
108                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "countByUUID_G",
110                            new String[] { String.class.getName(), Long.class.getName() });
111            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
112                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113                            "findByGroupId",
114                            new String[] {
115                                    Long.class.getName(),
116                                    
117                            "java.lang.Integer", "java.lang.Integer",
118                                    "com.liferay.portal.kernel.util.OrderByComparator"
119                            });
120            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
121                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122                            "countByGroupId", new String[] { Long.class.getName() });
123            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
124                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125                            "findByCompanyId",
126                            new String[] {
127                                    Long.class.getName(),
128                                    
129                            "java.lang.Integer", "java.lang.Integer",
130                                    "com.liferay.portal.kernel.util.OrderByComparator"
131                            });
132            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
133                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134                            "countByCompanyId", new String[] { Long.class.getName() });
135            public static final FinderPath FINDER_PATH_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
136                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137                            "findByThreadId",
138                            new String[] {
139                                    Long.class.getName(),
140                                    
141                            "java.lang.Integer", "java.lang.Integer",
142                                    "com.liferay.portal.kernel.util.OrderByComparator"
143                            });
144            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
145                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
146                            "countByThreadId", new String[] { Long.class.getName() });
147            public static final FinderPath FINDER_PATH_FIND_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
148                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
149                            "findByThreadReplies",
150                            new String[] {
151                                    Long.class.getName(),
152                                    
153                            "java.lang.Integer", "java.lang.Integer",
154                                    "com.liferay.portal.kernel.util.OrderByComparator"
155                            });
156            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
157                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
158                            "countByThreadReplies", new String[] { Long.class.getName() });
159            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
160                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
161                            "findByUserId",
162                            new String[] {
163                                    Long.class.getName(),
164                                    
165                            "java.lang.Integer", "java.lang.Integer",
166                                    "com.liferay.portal.kernel.util.OrderByComparator"
167                            });
168            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
169                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
170                            "countByUserId", new String[] { Long.class.getName() });
171            public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
172                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
173                            "findByG_U",
174                            new String[] {
175                                    Long.class.getName(), Long.class.getName(),
176                                    
177                            "java.lang.Integer", "java.lang.Integer",
178                                    "com.liferay.portal.kernel.util.OrderByComparator"
179                            });
180            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
181                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
182                            "countByG_U",
183                            new String[] { Long.class.getName(), Long.class.getName() });
184            public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
186                            "findByG_C",
187                            new String[] {
188                                    Long.class.getName(), Long.class.getName(),
189                                    
190                            "java.lang.Integer", "java.lang.Integer",
191                                    "com.liferay.portal.kernel.util.OrderByComparator"
192                            });
193            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
194                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
195                            "countByG_C",
196                            new String[] { Long.class.getName(), Long.class.getName() });
197            public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
199                            "findByG_S",
200                            new String[] {
201                                    Long.class.getName(), Integer.class.getName(),
202                                    
203                            "java.lang.Integer", "java.lang.Integer",
204                                    "com.liferay.portal.kernel.util.OrderByComparator"
205                            });
206            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
207                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
208                            "countByG_S",
209                            new String[] { Long.class.getName(), Integer.class.getName() });
210            public static final FinderPath FINDER_PATH_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
211                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
212                            "findByC_S",
213                            new String[] {
214                                    Long.class.getName(), Integer.class.getName(),
215                                    
216                            "java.lang.Integer", "java.lang.Integer",
217                                    "com.liferay.portal.kernel.util.OrderByComparator"
218                            });
219            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
220                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
221                            "countByC_S",
222                            new String[] { Long.class.getName(), Integer.class.getName() });
223            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
224                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
225                            "findByC_C",
226                            new String[] {
227                                    Long.class.getName(), Long.class.getName(),
228                                    
229                            "java.lang.Integer", "java.lang.Integer",
230                                    "com.liferay.portal.kernel.util.OrderByComparator"
231                            });
232            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
233                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
234                            "countByC_C",
235                            new String[] { Long.class.getName(), Long.class.getName() });
236            public static final FinderPath FINDER_PATH_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
237                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
238                            "findByT_P",
239                            new String[] {
240                                    Long.class.getName(), Long.class.getName(),
241                                    
242                            "java.lang.Integer", "java.lang.Integer",
243                                    "com.liferay.portal.kernel.util.OrderByComparator"
244                            });
245            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
246                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
247                            "countByT_P",
248                            new String[] { Long.class.getName(), Long.class.getName() });
249            public static final FinderPath FINDER_PATH_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
250                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
251                            "findByT_S",
252                            new String[] {
253                                    Long.class.getName(), Integer.class.getName(),
254                                    
255                            "java.lang.Integer", "java.lang.Integer",
256                                    "com.liferay.portal.kernel.util.OrderByComparator"
257                            });
258            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
259                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
260                            "countByT_S",
261                            new String[] { Long.class.getName(), Integer.class.getName() });
262            public static final FinderPath FINDER_PATH_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
263                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
264                            "findByTR_S",
265                            new String[] {
266                                    Long.class.getName(), Integer.class.getName(),
267                                    
268                            "java.lang.Integer", "java.lang.Integer",
269                                    "com.liferay.portal.kernel.util.OrderByComparator"
270                            });
271            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
272                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
273                            "countByTR_S",
274                            new String[] { Long.class.getName(), Integer.class.getName() });
275            public static final FinderPath FINDER_PATH_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
276                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
277                            "findByG_U_S",
278                            new String[] {
279                                    Long.class.getName(), Long.class.getName(),
280                                    Integer.class.getName(),
281                                    
282                            "java.lang.Integer", "java.lang.Integer",
283                                    "com.liferay.portal.kernel.util.OrderByComparator"
284                            });
285            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
286                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
287                            "countByG_U_S",
288                            new String[] {
289                                    Long.class.getName(), Long.class.getName(),
290                                    Integer.class.getName()
291                            });
292            public static final FinderPath FINDER_PATH_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
293                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
294                            "findByG_C_T",
295                            new String[] {
296                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
297                                    
298                            "java.lang.Integer", "java.lang.Integer",
299                                    "com.liferay.portal.kernel.util.OrderByComparator"
300                            });
301            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
302                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
303                            "countByG_C_T",
304                            new String[] {
305                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
306                            });
307            public static final FinderPath FINDER_PATH_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
308                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
309                            "findByG_C_S",
310                            new String[] {
311                                    Long.class.getName(), Long.class.getName(),
312                                    Integer.class.getName(),
313                                    
314                            "java.lang.Integer", "java.lang.Integer",
315                                    "com.liferay.portal.kernel.util.OrderByComparator"
316                            });
317            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
318                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
319                            "countByG_C_S",
320                            new String[] {
321                                    Long.class.getName(), Long.class.getName(),
322                                    Integer.class.getName()
323                            });
324            public static final FinderPath FINDER_PATH_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
325                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
326                            "findByC_C_S",
327                            new String[] {
328                                    Long.class.getName(), Long.class.getName(),
329                                    Integer.class.getName(),
330                                    
331                            "java.lang.Integer", "java.lang.Integer",
332                                    "com.liferay.portal.kernel.util.OrderByComparator"
333                            });
334            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
335                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
336                            "countByC_C_S",
337                            new String[] {
338                                    Long.class.getName(), Long.class.getName(),
339                                    Integer.class.getName()
340                            });
341            public static final FinderPath FINDER_PATH_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
342                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
343                            "findByG_C_T_S",
344                            new String[] {
345                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
346                                    Integer.class.getName(),
347                                    
348                            "java.lang.Integer", "java.lang.Integer",
349                                    "com.liferay.portal.kernel.util.OrderByComparator"
350                            });
351            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
352                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
353                            "countByG_C_T_S",
354                            new String[] {
355                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
356                                    Integer.class.getName()
357                            });
358            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
359                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
360                            "findAll", new String[0]);
361            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
362                            MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
363                            "countAll", new String[0]);
364    
365            /**
366             * Caches the message-boards message in the entity cache if it is enabled.
367             *
368             * @param mbMessage the message-boards message to cache
369             */
370            public void cacheResult(MBMessage mbMessage) {
371                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
372                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
373    
374                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
375                            new Object[] { mbMessage.getUuid(), new Long(mbMessage.getGroupId()) },
376                            mbMessage);
377            }
378    
379            /**
380             * Caches the message-boards messages in the entity cache if it is enabled.
381             *
382             * @param mbMessages the message-boards messages to cache
383             */
384            public void cacheResult(List<MBMessage> mbMessages) {
385                    for (MBMessage mbMessage : mbMessages) {
386                            if (EntityCacheUtil.getResult(
387                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
388                                                    MBMessageImpl.class, mbMessage.getPrimaryKey(), this) == null) {
389                                    cacheResult(mbMessage);
390                            }
391                    }
392            }
393    
394            /**
395             * Clears the cache for all message-boards messages.
396             *
397             * <p>
398             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
399             * </p>
400             */
401            public void clearCache() {
402                    CacheRegistryUtil.clear(MBMessageImpl.class.getName());
403                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
404                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
406            }
407    
408            /**
409             * Clears the cache for the message-boards message.
410             *
411             * <p>
412             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
413             * </p>
414             */
415            public void clearCache(MBMessage mbMessage) {
416                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
417                            MBMessageImpl.class, mbMessage.getPrimaryKey());
418    
419                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
420                            new Object[] { mbMessage.getUuid(), new Long(mbMessage.getGroupId()) });
421            }
422    
423            /**
424             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
425             *
426             * @param messageId the primary key for the new message-boards message
427             * @return the new message-boards message
428             */
429            public MBMessage create(long messageId) {
430                    MBMessage mbMessage = new MBMessageImpl();
431    
432                    mbMessage.setNew(true);
433                    mbMessage.setPrimaryKey(messageId);
434    
435                    String uuid = PortalUUIDUtil.generate();
436    
437                    mbMessage.setUuid(uuid);
438    
439                    return mbMessage;
440            }
441    
442            /**
443             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
444             *
445             * @param primaryKey the primary key of the message-boards message to remove
446             * @return the message-boards message that was removed
447             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
448             * @throws SystemException if a system exception occurred
449             */
450            public MBMessage remove(Serializable primaryKey)
451                    throws NoSuchModelException, SystemException {
452                    return remove(((Long)primaryKey).longValue());
453            }
454    
455            /**
456             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
457             *
458             * @param messageId the primary key of the message-boards message to remove
459             * @return the message-boards message that was removed
460             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
461             * @throws SystemException if a system exception occurred
462             */
463            public MBMessage remove(long messageId)
464                    throws NoSuchMessageException, SystemException {
465                    Session session = null;
466    
467                    try {
468                            session = openSession();
469    
470                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
471                                            new Long(messageId));
472    
473                            if (mbMessage == null) {
474                                    if (_log.isWarnEnabled()) {
475                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
476                                    }
477    
478                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
479                                            messageId);
480                            }
481    
482                            return remove(mbMessage);
483                    }
484                    catch (NoSuchMessageException nsee) {
485                            throw nsee;
486                    }
487                    catch (Exception e) {
488                            throw processException(e);
489                    }
490                    finally {
491                            closeSession(session);
492                    }
493            }
494    
495            protected MBMessage removeImpl(MBMessage mbMessage)
496                    throws SystemException {
497                    mbMessage = toUnwrappedModel(mbMessage);
498    
499                    Session session = null;
500    
501                    try {
502                            session = openSession();
503    
504                            if (mbMessage.isCachedModel() || BatchSessionUtil.isEnabled()) {
505                                    Object staleObject = session.get(MBMessageImpl.class,
506                                                    mbMessage.getPrimaryKeyObj());
507    
508                                    if (staleObject != null) {
509                                            session.evict(staleObject);
510                                    }
511                            }
512    
513                            session.delete(mbMessage);
514    
515                            session.flush();
516                    }
517                    catch (Exception e) {
518                            throw processException(e);
519                    }
520                    finally {
521                            closeSession(session);
522                    }
523    
524                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
525    
526                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
527    
528                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
529                            new Object[] {
530                                    mbMessageModelImpl.getOriginalUuid(),
531                                    new Long(mbMessageModelImpl.getOriginalGroupId())
532                            });
533    
534                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
535                            MBMessageImpl.class, mbMessage.getPrimaryKey());
536    
537                    return mbMessage;
538            }
539    
540            public MBMessage updateImpl(
541                    com.liferay.portlet.messageboards.model.MBMessage mbMessage,
542                    boolean merge) throws SystemException {
543                    mbMessage = toUnwrappedModel(mbMessage);
544    
545                    boolean isNew = mbMessage.isNew();
546    
547                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
548    
549                    if (Validator.isNull(mbMessage.getUuid())) {
550                            String uuid = PortalUUIDUtil.generate();
551    
552                            mbMessage.setUuid(uuid);
553                    }
554    
555                    Session session = null;
556    
557                    try {
558                            session = openSession();
559    
560                            BatchSessionUtil.update(session, mbMessage, merge);
561    
562                            mbMessage.setNew(false);
563                    }
564                    catch (Exception e) {
565                            throw processException(e);
566                    }
567                    finally {
568                            closeSession(session);
569                    }
570    
571                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
572    
573                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
574                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
575    
576                    if (!isNew &&
577                                    (!Validator.equals(mbMessage.getUuid(),
578                                            mbMessageModelImpl.getOriginalUuid()) ||
579                                    (mbMessage.getGroupId() != mbMessageModelImpl.getOriginalGroupId()))) {
580                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
581                                    new Object[] {
582                                            mbMessageModelImpl.getOriginalUuid(),
583                                            new Long(mbMessageModelImpl.getOriginalGroupId())
584                                    });
585                    }
586    
587                    if (isNew ||
588                                    (!Validator.equals(mbMessage.getUuid(),
589                                            mbMessageModelImpl.getOriginalUuid()) ||
590                                    (mbMessage.getGroupId() != mbMessageModelImpl.getOriginalGroupId()))) {
591                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
592                                    new Object[] {
593                                            mbMessage.getUuid(), new Long(mbMessage.getGroupId())
594                                    }, mbMessage);
595                    }
596    
597                    return mbMessage;
598            }
599    
600            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
601                    if (mbMessage instanceof MBMessageImpl) {
602                            return mbMessage;
603                    }
604    
605                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
606    
607                    mbMessageImpl.setNew(mbMessage.isNew());
608                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
609    
610                    mbMessageImpl.setUuid(mbMessage.getUuid());
611                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
612                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
613                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
614                    mbMessageImpl.setUserId(mbMessage.getUserId());
615                    mbMessageImpl.setUserName(mbMessage.getUserName());
616                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
617                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
618                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
619                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
620                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
621                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
622                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
623                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
624                    mbMessageImpl.setSubject(mbMessage.getSubject());
625                    mbMessageImpl.setBody(mbMessage.getBody());
626                    mbMessageImpl.setAttachments(mbMessage.isAttachments());
627                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
628                    mbMessageImpl.setPriority(mbMessage.getPriority());
629                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
630                    mbMessageImpl.setStatus(mbMessage.getStatus());
631                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
632                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
633                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
634    
635                    return mbMessageImpl;
636            }
637    
638            /**
639             * Finds the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
640             *
641             * @param primaryKey the primary key of the message-boards message to find
642             * @return the message-boards message
643             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public MBMessage findByPrimaryKey(Serializable primaryKey)
647                    throws NoSuchModelException, SystemException {
648                    return findByPrimaryKey(((Long)primaryKey).longValue());
649            }
650    
651            /**
652             * Finds the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
653             *
654             * @param messageId the primary key of the message-boards message to find
655             * @return the message-boards message
656             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
657             * @throws SystemException if a system exception occurred
658             */
659            public MBMessage findByPrimaryKey(long messageId)
660                    throws NoSuchMessageException, SystemException {
661                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
662    
663                    if (mbMessage == null) {
664                            if (_log.isWarnEnabled()) {
665                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
666                            }
667    
668                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
669                                    messageId);
670                    }
671    
672                    return mbMessage;
673            }
674    
675            /**
676             * Finds the message-boards message with the primary key or returns <code>null</code> if it could not be found.
677             *
678             * @param primaryKey the primary key of the message-boards message to find
679             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
680             * @throws SystemException if a system exception occurred
681             */
682            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
683                    throws SystemException {
684                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
685            }
686    
687            /**
688             * Finds the message-boards message with the primary key or returns <code>null</code> if it could not be found.
689             *
690             * @param messageId the primary key of the message-boards message to find
691             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
692             * @throws SystemException if a system exception occurred
693             */
694            public MBMessage fetchByPrimaryKey(long messageId)
695                    throws SystemException {
696                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
697                                    MBMessageImpl.class, messageId, this);
698    
699                    if (mbMessage == null) {
700                            Session session = null;
701    
702                            try {
703                                    session = openSession();
704    
705                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
706                                                    new Long(messageId));
707                            }
708                            catch (Exception e) {
709                                    throw processException(e);
710                            }
711                            finally {
712                                    if (mbMessage != null) {
713                                            cacheResult(mbMessage);
714                                    }
715    
716                                    closeSession(session);
717                            }
718                    }
719    
720                    return mbMessage;
721            }
722    
723            /**
724             * Finds all the message-boards messages where uuid = &#63;.
725             *
726             * @param uuid the uuid to search with
727             * @return the matching message-boards messages
728             * @throws SystemException if a system exception occurred
729             */
730            public List<MBMessage> findByUuid(String uuid) throws SystemException {
731                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
732            }
733    
734            /**
735             * Finds a range of all the message-boards messages where uuid = &#63;.
736             *
737             * <p>
738             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
739             * </p>
740             *
741             * @param uuid the uuid to search with
742             * @param start the lower bound of the range of message-boards messages to return
743             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
744             * @return the range of matching message-boards messages
745             * @throws SystemException if a system exception occurred
746             */
747            public List<MBMessage> findByUuid(String uuid, int start, int end)
748                    throws SystemException {
749                    return findByUuid(uuid, start, end, null);
750            }
751    
752            /**
753             * Finds an ordered range of all the message-boards messages where uuid = &#63;.
754             *
755             * <p>
756             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
757             * </p>
758             *
759             * @param uuid the uuid to search with
760             * @param start the lower bound of the range of message-boards messages to return
761             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
762             * @param orderByComparator the comparator to order the results by
763             * @return the ordered range of matching message-boards messages
764             * @throws SystemException if a system exception occurred
765             */
766            public List<MBMessage> findByUuid(String uuid, int start, int end,
767                    OrderByComparator orderByComparator) throws SystemException {
768                    Object[] finderArgs = new Object[] {
769                                    uuid,
770                                    
771                                    String.valueOf(start), String.valueOf(end),
772                                    String.valueOf(orderByComparator)
773                            };
774    
775                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
776                                    finderArgs, this);
777    
778                    if (list == null) {
779                            Session session = null;
780    
781                            try {
782                                    session = openSession();
783    
784                                    StringBundler query = null;
785    
786                                    if (orderByComparator != null) {
787                                            query = new StringBundler(3 +
788                                                            (orderByComparator.getOrderByFields().length * 3));
789                                    }
790                                    else {
791                                            query = new StringBundler(3);
792                                    }
793    
794                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
795    
796                                    if (uuid == null) {
797                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
798                                    }
799                                    else {
800                                            if (uuid.equals(StringPool.BLANK)) {
801                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
802                                            }
803                                            else {
804                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
805                                            }
806                                    }
807    
808                                    if (orderByComparator != null) {
809                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
810                                                    orderByComparator);
811                                    }
812    
813                                    else {
814                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
815                                    }
816    
817                                    String sql = query.toString();
818    
819                                    Query q = session.createQuery(sql);
820    
821                                    QueryPos qPos = QueryPos.getInstance(q);
822    
823                                    if (uuid != null) {
824                                            qPos.add(uuid);
825                                    }
826    
827                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
828                                                    end);
829                            }
830                            catch (Exception e) {
831                                    throw processException(e);
832                            }
833                            finally {
834                                    if (list == null) {
835                                            list = new ArrayList<MBMessage>();
836                                    }
837    
838                                    cacheResult(list);
839    
840                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
841                                            list);
842    
843                                    closeSession(session);
844                            }
845                    }
846    
847                    return list;
848            }
849    
850            /**
851             * Finds the first message-boards message in the ordered set where uuid = &#63;.
852             *
853             * <p>
854             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
855             * </p>
856             *
857             * @param uuid the uuid to search with
858             * @param orderByComparator the comparator to order the set by
859             * @return the first matching message-boards message
860             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
861             * @throws SystemException if a system exception occurred
862             */
863            public MBMessage findByUuid_First(String uuid,
864                    OrderByComparator orderByComparator)
865                    throws NoSuchMessageException, SystemException {
866                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
867    
868                    if (list.isEmpty()) {
869                            StringBundler msg = new StringBundler(4);
870    
871                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
872    
873                            msg.append("uuid=");
874                            msg.append(uuid);
875    
876                            msg.append(StringPool.CLOSE_CURLY_BRACE);
877    
878                            throw new NoSuchMessageException(msg.toString());
879                    }
880                    else {
881                            return list.get(0);
882                    }
883            }
884    
885            /**
886             * Finds the last message-boards message in the ordered set where uuid = &#63;.
887             *
888             * <p>
889             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
890             * </p>
891             *
892             * @param uuid the uuid to search with
893             * @param orderByComparator the comparator to order the set by
894             * @return the last matching message-boards message
895             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
896             * @throws SystemException if a system exception occurred
897             */
898            public MBMessage findByUuid_Last(String uuid,
899                    OrderByComparator orderByComparator)
900                    throws NoSuchMessageException, SystemException {
901                    int count = countByUuid(uuid);
902    
903                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
904                                    orderByComparator);
905    
906                    if (list.isEmpty()) {
907                            StringBundler msg = new StringBundler(4);
908    
909                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
910    
911                            msg.append("uuid=");
912                            msg.append(uuid);
913    
914                            msg.append(StringPool.CLOSE_CURLY_BRACE);
915    
916                            throw new NoSuchMessageException(msg.toString());
917                    }
918                    else {
919                            return list.get(0);
920                    }
921            }
922    
923            /**
924             * Finds the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
925             *
926             * <p>
927             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
928             * </p>
929             *
930             * @param messageId the primary key of the current message-boards message
931             * @param uuid the uuid to search with
932             * @param orderByComparator the comparator to order the set by
933             * @return the previous, current, and next message-boards message
934             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
935             * @throws SystemException if a system exception occurred
936             */
937            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
938                    OrderByComparator orderByComparator)
939                    throws NoSuchMessageException, SystemException {
940                    MBMessage mbMessage = findByPrimaryKey(messageId);
941    
942                    Session session = null;
943    
944                    try {
945                            session = openSession();
946    
947                            MBMessage[] array = new MBMessageImpl[3];
948    
949                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
950                                            orderByComparator, true);
951    
952                            array[1] = mbMessage;
953    
954                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
955                                            orderByComparator, false);
956    
957                            return array;
958                    }
959                    catch (Exception e) {
960                            throw processException(e);
961                    }
962                    finally {
963                            closeSession(session);
964                    }
965            }
966    
967            protected MBMessage getByUuid_PrevAndNext(Session session,
968                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
969                    boolean previous) {
970                    StringBundler query = null;
971    
972                    if (orderByComparator != null) {
973                            query = new StringBundler(6 +
974                                            (orderByComparator.getOrderByFields().length * 6));
975                    }
976                    else {
977                            query = new StringBundler(3);
978                    }
979    
980                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
981    
982                    if (uuid == null) {
983                            query.append(_FINDER_COLUMN_UUID_UUID_1);
984                    }
985                    else {
986                            if (uuid.equals(StringPool.BLANK)) {
987                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
988                            }
989                            else {
990                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
991                            }
992                    }
993    
994                    if (orderByComparator != null) {
995                            String[] orderByFields = orderByComparator.getOrderByFields();
996    
997                            if (orderByFields.length > 0) {
998                                    query.append(WHERE_AND);
999                            }
1000    
1001                            for (int i = 0; i < orderByFields.length; i++) {
1002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1003                                    query.append(orderByFields[i]);
1004    
1005                                    if ((i + 1) < orderByFields.length) {
1006                                            if (orderByComparator.isAscending() ^ previous) {
1007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1008                                            }
1009                                            else {
1010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1011                                            }
1012                                    }
1013                                    else {
1014                                            if (orderByComparator.isAscending() ^ previous) {
1015                                                    query.append(WHERE_GREATER_THAN);
1016                                            }
1017                                            else {
1018                                                    query.append(WHERE_LESSER_THAN);
1019                                            }
1020                                    }
1021                            }
1022    
1023                            query.append(ORDER_BY_CLAUSE);
1024    
1025                            for (int i = 0; i < orderByFields.length; i++) {
1026                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1027                                    query.append(orderByFields[i]);
1028    
1029                                    if ((i + 1) < orderByFields.length) {
1030                                            if (orderByComparator.isAscending() ^ previous) {
1031                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1032                                            }
1033                                            else {
1034                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1035                                            }
1036                                    }
1037                                    else {
1038                                            if (orderByComparator.isAscending() ^ previous) {
1039                                                    query.append(ORDER_BY_ASC);
1040                                            }
1041                                            else {
1042                                                    query.append(ORDER_BY_DESC);
1043                                            }
1044                                    }
1045                            }
1046                    }
1047    
1048                    else {
1049                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1050                    }
1051    
1052                    String sql = query.toString();
1053    
1054                    Query q = session.createQuery(sql);
1055    
1056                    q.setFirstResult(0);
1057                    q.setMaxResults(2);
1058    
1059                    QueryPos qPos = QueryPos.getInstance(q);
1060    
1061                    if (uuid != null) {
1062                            qPos.add(uuid);
1063                    }
1064    
1065                    if (orderByComparator != null) {
1066                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
1067    
1068                            for (Object value : values) {
1069                                    qPos.add(value);
1070                            }
1071                    }
1072    
1073                    List<MBMessage> list = q.list();
1074    
1075                    if (list.size() == 2) {
1076                            return list.get(1);
1077                    }
1078                    else {
1079                            return null;
1080                    }
1081            }
1082    
1083            /**
1084             * Finds the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
1085             *
1086             * @param uuid the uuid to search with
1087             * @param groupId the group id to search with
1088             * @return the matching message-boards message
1089             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1090             * @throws SystemException if a system exception occurred
1091             */
1092            public MBMessage findByUUID_G(String uuid, long groupId)
1093                    throws NoSuchMessageException, SystemException {
1094                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
1095    
1096                    if (mbMessage == null) {
1097                            StringBundler msg = new StringBundler(6);
1098    
1099                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1100    
1101                            msg.append("uuid=");
1102                            msg.append(uuid);
1103    
1104                            msg.append(", groupId=");
1105                            msg.append(groupId);
1106    
1107                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1108    
1109                            if (_log.isWarnEnabled()) {
1110                                    _log.warn(msg.toString());
1111                            }
1112    
1113                            throw new NoSuchMessageException(msg.toString());
1114                    }
1115    
1116                    return mbMessage;
1117            }
1118    
1119            /**
1120             * Finds 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.
1121             *
1122             * @param uuid the uuid to search with
1123             * @param groupId the group id to search with
1124             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1125             * @throws SystemException if a system exception occurred
1126             */
1127            public MBMessage fetchByUUID_G(String uuid, long groupId)
1128                    throws SystemException {
1129                    return fetchByUUID_G(uuid, groupId, true);
1130            }
1131    
1132            /**
1133             * Finds 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.
1134             *
1135             * @param uuid the uuid to search with
1136             * @param groupId the group id to search with
1137             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1138             * @throws SystemException if a system exception occurred
1139             */
1140            public MBMessage fetchByUUID_G(String uuid, long groupId,
1141                    boolean retrieveFromCache) throws SystemException {
1142                    Object[] finderArgs = new Object[] { uuid, groupId };
1143    
1144                    Object result = null;
1145    
1146                    if (retrieveFromCache) {
1147                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1148                                            finderArgs, this);
1149                    }
1150    
1151                    if (result == null) {
1152                            Session session = null;
1153    
1154                            try {
1155                                    session = openSession();
1156    
1157                                    StringBundler query = new StringBundler(4);
1158    
1159                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1160    
1161                                    if (uuid == null) {
1162                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1163                                    }
1164                                    else {
1165                                            if (uuid.equals(StringPool.BLANK)) {
1166                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1167                                            }
1168                                            else {
1169                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1170                                            }
1171                                    }
1172    
1173                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1174    
1175                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1176    
1177                                    String sql = query.toString();
1178    
1179                                    Query q = session.createQuery(sql);
1180    
1181                                    QueryPos qPos = QueryPos.getInstance(q);
1182    
1183                                    if (uuid != null) {
1184                                            qPos.add(uuid);
1185                                    }
1186    
1187                                    qPos.add(groupId);
1188    
1189                                    List<MBMessage> list = q.list();
1190    
1191                                    result = list;
1192    
1193                                    MBMessage mbMessage = null;
1194    
1195                                    if (list.isEmpty()) {
1196                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1197                                                    finderArgs, list);
1198                                    }
1199                                    else {
1200                                            mbMessage = list.get(0);
1201    
1202                                            cacheResult(mbMessage);
1203    
1204                                            if ((mbMessage.getUuid() == null) ||
1205                                                            !mbMessage.getUuid().equals(uuid) ||
1206                                                            (mbMessage.getGroupId() != groupId)) {
1207                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1208                                                            finderArgs, mbMessage);
1209                                            }
1210                                    }
1211    
1212                                    return mbMessage;
1213                            }
1214                            catch (Exception e) {
1215                                    throw processException(e);
1216                            }
1217                            finally {
1218                                    if (result == null) {
1219                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1220                                                    finderArgs, new ArrayList<MBMessage>());
1221                                    }
1222    
1223                                    closeSession(session);
1224                            }
1225                    }
1226                    else {
1227                            if (result instanceof List<?>) {
1228                                    return null;
1229                            }
1230                            else {
1231                                    return (MBMessage)result;
1232                            }
1233                    }
1234            }
1235    
1236            /**
1237             * Finds all the message-boards messages where groupId = &#63;.
1238             *
1239             * @param groupId the group id to search with
1240             * @return the matching message-boards messages
1241             * @throws SystemException if a system exception occurred
1242             */
1243            public List<MBMessage> findByGroupId(long groupId)
1244                    throws SystemException {
1245                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1246            }
1247    
1248            /**
1249             * Finds a range of all the message-boards messages where groupId = &#63;.
1250             *
1251             * <p>
1252             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1253             * </p>
1254             *
1255             * @param groupId the group id to search with
1256             * @param start the lower bound of the range of message-boards messages to return
1257             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
1258             * @return the range of matching message-boards messages
1259             * @throws SystemException if a system exception occurred
1260             */
1261            public List<MBMessage> findByGroupId(long groupId, int start, int end)
1262                    throws SystemException {
1263                    return findByGroupId(groupId, start, end, null);
1264            }
1265    
1266            /**
1267             * Finds an ordered range of all the message-boards messages where groupId = &#63;.
1268             *
1269             * <p>
1270             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1271             * </p>
1272             *
1273             * @param groupId the group id to search with
1274             * @param start the lower bound of the range of message-boards messages to return
1275             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
1276             * @param orderByComparator the comparator to order the results by
1277             * @return the ordered range of matching message-boards messages
1278             * @throws SystemException if a system exception occurred
1279             */
1280            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1281                    OrderByComparator orderByComparator) throws SystemException {
1282                    Object[] finderArgs = new Object[] {
1283                                    groupId,
1284                                    
1285                                    String.valueOf(start), String.valueOf(end),
1286                                    String.valueOf(orderByComparator)
1287                            };
1288    
1289                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1290                                    finderArgs, this);
1291    
1292                    if (list == null) {
1293                            Session session = null;
1294    
1295                            try {
1296                                    session = openSession();
1297    
1298                                    StringBundler query = null;
1299    
1300                                    if (orderByComparator != null) {
1301                                            query = new StringBundler(3 +
1302                                                            (orderByComparator.getOrderByFields().length * 3));
1303                                    }
1304                                    else {
1305                                            query = new StringBundler(3);
1306                                    }
1307    
1308                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1309    
1310                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1311    
1312                                    if (orderByComparator != null) {
1313                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1314                                                    orderByComparator);
1315                                    }
1316    
1317                                    else {
1318                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1319                                    }
1320    
1321                                    String sql = query.toString();
1322    
1323                                    Query q = session.createQuery(sql);
1324    
1325                                    QueryPos qPos = QueryPos.getInstance(q);
1326    
1327                                    qPos.add(groupId);
1328    
1329                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1330                                                    end);
1331                            }
1332                            catch (Exception e) {
1333                                    throw processException(e);
1334                            }
1335                            finally {
1336                                    if (list == null) {
1337                                            list = new ArrayList<MBMessage>();
1338                                    }
1339    
1340                                    cacheResult(list);
1341    
1342                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1343                                            finderArgs, list);
1344    
1345                                    closeSession(session);
1346                            }
1347                    }
1348    
1349                    return list;
1350            }
1351    
1352            /**
1353             * Finds the first message-boards message in the ordered set where groupId = &#63;.
1354             *
1355             * <p>
1356             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1357             * </p>
1358             *
1359             * @param groupId the group id to search with
1360             * @param orderByComparator the comparator to order the set by
1361             * @return the first matching message-boards message
1362             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public MBMessage findByGroupId_First(long groupId,
1366                    OrderByComparator orderByComparator)
1367                    throws NoSuchMessageException, SystemException {
1368                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1369    
1370                    if (list.isEmpty()) {
1371                            StringBundler msg = new StringBundler(4);
1372    
1373                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1374    
1375                            msg.append("groupId=");
1376                            msg.append(groupId);
1377    
1378                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1379    
1380                            throw new NoSuchMessageException(msg.toString());
1381                    }
1382                    else {
1383                            return list.get(0);
1384                    }
1385            }
1386    
1387            /**
1388             * Finds the last message-boards message in the ordered set where groupId = &#63;.
1389             *
1390             * <p>
1391             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1392             * </p>
1393             *
1394             * @param groupId the group id to search with
1395             * @param orderByComparator the comparator to order the set by
1396             * @return the last matching message-boards message
1397             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1398             * @throws SystemException if a system exception occurred
1399             */
1400            public MBMessage findByGroupId_Last(long groupId,
1401                    OrderByComparator orderByComparator)
1402                    throws NoSuchMessageException, SystemException {
1403                    int count = countByGroupId(groupId);
1404    
1405                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1406                                    orderByComparator);
1407    
1408                    if (list.isEmpty()) {
1409                            StringBundler msg = new StringBundler(4);
1410    
1411                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1412    
1413                            msg.append("groupId=");
1414                            msg.append(groupId);
1415    
1416                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1417    
1418                            throw new NoSuchMessageException(msg.toString());
1419                    }
1420                    else {
1421                            return list.get(0);
1422                    }
1423            }
1424    
1425            /**
1426             * Finds the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1427             *
1428             * <p>
1429             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1430             * </p>
1431             *
1432             * @param messageId the primary key of the current message-boards message
1433             * @param groupId the group id to search with
1434             * @param orderByComparator the comparator to order the set by
1435             * @return the previous, current, and next message-boards message
1436             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1437             * @throws SystemException if a system exception occurred
1438             */
1439            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1440                    OrderByComparator orderByComparator)
1441                    throws NoSuchMessageException, SystemException {
1442                    MBMessage mbMessage = findByPrimaryKey(messageId);
1443    
1444                    Session session = null;
1445    
1446                    try {
1447                            session = openSession();
1448    
1449                            MBMessage[] array = new MBMessageImpl[3];
1450    
1451                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1452                                            orderByComparator, true);
1453    
1454                            array[1] = mbMessage;
1455    
1456                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1457                                            orderByComparator, false);
1458    
1459                            return array;
1460                    }
1461                    catch (Exception e) {
1462                            throw processException(e);
1463                    }
1464                    finally {
1465                            closeSession(session);
1466                    }
1467            }
1468    
1469            protected MBMessage getByGroupId_PrevAndNext(Session session,
1470                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1471                    boolean previous) {
1472                    StringBundler query = null;
1473    
1474                    if (orderByComparator != null) {
1475                            query = new StringBundler(6 +
1476                                            (orderByComparator.getOrderByFields().length * 6));
1477                    }
1478                    else {
1479                            query = new StringBundler(3);
1480                    }
1481    
1482                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1483    
1484                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1485    
1486                    if (orderByComparator != null) {
1487                            String[] orderByFields = orderByComparator.getOrderByFields();
1488    
1489                            if (orderByFields.length > 0) {
1490                                    query.append(WHERE_AND);
1491                            }
1492    
1493                            for (int i = 0; i < orderByFields.length; i++) {
1494                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1495                                    query.append(orderByFields[i]);
1496    
1497                                    if ((i + 1) < orderByFields.length) {
1498                                            if (orderByComparator.isAscending() ^ previous) {
1499                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1500                                            }
1501                                            else {
1502                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1503                                            }
1504                                    }
1505                                    else {
1506                                            if (orderByComparator.isAscending() ^ previous) {
1507                                                    query.append(WHERE_GREATER_THAN);
1508                                            }
1509                                            else {
1510                                                    query.append(WHERE_LESSER_THAN);
1511                                            }
1512                                    }
1513                            }
1514    
1515                            query.append(ORDER_BY_CLAUSE);
1516    
1517                            for (int i = 0; i < orderByFields.length; i++) {
1518                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1519                                    query.append(orderByFields[i]);
1520    
1521                                    if ((i + 1) < orderByFields.length) {
1522                                            if (orderByComparator.isAscending() ^ previous) {
1523                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1524                                            }
1525                                            else {
1526                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1527                                            }
1528                                    }
1529                                    else {
1530                                            if (orderByComparator.isAscending() ^ previous) {
1531                                                    query.append(ORDER_BY_ASC);
1532                                            }
1533                                            else {
1534                                                    query.append(ORDER_BY_DESC);
1535                                            }
1536                                    }
1537                            }
1538                    }
1539    
1540                    else {
1541                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1542                    }
1543    
1544                    String sql = query.toString();
1545    
1546                    Query q = session.createQuery(sql);
1547    
1548                    q.setFirstResult(0);
1549                    q.setMaxResults(2);
1550    
1551                    QueryPos qPos = QueryPos.getInstance(q);
1552    
1553                    qPos.add(groupId);
1554    
1555                    if (orderByComparator != null) {
1556                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
1557    
1558                            for (Object value : values) {
1559                                    qPos.add(value);
1560                            }
1561                    }
1562    
1563                    List<MBMessage> list = q.list();
1564    
1565                    if (list.size() == 2) {
1566                            return list.get(1);
1567                    }
1568                    else {
1569                            return null;
1570                    }
1571            }
1572    
1573            /**
1574             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63;.
1575             *
1576             * @param groupId the group id to search with
1577             * @return the matching message-boards messages that the user has permission to view
1578             * @throws SystemException if a system exception occurred
1579             */
1580            public List<MBMessage> filterFindByGroupId(long groupId)
1581                    throws SystemException {
1582                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1583                            QueryUtil.ALL_POS, null);
1584            }
1585    
1586            /**
1587             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63;.
1588             *
1589             * <p>
1590             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1591             * </p>
1592             *
1593             * @param groupId the group id to search with
1594             * @param start the lower bound of the range of message-boards messages to return
1595             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
1596             * @return the range of matching message-boards messages that the user has permission to view
1597             * @throws SystemException if a system exception occurred
1598             */
1599            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1600                    throws SystemException {
1601                    return filterFindByGroupId(groupId, start, end, null);
1602            }
1603    
1604            /**
1605             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63;.
1606             *
1607             * <p>
1608             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1609             * </p>
1610             *
1611             * @param groupId the group id to search with
1612             * @param start the lower bound of the range of message-boards messages to return
1613             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
1614             * @param orderByComparator the comparator to order the results by
1615             * @return the ordered range of matching message-boards messages that the user has permission to view
1616             * @throws SystemException if a system exception occurred
1617             */
1618            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1619                    int end, OrderByComparator orderByComparator) throws SystemException {
1620                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1621                            return findByGroupId(groupId, start, end, orderByComparator);
1622                    }
1623    
1624                    Session session = null;
1625    
1626                    try {
1627                            session = openSession();
1628    
1629                            StringBundler query = null;
1630    
1631                            if (orderByComparator != null) {
1632                                    query = new StringBundler(3 +
1633                                                    (orderByComparator.getOrderByFields().length * 3));
1634                            }
1635                            else {
1636                                    query = new StringBundler(3);
1637                            }
1638    
1639                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1640    
1641                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1642    
1643                            if (orderByComparator != null) {
1644                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1645                                            orderByComparator);
1646                            }
1647    
1648                            else {
1649                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1650                            }
1651    
1652                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1653                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
1654                                            _FILTER_COLUMN_USERID, groupId);
1655    
1656                            SQLQuery q = session.createSQLQuery(sql);
1657    
1658                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1659    
1660                            QueryPos qPos = QueryPos.getInstance(q);
1661    
1662                            qPos.add(groupId);
1663    
1664                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1665                    }
1666                    catch (Exception e) {
1667                            throw processException(e);
1668                    }
1669                    finally {
1670                            closeSession(session);
1671                    }
1672            }
1673    
1674            /**
1675             * Finds all the message-boards messages where companyId = &#63;.
1676             *
1677             * @param companyId the company id to search with
1678             * @return the matching message-boards messages
1679             * @throws SystemException if a system exception occurred
1680             */
1681            public List<MBMessage> findByCompanyId(long companyId)
1682                    throws SystemException {
1683                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1684                            null);
1685            }
1686    
1687            /**
1688             * Finds a range of all the message-boards messages where companyId = &#63;.
1689             *
1690             * <p>
1691             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1692             * </p>
1693             *
1694             * @param companyId the company id to search with
1695             * @param start the lower bound of the range of message-boards messages to return
1696             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
1697             * @return the range of matching message-boards messages
1698             * @throws SystemException if a system exception occurred
1699             */
1700            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
1701                    throws SystemException {
1702                    return findByCompanyId(companyId, start, end, null);
1703            }
1704    
1705            /**
1706             * Finds an ordered range of all the message-boards messages where companyId = &#63;.
1707             *
1708             * <p>
1709             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1710             * </p>
1711             *
1712             * @param companyId the company id to search with
1713             * @param start the lower bound of the range of message-boards messages to return
1714             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
1715             * @param orderByComparator the comparator to order the results by
1716             * @return the ordered range of matching message-boards messages
1717             * @throws SystemException if a system exception occurred
1718             */
1719            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
1720                    OrderByComparator orderByComparator) throws SystemException {
1721                    Object[] finderArgs = new Object[] {
1722                                    companyId,
1723                                    
1724                                    String.valueOf(start), String.valueOf(end),
1725                                    String.valueOf(orderByComparator)
1726                            };
1727    
1728                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1729                                    finderArgs, this);
1730    
1731                    if (list == null) {
1732                            Session session = null;
1733    
1734                            try {
1735                                    session = openSession();
1736    
1737                                    StringBundler query = null;
1738    
1739                                    if (orderByComparator != null) {
1740                                            query = new StringBundler(3 +
1741                                                            (orderByComparator.getOrderByFields().length * 3));
1742                                    }
1743                                    else {
1744                                            query = new StringBundler(3);
1745                                    }
1746    
1747                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1748    
1749                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1750    
1751                                    if (orderByComparator != null) {
1752                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1753                                                    orderByComparator);
1754                                    }
1755    
1756                                    else {
1757                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1758                                    }
1759    
1760                                    String sql = query.toString();
1761    
1762                                    Query q = session.createQuery(sql);
1763    
1764                                    QueryPos qPos = QueryPos.getInstance(q);
1765    
1766                                    qPos.add(companyId);
1767    
1768                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1769                                                    end);
1770                            }
1771                            catch (Exception e) {
1772                                    throw processException(e);
1773                            }
1774                            finally {
1775                                    if (list == null) {
1776                                            list = new ArrayList<MBMessage>();
1777                                    }
1778    
1779                                    cacheResult(list);
1780    
1781                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1782                                            finderArgs, list);
1783    
1784                                    closeSession(session);
1785                            }
1786                    }
1787    
1788                    return list;
1789            }
1790    
1791            /**
1792             * Finds the first message-boards message in the ordered set where companyId = &#63;.
1793             *
1794             * <p>
1795             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1796             * </p>
1797             *
1798             * @param companyId the company id to search with
1799             * @param orderByComparator the comparator to order the set by
1800             * @return the first matching message-boards message
1801             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1802             * @throws SystemException if a system exception occurred
1803             */
1804            public MBMessage findByCompanyId_First(long companyId,
1805                    OrderByComparator orderByComparator)
1806                    throws NoSuchMessageException, SystemException {
1807                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
1808                                    orderByComparator);
1809    
1810                    if (list.isEmpty()) {
1811                            StringBundler msg = new StringBundler(4);
1812    
1813                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1814    
1815                            msg.append("companyId=");
1816                            msg.append(companyId);
1817    
1818                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1819    
1820                            throw new NoSuchMessageException(msg.toString());
1821                    }
1822                    else {
1823                            return list.get(0);
1824                    }
1825            }
1826    
1827            /**
1828             * Finds the last message-boards message in the ordered set where companyId = &#63;.
1829             *
1830             * <p>
1831             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1832             * </p>
1833             *
1834             * @param companyId the company id to search with
1835             * @param orderByComparator the comparator to order the set by
1836             * @return the last matching message-boards message
1837             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public MBMessage findByCompanyId_Last(long companyId,
1841                    OrderByComparator orderByComparator)
1842                    throws NoSuchMessageException, SystemException {
1843                    int count = countByCompanyId(companyId);
1844    
1845                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
1846                                    orderByComparator);
1847    
1848                    if (list.isEmpty()) {
1849                            StringBundler msg = new StringBundler(4);
1850    
1851                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1852    
1853                            msg.append("companyId=");
1854                            msg.append(companyId);
1855    
1856                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1857    
1858                            throw new NoSuchMessageException(msg.toString());
1859                    }
1860                    else {
1861                            return list.get(0);
1862                    }
1863            }
1864    
1865            /**
1866             * Finds the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
1867             *
1868             * <p>
1869             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1870             * </p>
1871             *
1872             * @param messageId the primary key of the current message-boards message
1873             * @param companyId the company id to search with
1874             * @param orderByComparator the comparator to order the set by
1875             * @return the previous, current, and next message-boards message
1876             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1877             * @throws SystemException if a system exception occurred
1878             */
1879            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
1880                    long companyId, OrderByComparator orderByComparator)
1881                    throws NoSuchMessageException, SystemException {
1882                    MBMessage mbMessage = findByPrimaryKey(messageId);
1883    
1884                    Session session = null;
1885    
1886                    try {
1887                            session = openSession();
1888    
1889                            MBMessage[] array = new MBMessageImpl[3];
1890    
1891                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
1892                                            companyId, orderByComparator, true);
1893    
1894                            array[1] = mbMessage;
1895    
1896                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
1897                                            companyId, orderByComparator, false);
1898    
1899                            return array;
1900                    }
1901                    catch (Exception e) {
1902                            throw processException(e);
1903                    }
1904                    finally {
1905                            closeSession(session);
1906                    }
1907            }
1908    
1909            protected MBMessage getByCompanyId_PrevAndNext(Session session,
1910                    MBMessage mbMessage, long companyId,
1911                    OrderByComparator orderByComparator, boolean previous) {
1912                    StringBundler query = null;
1913    
1914                    if (orderByComparator != null) {
1915                            query = new StringBundler(6 +
1916                                            (orderByComparator.getOrderByFields().length * 6));
1917                    }
1918                    else {
1919                            query = new StringBundler(3);
1920                    }
1921    
1922                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1923    
1924                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1925    
1926                    if (orderByComparator != null) {
1927                            String[] orderByFields = orderByComparator.getOrderByFields();
1928    
1929                            if (orderByFields.length > 0) {
1930                                    query.append(WHERE_AND);
1931                            }
1932    
1933                            for (int i = 0; i < orderByFields.length; i++) {
1934                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1935                                    query.append(orderByFields[i]);
1936    
1937                                    if ((i + 1) < orderByFields.length) {
1938                                            if (orderByComparator.isAscending() ^ previous) {
1939                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1940                                            }
1941                                            else {
1942                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1943                                            }
1944                                    }
1945                                    else {
1946                                            if (orderByComparator.isAscending() ^ previous) {
1947                                                    query.append(WHERE_GREATER_THAN);
1948                                            }
1949                                            else {
1950                                                    query.append(WHERE_LESSER_THAN);
1951                                            }
1952                                    }
1953                            }
1954    
1955                            query.append(ORDER_BY_CLAUSE);
1956    
1957                            for (int i = 0; i < orderByFields.length; i++) {
1958                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1959                                    query.append(orderByFields[i]);
1960    
1961                                    if ((i + 1) < orderByFields.length) {
1962                                            if (orderByComparator.isAscending() ^ previous) {
1963                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1964                                            }
1965                                            else {
1966                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1967                                            }
1968                                    }
1969                                    else {
1970                                            if (orderByComparator.isAscending() ^ previous) {
1971                                                    query.append(ORDER_BY_ASC);
1972                                            }
1973                                            else {
1974                                                    query.append(ORDER_BY_DESC);
1975                                            }
1976                                    }
1977                            }
1978                    }
1979    
1980                    else {
1981                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1982                    }
1983    
1984                    String sql = query.toString();
1985    
1986                    Query q = session.createQuery(sql);
1987    
1988                    q.setFirstResult(0);
1989                    q.setMaxResults(2);
1990    
1991                    QueryPos qPos = QueryPos.getInstance(q);
1992    
1993                    qPos.add(companyId);
1994    
1995                    if (orderByComparator != null) {
1996                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
1997    
1998                            for (Object value : values) {
1999                                    qPos.add(value);
2000                            }
2001                    }
2002    
2003                    List<MBMessage> list = q.list();
2004    
2005                    if (list.size() == 2) {
2006                            return list.get(1);
2007                    }
2008                    else {
2009                            return null;
2010                    }
2011            }
2012    
2013            /**
2014             * Finds all the message-boards messages where threadId = &#63;.
2015             *
2016             * @param threadId the thread id to search with
2017             * @return the matching message-boards messages
2018             * @throws SystemException if a system exception occurred
2019             */
2020            public List<MBMessage> findByThreadId(long threadId)
2021                    throws SystemException {
2022                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2023                            null);
2024            }
2025    
2026            /**
2027             * Finds a range of all the message-boards messages where threadId = &#63;.
2028             *
2029             * <p>
2030             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2031             * </p>
2032             *
2033             * @param threadId the thread id to search with
2034             * @param start the lower bound of the range of message-boards messages to return
2035             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
2036             * @return the range of matching message-boards messages
2037             * @throws SystemException if a system exception occurred
2038             */
2039            public List<MBMessage> findByThreadId(long threadId, int start, int end)
2040                    throws SystemException {
2041                    return findByThreadId(threadId, start, end, null);
2042            }
2043    
2044            /**
2045             * Finds an ordered range of all the message-boards messages where threadId = &#63;.
2046             *
2047             * <p>
2048             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2049             * </p>
2050             *
2051             * @param threadId the thread id to search with
2052             * @param start the lower bound of the range of message-boards messages to return
2053             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
2054             * @param orderByComparator the comparator to order the results by
2055             * @return the ordered range of matching message-boards messages
2056             * @throws SystemException if a system exception occurred
2057             */
2058            public List<MBMessage> findByThreadId(long threadId, int start, int end,
2059                    OrderByComparator orderByComparator) throws SystemException {
2060                    Object[] finderArgs = new Object[] {
2061                                    threadId,
2062                                    
2063                                    String.valueOf(start), String.valueOf(end),
2064                                    String.valueOf(orderByComparator)
2065                            };
2066    
2067                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
2068                                    finderArgs, this);
2069    
2070                    if (list == null) {
2071                            Session session = null;
2072    
2073                            try {
2074                                    session = openSession();
2075    
2076                                    StringBundler query = null;
2077    
2078                                    if (orderByComparator != null) {
2079                                            query = new StringBundler(3 +
2080                                                            (orderByComparator.getOrderByFields().length * 3));
2081                                    }
2082                                    else {
2083                                            query = new StringBundler(3);
2084                                    }
2085    
2086                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2087    
2088                                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2089    
2090                                    if (orderByComparator != null) {
2091                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2092                                                    orderByComparator);
2093                                    }
2094    
2095                                    else {
2096                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2097                                    }
2098    
2099                                    String sql = query.toString();
2100    
2101                                    Query q = session.createQuery(sql);
2102    
2103                                    QueryPos qPos = QueryPos.getInstance(q);
2104    
2105                                    qPos.add(threadId);
2106    
2107                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2108                                                    end);
2109                            }
2110                            catch (Exception e) {
2111                                    throw processException(e);
2112                            }
2113                            finally {
2114                                    if (list == null) {
2115                                            list = new ArrayList<MBMessage>();
2116                                    }
2117    
2118                                    cacheResult(list);
2119    
2120                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
2121                                            finderArgs, list);
2122    
2123                                    closeSession(session);
2124                            }
2125                    }
2126    
2127                    return list;
2128            }
2129    
2130            /**
2131             * Finds the first message-boards message in the ordered set where threadId = &#63;.
2132             *
2133             * <p>
2134             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2135             * </p>
2136             *
2137             * @param threadId the thread id to search with
2138             * @param orderByComparator the comparator to order the set by
2139             * @return the first matching message-boards message
2140             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2141             * @throws SystemException if a system exception occurred
2142             */
2143            public MBMessage findByThreadId_First(long threadId,
2144                    OrderByComparator orderByComparator)
2145                    throws NoSuchMessageException, SystemException {
2146                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
2147    
2148                    if (list.isEmpty()) {
2149                            StringBundler msg = new StringBundler(4);
2150    
2151                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2152    
2153                            msg.append("threadId=");
2154                            msg.append(threadId);
2155    
2156                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2157    
2158                            throw new NoSuchMessageException(msg.toString());
2159                    }
2160                    else {
2161                            return list.get(0);
2162                    }
2163            }
2164    
2165            /**
2166             * Finds the last message-boards message in the ordered set where threadId = &#63;.
2167             *
2168             * <p>
2169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2170             * </p>
2171             *
2172             * @param threadId the thread id to search with
2173             * @param orderByComparator the comparator to order the set by
2174             * @return the last matching message-boards message
2175             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2176             * @throws SystemException if a system exception occurred
2177             */
2178            public MBMessage findByThreadId_Last(long threadId,
2179                    OrderByComparator orderByComparator)
2180                    throws NoSuchMessageException, SystemException {
2181                    int count = countByThreadId(threadId);
2182    
2183                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
2184                                    orderByComparator);
2185    
2186                    if (list.isEmpty()) {
2187                            StringBundler msg = new StringBundler(4);
2188    
2189                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2190    
2191                            msg.append("threadId=");
2192                            msg.append(threadId);
2193    
2194                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2195    
2196                            throw new NoSuchMessageException(msg.toString());
2197                    }
2198                    else {
2199                            return list.get(0);
2200                    }
2201            }
2202    
2203            /**
2204             * Finds the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
2205             *
2206             * <p>
2207             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2208             * </p>
2209             *
2210             * @param messageId the primary key of the current message-boards message
2211             * @param threadId the thread id to search with
2212             * @param orderByComparator the comparator to order the set by
2213             * @return the previous, current, and next message-boards message
2214             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2215             * @throws SystemException if a system exception occurred
2216             */
2217            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
2218                    long threadId, OrderByComparator orderByComparator)
2219                    throws NoSuchMessageException, SystemException {
2220                    MBMessage mbMessage = findByPrimaryKey(messageId);
2221    
2222                    Session session = null;
2223    
2224                    try {
2225                            session = openSession();
2226    
2227                            MBMessage[] array = new MBMessageImpl[3];
2228    
2229                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
2230                                            orderByComparator, true);
2231    
2232                            array[1] = mbMessage;
2233    
2234                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
2235                                            orderByComparator, false);
2236    
2237                            return array;
2238                    }
2239                    catch (Exception e) {
2240                            throw processException(e);
2241                    }
2242                    finally {
2243                            closeSession(session);
2244                    }
2245            }
2246    
2247            protected MBMessage getByThreadId_PrevAndNext(Session session,
2248                    MBMessage mbMessage, long threadId,
2249                    OrderByComparator orderByComparator, boolean previous) {
2250                    StringBundler query = null;
2251    
2252                    if (orderByComparator != null) {
2253                            query = new StringBundler(6 +
2254                                            (orderByComparator.getOrderByFields().length * 6));
2255                    }
2256                    else {
2257                            query = new StringBundler(3);
2258                    }
2259    
2260                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2261    
2262                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2263    
2264                    if (orderByComparator != null) {
2265                            String[] orderByFields = orderByComparator.getOrderByFields();
2266    
2267                            if (orderByFields.length > 0) {
2268                                    query.append(WHERE_AND);
2269                            }
2270    
2271                            for (int i = 0; i < orderByFields.length; i++) {
2272                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2273                                    query.append(orderByFields[i]);
2274    
2275                                    if ((i + 1) < orderByFields.length) {
2276                                            if (orderByComparator.isAscending() ^ previous) {
2277                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2278                                            }
2279                                            else {
2280                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2281                                            }
2282                                    }
2283                                    else {
2284                                            if (orderByComparator.isAscending() ^ previous) {
2285                                                    query.append(WHERE_GREATER_THAN);
2286                                            }
2287                                            else {
2288                                                    query.append(WHERE_LESSER_THAN);
2289                                            }
2290                                    }
2291                            }
2292    
2293                            query.append(ORDER_BY_CLAUSE);
2294    
2295                            for (int i = 0; i < orderByFields.length; i++) {
2296                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2297                                    query.append(orderByFields[i]);
2298    
2299                                    if ((i + 1) < orderByFields.length) {
2300                                            if (orderByComparator.isAscending() ^ previous) {
2301                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2302                                            }
2303                                            else {
2304                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2305                                            }
2306                                    }
2307                                    else {
2308                                            if (orderByComparator.isAscending() ^ previous) {
2309                                                    query.append(ORDER_BY_ASC);
2310                                            }
2311                                            else {
2312                                                    query.append(ORDER_BY_DESC);
2313                                            }
2314                                    }
2315                            }
2316                    }
2317    
2318                    else {
2319                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2320                    }
2321    
2322                    String sql = query.toString();
2323    
2324                    Query q = session.createQuery(sql);
2325    
2326                    q.setFirstResult(0);
2327                    q.setMaxResults(2);
2328    
2329                    QueryPos qPos = QueryPos.getInstance(q);
2330    
2331                    qPos.add(threadId);
2332    
2333                    if (orderByComparator != null) {
2334                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
2335    
2336                            for (Object value : values) {
2337                                    qPos.add(value);
2338                            }
2339                    }
2340    
2341                    List<MBMessage> list = q.list();
2342    
2343                    if (list.size() == 2) {
2344                            return list.get(1);
2345                    }
2346                    else {
2347                            return null;
2348                    }
2349            }
2350    
2351            /**
2352             * Finds all the message-boards messages where threadId = &#63;.
2353             *
2354             * @param threadId the thread id to search with
2355             * @return the matching message-boards messages
2356             * @throws SystemException if a system exception occurred
2357             */
2358            public List<MBMessage> findByThreadReplies(long threadId)
2359                    throws SystemException {
2360                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
2361                            QueryUtil.ALL_POS, null);
2362            }
2363    
2364            /**
2365             * Finds a range of all the message-boards messages where threadId = &#63;.
2366             *
2367             * <p>
2368             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2369             * </p>
2370             *
2371             * @param threadId the thread id to search with
2372             * @param start the lower bound of the range of message-boards messages to return
2373             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
2374             * @return the range of matching message-boards messages
2375             * @throws SystemException if a system exception occurred
2376             */
2377            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
2378                    throws SystemException {
2379                    return findByThreadReplies(threadId, start, end, null);
2380            }
2381    
2382            /**
2383             * Finds an ordered range of all the message-boards messages where threadId = &#63;.
2384             *
2385             * <p>
2386             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2387             * </p>
2388             *
2389             * @param threadId the thread id to search with
2390             * @param start the lower bound of the range of message-boards messages to return
2391             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
2392             * @param orderByComparator the comparator to order the results by
2393             * @return the ordered range of matching message-boards messages
2394             * @throws SystemException if a system exception occurred
2395             */
2396            public List<MBMessage> findByThreadReplies(long threadId, int start,
2397                    int end, OrderByComparator orderByComparator) throws SystemException {
2398                    Object[] finderArgs = new Object[] {
2399                                    threadId,
2400                                    
2401                                    String.valueOf(start), String.valueOf(end),
2402                                    String.valueOf(orderByComparator)
2403                            };
2404    
2405                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADREPLIES,
2406                                    finderArgs, this);
2407    
2408                    if (list == null) {
2409                            Session session = null;
2410    
2411                            try {
2412                                    session = openSession();
2413    
2414                                    StringBundler query = null;
2415    
2416                                    if (orderByComparator != null) {
2417                                            query = new StringBundler(3 +
2418                                                            (orderByComparator.getOrderByFields().length * 3));
2419                                    }
2420                                    else {
2421                                            query = new StringBundler(3);
2422                                    }
2423    
2424                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2425    
2426                                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
2427    
2428                                    if (orderByComparator != null) {
2429                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2430                                                    orderByComparator);
2431                                    }
2432    
2433                                    else {
2434                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2435                                    }
2436    
2437                                    String sql = query.toString();
2438    
2439                                    Query q = session.createQuery(sql);
2440    
2441                                    QueryPos qPos = QueryPos.getInstance(q);
2442    
2443                                    qPos.add(threadId);
2444    
2445                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2446                                                    end);
2447                            }
2448                            catch (Exception e) {
2449                                    throw processException(e);
2450                            }
2451                            finally {
2452                                    if (list == null) {
2453                                            list = new ArrayList<MBMessage>();
2454                                    }
2455    
2456                                    cacheResult(list);
2457    
2458                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADREPLIES,
2459                                            finderArgs, list);
2460    
2461                                    closeSession(session);
2462                            }
2463                    }
2464    
2465                    return list;
2466            }
2467    
2468            /**
2469             * Finds the first message-boards message in the ordered set where threadId = &#63;.
2470             *
2471             * <p>
2472             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2473             * </p>
2474             *
2475             * @param threadId the thread id to search with
2476             * @param orderByComparator the comparator to order the set by
2477             * @return the first matching message-boards message
2478             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2479             * @throws SystemException if a system exception occurred
2480             */
2481            public MBMessage findByThreadReplies_First(long threadId,
2482                    OrderByComparator orderByComparator)
2483                    throws NoSuchMessageException, SystemException {
2484                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
2485                                    orderByComparator);
2486    
2487                    if (list.isEmpty()) {
2488                            StringBundler msg = new StringBundler(4);
2489    
2490                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2491    
2492                            msg.append("threadId=");
2493                            msg.append(threadId);
2494    
2495                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2496    
2497                            throw new NoSuchMessageException(msg.toString());
2498                    }
2499                    else {
2500                            return list.get(0);
2501                    }
2502            }
2503    
2504            /**
2505             * Finds the last message-boards message in the ordered set where threadId = &#63;.
2506             *
2507             * <p>
2508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2509             * </p>
2510             *
2511             * @param threadId the thread id to search with
2512             * @param orderByComparator the comparator to order the set by
2513             * @return the last matching message-boards message
2514             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2515             * @throws SystemException if a system exception occurred
2516             */
2517            public MBMessage findByThreadReplies_Last(long threadId,
2518                    OrderByComparator orderByComparator)
2519                    throws NoSuchMessageException, SystemException {
2520                    int count = countByThreadReplies(threadId);
2521    
2522                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
2523                                    orderByComparator);
2524    
2525                    if (list.isEmpty()) {
2526                            StringBundler msg = new StringBundler(4);
2527    
2528                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2529    
2530                            msg.append("threadId=");
2531                            msg.append(threadId);
2532    
2533                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2534    
2535                            throw new NoSuchMessageException(msg.toString());
2536                    }
2537                    else {
2538                            return list.get(0);
2539                    }
2540            }
2541    
2542            /**
2543             * Finds the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
2544             *
2545             * <p>
2546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2547             * </p>
2548             *
2549             * @param messageId the primary key of the current message-boards message
2550             * @param threadId the thread id to search with
2551             * @param orderByComparator the comparator to order the set by
2552             * @return the previous, current, and next message-boards message
2553             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2554             * @throws SystemException if a system exception occurred
2555             */
2556            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
2557                    long threadId, OrderByComparator orderByComparator)
2558                    throws NoSuchMessageException, SystemException {
2559                    MBMessage mbMessage = findByPrimaryKey(messageId);
2560    
2561                    Session session = null;
2562    
2563                    try {
2564                            session = openSession();
2565    
2566                            MBMessage[] array = new MBMessageImpl[3];
2567    
2568                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
2569                                            threadId, orderByComparator, true);
2570    
2571                            array[1] = mbMessage;
2572    
2573                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
2574                                            threadId, orderByComparator, false);
2575    
2576                            return array;
2577                    }
2578                    catch (Exception e) {
2579                            throw processException(e);
2580                    }
2581                    finally {
2582                            closeSession(session);
2583                    }
2584            }
2585    
2586            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
2587                    MBMessage mbMessage, long threadId,
2588                    OrderByComparator orderByComparator, boolean previous) {
2589                    StringBundler query = null;
2590    
2591                    if (orderByComparator != null) {
2592                            query = new StringBundler(6 +
2593                                            (orderByComparator.getOrderByFields().length * 6));
2594                    }
2595                    else {
2596                            query = new StringBundler(3);
2597                    }
2598    
2599                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2600    
2601                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
2602    
2603                    if (orderByComparator != null) {
2604                            String[] orderByFields = orderByComparator.getOrderByFields();
2605    
2606                            if (orderByFields.length > 0) {
2607                                    query.append(WHERE_AND);
2608                            }
2609    
2610                            for (int i = 0; i < orderByFields.length; i++) {
2611                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2612                                    query.append(orderByFields[i]);
2613    
2614                                    if ((i + 1) < orderByFields.length) {
2615                                            if (orderByComparator.isAscending() ^ previous) {
2616                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2617                                            }
2618                                            else {
2619                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2620                                            }
2621                                    }
2622                                    else {
2623                                            if (orderByComparator.isAscending() ^ previous) {
2624                                                    query.append(WHERE_GREATER_THAN);
2625                                            }
2626                                            else {
2627                                                    query.append(WHERE_LESSER_THAN);
2628                                            }
2629                                    }
2630                            }
2631    
2632                            query.append(ORDER_BY_CLAUSE);
2633    
2634                            for (int i = 0; i < orderByFields.length; i++) {
2635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2636                                    query.append(orderByFields[i]);
2637    
2638                                    if ((i + 1) < orderByFields.length) {
2639                                            if (orderByComparator.isAscending() ^ previous) {
2640                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2641                                            }
2642                                            else {
2643                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2644                                            }
2645                                    }
2646                                    else {
2647                                            if (orderByComparator.isAscending() ^ previous) {
2648                                                    query.append(ORDER_BY_ASC);
2649                                            }
2650                                            else {
2651                                                    query.append(ORDER_BY_DESC);
2652                                            }
2653                                    }
2654                            }
2655                    }
2656    
2657                    else {
2658                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2659                    }
2660    
2661                    String sql = query.toString();
2662    
2663                    Query q = session.createQuery(sql);
2664    
2665                    q.setFirstResult(0);
2666                    q.setMaxResults(2);
2667    
2668                    QueryPos qPos = QueryPos.getInstance(q);
2669    
2670                    qPos.add(threadId);
2671    
2672                    if (orderByComparator != null) {
2673                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
2674    
2675                            for (Object value : values) {
2676                                    qPos.add(value);
2677                            }
2678                    }
2679    
2680                    List<MBMessage> list = q.list();
2681    
2682                    if (list.size() == 2) {
2683                            return list.get(1);
2684                    }
2685                    else {
2686                            return null;
2687                    }
2688            }
2689    
2690            /**
2691             * Finds all the message-boards messages where userId = &#63;.
2692             *
2693             * @param userId the user id to search with
2694             * @return the matching message-boards messages
2695             * @throws SystemException if a system exception occurred
2696             */
2697            public List<MBMessage> findByUserId(long userId) throws SystemException {
2698                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2699            }
2700    
2701            /**
2702             * Finds a range of all the message-boards messages where userId = &#63;.
2703             *
2704             * <p>
2705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2706             * </p>
2707             *
2708             * @param userId the user id to search with
2709             * @param start the lower bound of the range of message-boards messages to return
2710             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
2711             * @return the range of matching message-boards messages
2712             * @throws SystemException if a system exception occurred
2713             */
2714            public List<MBMessage> findByUserId(long userId, int start, int end)
2715                    throws SystemException {
2716                    return findByUserId(userId, start, end, null);
2717            }
2718    
2719            /**
2720             * Finds an ordered range of all the message-boards messages where userId = &#63;.
2721             *
2722             * <p>
2723             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2724             * </p>
2725             *
2726             * @param userId the user id to search with
2727             * @param start the lower bound of the range of message-boards messages to return
2728             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
2729             * @param orderByComparator the comparator to order the results by
2730             * @return the ordered range of matching message-boards messages
2731             * @throws SystemException if a system exception occurred
2732             */
2733            public List<MBMessage> findByUserId(long userId, int start, int end,
2734                    OrderByComparator orderByComparator) throws SystemException {
2735                    Object[] finderArgs = new Object[] {
2736                                    userId,
2737                                    
2738                                    String.valueOf(start), String.valueOf(end),
2739                                    String.valueOf(orderByComparator)
2740                            };
2741    
2742                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
2743                                    finderArgs, this);
2744    
2745                    if (list == null) {
2746                            Session session = null;
2747    
2748                            try {
2749                                    session = openSession();
2750    
2751                                    StringBundler query = null;
2752    
2753                                    if (orderByComparator != null) {
2754                                            query = new StringBundler(3 +
2755                                                            (orderByComparator.getOrderByFields().length * 3));
2756                                    }
2757                                    else {
2758                                            query = new StringBundler(3);
2759                                    }
2760    
2761                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2762    
2763                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2764    
2765                                    if (orderByComparator != null) {
2766                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2767                                                    orderByComparator);
2768                                    }
2769    
2770                                    else {
2771                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2772                                    }
2773    
2774                                    String sql = query.toString();
2775    
2776                                    Query q = session.createQuery(sql);
2777    
2778                                    QueryPos qPos = QueryPos.getInstance(q);
2779    
2780                                    qPos.add(userId);
2781    
2782                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2783                                                    end);
2784                            }
2785                            catch (Exception e) {
2786                                    throw processException(e);
2787                            }
2788                            finally {
2789                                    if (list == null) {
2790                                            list = new ArrayList<MBMessage>();
2791                                    }
2792    
2793                                    cacheResult(list);
2794    
2795                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
2796                                            finderArgs, list);
2797    
2798                                    closeSession(session);
2799                            }
2800                    }
2801    
2802                    return list;
2803            }
2804    
2805            /**
2806             * Finds the first message-boards message in the ordered set where userId = &#63;.
2807             *
2808             * <p>
2809             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2810             * </p>
2811             *
2812             * @param userId the user id to search with
2813             * @param orderByComparator the comparator to order the set by
2814             * @return the first matching message-boards message
2815             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2816             * @throws SystemException if a system exception occurred
2817             */
2818            public MBMessage findByUserId_First(long userId,
2819                    OrderByComparator orderByComparator)
2820                    throws NoSuchMessageException, SystemException {
2821                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
2822    
2823                    if (list.isEmpty()) {
2824                            StringBundler msg = new StringBundler(4);
2825    
2826                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2827    
2828                            msg.append("userId=");
2829                            msg.append(userId);
2830    
2831                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2832    
2833                            throw new NoSuchMessageException(msg.toString());
2834                    }
2835                    else {
2836                            return list.get(0);
2837                    }
2838            }
2839    
2840            /**
2841             * Finds the last message-boards message in the ordered set where userId = &#63;.
2842             *
2843             * <p>
2844             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2845             * </p>
2846             *
2847             * @param userId the user id to search with
2848             * @param orderByComparator the comparator to order the set by
2849             * @return the last matching message-boards message
2850             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2851             * @throws SystemException if a system exception occurred
2852             */
2853            public MBMessage findByUserId_Last(long userId,
2854                    OrderByComparator orderByComparator)
2855                    throws NoSuchMessageException, SystemException {
2856                    int count = countByUserId(userId);
2857    
2858                    List<MBMessage> list = findByUserId(userId, count - 1, count,
2859                                    orderByComparator);
2860    
2861                    if (list.isEmpty()) {
2862                            StringBundler msg = new StringBundler(4);
2863    
2864                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2865    
2866                            msg.append("userId=");
2867                            msg.append(userId);
2868    
2869                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2870    
2871                            throw new NoSuchMessageException(msg.toString());
2872                    }
2873                    else {
2874                            return list.get(0);
2875                    }
2876            }
2877    
2878            /**
2879             * Finds the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
2880             *
2881             * <p>
2882             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2883             * </p>
2884             *
2885             * @param messageId the primary key of the current message-boards message
2886             * @param userId the user id to search with
2887             * @param orderByComparator the comparator to order the set by
2888             * @return the previous, current, and next message-boards message
2889             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2890             * @throws SystemException if a system exception occurred
2891             */
2892            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
2893                    OrderByComparator orderByComparator)
2894                    throws NoSuchMessageException, SystemException {
2895                    MBMessage mbMessage = findByPrimaryKey(messageId);
2896    
2897                    Session session = null;
2898    
2899                    try {
2900                            session = openSession();
2901    
2902                            MBMessage[] array = new MBMessageImpl[3];
2903    
2904                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
2905                                            orderByComparator, true);
2906    
2907                            array[1] = mbMessage;
2908    
2909                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
2910                                            orderByComparator, false);
2911    
2912                            return array;
2913                    }
2914                    catch (Exception e) {
2915                            throw processException(e);
2916                    }
2917                    finally {
2918                            closeSession(session);
2919                    }
2920            }
2921    
2922            protected MBMessage getByUserId_PrevAndNext(Session session,
2923                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
2924                    boolean previous) {
2925                    StringBundler query = null;
2926    
2927                    if (orderByComparator != null) {
2928                            query = new StringBundler(6 +
2929                                            (orderByComparator.getOrderByFields().length * 6));
2930                    }
2931                    else {
2932                            query = new StringBundler(3);
2933                    }
2934    
2935                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2936    
2937                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2938    
2939                    if (orderByComparator != null) {
2940                            String[] orderByFields = orderByComparator.getOrderByFields();
2941    
2942                            if (orderByFields.length > 0) {
2943                                    query.append(WHERE_AND);
2944                            }
2945    
2946                            for (int i = 0; i < orderByFields.length; i++) {
2947                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2948                                    query.append(orderByFields[i]);
2949    
2950                                    if ((i + 1) < orderByFields.length) {
2951                                            if (orderByComparator.isAscending() ^ previous) {
2952                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2953                                            }
2954                                            else {
2955                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2956                                            }
2957                                    }
2958                                    else {
2959                                            if (orderByComparator.isAscending() ^ previous) {
2960                                                    query.append(WHERE_GREATER_THAN);
2961                                            }
2962                                            else {
2963                                                    query.append(WHERE_LESSER_THAN);
2964                                            }
2965                                    }
2966                            }
2967    
2968                            query.append(ORDER_BY_CLAUSE);
2969    
2970                            for (int i = 0; i < orderByFields.length; i++) {
2971                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2972                                    query.append(orderByFields[i]);
2973    
2974                                    if ((i + 1) < orderByFields.length) {
2975                                            if (orderByComparator.isAscending() ^ previous) {
2976                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2977                                            }
2978                                            else {
2979                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2980                                            }
2981                                    }
2982                                    else {
2983                                            if (orderByComparator.isAscending() ^ previous) {
2984                                                    query.append(ORDER_BY_ASC);
2985                                            }
2986                                            else {
2987                                                    query.append(ORDER_BY_DESC);
2988                                            }
2989                                    }
2990                            }
2991                    }
2992    
2993                    else {
2994                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2995                    }
2996    
2997                    String sql = query.toString();
2998    
2999                    Query q = session.createQuery(sql);
3000    
3001                    q.setFirstResult(0);
3002                    q.setMaxResults(2);
3003    
3004                    QueryPos qPos = QueryPos.getInstance(q);
3005    
3006                    qPos.add(userId);
3007    
3008                    if (orderByComparator != null) {
3009                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
3010    
3011                            for (Object value : values) {
3012                                    qPos.add(value);
3013                            }
3014                    }
3015    
3016                    List<MBMessage> list = q.list();
3017    
3018                    if (list.size() == 2) {
3019                            return list.get(1);
3020                    }
3021                    else {
3022                            return null;
3023                    }
3024            }
3025    
3026            /**
3027             * Finds all the message-boards messages where groupId = &#63; and userId = &#63;.
3028             *
3029             * @param groupId the group id to search with
3030             * @param userId the user id to search with
3031             * @return the matching message-boards messages
3032             * @throws SystemException if a system exception occurred
3033             */
3034            public List<MBMessage> findByG_U(long groupId, long userId)
3035                    throws SystemException {
3036                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3037                            null);
3038            }
3039    
3040            /**
3041             * Finds a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
3042             *
3043             * <p>
3044             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3045             * </p>
3046             *
3047             * @param groupId the group id to search with
3048             * @param userId the user id to search with
3049             * @param start the lower bound of the range of message-boards messages to return
3050             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3051             * @return the range of matching message-boards messages
3052             * @throws SystemException if a system exception occurred
3053             */
3054            public List<MBMessage> findByG_U(long groupId, long userId, int start,
3055                    int end) throws SystemException {
3056                    return findByG_U(groupId, userId, start, end, null);
3057            }
3058    
3059            /**
3060             * Finds an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
3061             *
3062             * <p>
3063             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3064             * </p>
3065             *
3066             * @param groupId the group id to search with
3067             * @param userId the user id to search with
3068             * @param start the lower bound of the range of message-boards messages to return
3069             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3070             * @param orderByComparator the comparator to order the results by
3071             * @return the ordered range of matching message-boards messages
3072             * @throws SystemException if a system exception occurred
3073             */
3074            public List<MBMessage> findByG_U(long groupId, long userId, int start,
3075                    int end, OrderByComparator orderByComparator) throws SystemException {
3076                    Object[] finderArgs = new Object[] {
3077                                    groupId, userId,
3078                                    
3079                                    String.valueOf(start), String.valueOf(end),
3080                                    String.valueOf(orderByComparator)
3081                            };
3082    
3083                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
3084                                    finderArgs, this);
3085    
3086                    if (list == null) {
3087                            Session session = null;
3088    
3089                            try {
3090                                    session = openSession();
3091    
3092                                    StringBundler query = null;
3093    
3094                                    if (orderByComparator != null) {
3095                                            query = new StringBundler(4 +
3096                                                            (orderByComparator.getOrderByFields().length * 3));
3097                                    }
3098                                    else {
3099                                            query = new StringBundler(4);
3100                                    }
3101    
3102                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3103    
3104                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3105    
3106                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
3107    
3108                                    if (orderByComparator != null) {
3109                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3110                                                    orderByComparator);
3111                                    }
3112    
3113                                    else {
3114                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3115                                    }
3116    
3117                                    String sql = query.toString();
3118    
3119                                    Query q = session.createQuery(sql);
3120    
3121                                    QueryPos qPos = QueryPos.getInstance(q);
3122    
3123                                    qPos.add(groupId);
3124    
3125                                    qPos.add(userId);
3126    
3127                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3128                                                    end);
3129                            }
3130                            catch (Exception e) {
3131                                    throw processException(e);
3132                            }
3133                            finally {
3134                                    if (list == null) {
3135                                            list = new ArrayList<MBMessage>();
3136                                    }
3137    
3138                                    cacheResult(list);
3139    
3140                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
3141                                            list);
3142    
3143                                    closeSession(session);
3144                            }
3145                    }
3146    
3147                    return list;
3148            }
3149    
3150            /**
3151             * Finds the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
3152             *
3153             * <p>
3154             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3155             * </p>
3156             *
3157             * @param groupId the group id to search with
3158             * @param userId the user id to search with
3159             * @param orderByComparator the comparator to order the set by
3160             * @return the first matching message-boards message
3161             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3162             * @throws SystemException if a system exception occurred
3163             */
3164            public MBMessage findByG_U_First(long groupId, long userId,
3165                    OrderByComparator orderByComparator)
3166                    throws NoSuchMessageException, SystemException {
3167                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
3168                                    orderByComparator);
3169    
3170                    if (list.isEmpty()) {
3171                            StringBundler msg = new StringBundler(6);
3172    
3173                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3174    
3175                            msg.append("groupId=");
3176                            msg.append(groupId);
3177    
3178                            msg.append(", userId=");
3179                            msg.append(userId);
3180    
3181                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3182    
3183                            throw new NoSuchMessageException(msg.toString());
3184                    }
3185                    else {
3186                            return list.get(0);
3187                    }
3188            }
3189    
3190            /**
3191             * Finds the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
3192             *
3193             * <p>
3194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3195             * </p>
3196             *
3197             * @param groupId the group id to search with
3198             * @param userId the user id to search with
3199             * @param orderByComparator the comparator to order the set by
3200             * @return the last matching message-boards message
3201             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3202             * @throws SystemException if a system exception occurred
3203             */
3204            public MBMessage findByG_U_Last(long groupId, long userId,
3205                    OrderByComparator orderByComparator)
3206                    throws NoSuchMessageException, SystemException {
3207                    int count = countByG_U(groupId, userId);
3208    
3209                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
3210                                    orderByComparator);
3211    
3212                    if (list.isEmpty()) {
3213                            StringBundler msg = new StringBundler(6);
3214    
3215                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3216    
3217                            msg.append("groupId=");
3218                            msg.append(groupId);
3219    
3220                            msg.append(", userId=");
3221                            msg.append(userId);
3222    
3223                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3224    
3225                            throw new NoSuchMessageException(msg.toString());
3226                    }
3227                    else {
3228                            return list.get(0);
3229                    }
3230            }
3231    
3232            /**
3233             * Finds the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
3234             *
3235             * <p>
3236             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3237             * </p>
3238             *
3239             * @param messageId the primary key of the current message-boards message
3240             * @param groupId the group id to search with
3241             * @param userId the user id to search with
3242             * @param orderByComparator the comparator to order the set by
3243             * @return the previous, current, and next message-boards message
3244             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3245             * @throws SystemException if a system exception occurred
3246             */
3247            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
3248                    long userId, OrderByComparator orderByComparator)
3249                    throws NoSuchMessageException, SystemException {
3250                    MBMessage mbMessage = findByPrimaryKey(messageId);
3251    
3252                    Session session = null;
3253    
3254                    try {
3255                            session = openSession();
3256    
3257                            MBMessage[] array = new MBMessageImpl[3];
3258    
3259                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
3260                                            userId, orderByComparator, true);
3261    
3262                            array[1] = mbMessage;
3263    
3264                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
3265                                            userId, orderByComparator, false);
3266    
3267                            return array;
3268                    }
3269                    catch (Exception e) {
3270                            throw processException(e);
3271                    }
3272                    finally {
3273                            closeSession(session);
3274                    }
3275            }
3276    
3277            protected MBMessage getByG_U_PrevAndNext(Session session,
3278                    MBMessage mbMessage, long groupId, long userId,
3279                    OrderByComparator orderByComparator, boolean previous) {
3280                    StringBundler query = null;
3281    
3282                    if (orderByComparator != null) {
3283                            query = new StringBundler(6 +
3284                                            (orderByComparator.getOrderByFields().length * 6));
3285                    }
3286                    else {
3287                            query = new StringBundler(3);
3288                    }
3289    
3290                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3291    
3292                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3293    
3294                    query.append(_FINDER_COLUMN_G_U_USERID_2);
3295    
3296                    if (orderByComparator != null) {
3297                            String[] orderByFields = orderByComparator.getOrderByFields();
3298    
3299                            if (orderByFields.length > 0) {
3300                                    query.append(WHERE_AND);
3301                            }
3302    
3303                            for (int i = 0; i < orderByFields.length; i++) {
3304                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3305                                    query.append(orderByFields[i]);
3306    
3307                                    if ((i + 1) < orderByFields.length) {
3308                                            if (orderByComparator.isAscending() ^ previous) {
3309                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3310                                            }
3311                                            else {
3312                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3313                                            }
3314                                    }
3315                                    else {
3316                                            if (orderByComparator.isAscending() ^ previous) {
3317                                                    query.append(WHERE_GREATER_THAN);
3318                                            }
3319                                            else {
3320                                                    query.append(WHERE_LESSER_THAN);
3321                                            }
3322                                    }
3323                            }
3324    
3325                            query.append(ORDER_BY_CLAUSE);
3326    
3327                            for (int i = 0; i < orderByFields.length; i++) {
3328                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3329                                    query.append(orderByFields[i]);
3330    
3331                                    if ((i + 1) < orderByFields.length) {
3332                                            if (orderByComparator.isAscending() ^ previous) {
3333                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3334                                            }
3335                                            else {
3336                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3337                                            }
3338                                    }
3339                                    else {
3340                                            if (orderByComparator.isAscending() ^ previous) {
3341                                                    query.append(ORDER_BY_ASC);
3342                                            }
3343                                            else {
3344                                                    query.append(ORDER_BY_DESC);
3345                                            }
3346                                    }
3347                            }
3348                    }
3349    
3350                    else {
3351                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3352                    }
3353    
3354                    String sql = query.toString();
3355    
3356                    Query q = session.createQuery(sql);
3357    
3358                    q.setFirstResult(0);
3359                    q.setMaxResults(2);
3360    
3361                    QueryPos qPos = QueryPos.getInstance(q);
3362    
3363                    qPos.add(groupId);
3364    
3365                    qPos.add(userId);
3366    
3367                    if (orderByComparator != null) {
3368                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
3369    
3370                            for (Object value : values) {
3371                                    qPos.add(value);
3372                            }
3373                    }
3374    
3375                    List<MBMessage> list = q.list();
3376    
3377                    if (list.size() == 2) {
3378                            return list.get(1);
3379                    }
3380                    else {
3381                            return null;
3382                    }
3383            }
3384    
3385            /**
3386             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and userId = &#63;.
3387             *
3388             * @param groupId the group id to search with
3389             * @param userId the user id to search with
3390             * @return the matching message-boards messages that the user has permission to view
3391             * @throws SystemException if a system exception occurred
3392             */
3393            public List<MBMessage> filterFindByG_U(long groupId, long userId)
3394                    throws SystemException {
3395                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
3396                            QueryUtil.ALL_POS, null);
3397            }
3398    
3399            /**
3400             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
3401             *
3402             * <p>
3403             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3404             * </p>
3405             *
3406             * @param groupId the group id to search with
3407             * @param userId the user id to search with
3408             * @param start the lower bound of the range of message-boards messages to return
3409             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3410             * @return the range of matching message-boards messages that the user has permission to view
3411             * @throws SystemException if a system exception occurred
3412             */
3413            public List<MBMessage> filterFindByG_U(long groupId, long userId,
3414                    int start, int end) throws SystemException {
3415                    return filterFindByG_U(groupId, userId, start, end, null);
3416            }
3417    
3418            /**
3419             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
3420             *
3421             * <p>
3422             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3423             * </p>
3424             *
3425             * @param groupId the group id to search with
3426             * @param userId the user id to search with
3427             * @param start the lower bound of the range of message-boards messages to return
3428             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3429             * @param orderByComparator the comparator to order the results by
3430             * @return the ordered range of matching message-boards messages that the user has permission to view
3431             * @throws SystemException if a system exception occurred
3432             */
3433            public List<MBMessage> filterFindByG_U(long groupId, long userId,
3434                    int start, int end, OrderByComparator orderByComparator)
3435                    throws SystemException {
3436                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3437                            return findByG_U(groupId, userId, start, end, orderByComparator);
3438                    }
3439    
3440                    Session session = null;
3441    
3442                    try {
3443                            session = openSession();
3444    
3445                            StringBundler query = null;
3446    
3447                            if (orderByComparator != null) {
3448                                    query = new StringBundler(4 +
3449                                                    (orderByComparator.getOrderByFields().length * 3));
3450                            }
3451                            else {
3452                                    query = new StringBundler(4);
3453                            }
3454    
3455                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
3456    
3457                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3458    
3459                            query.append(_FINDER_COLUMN_G_U_USERID_2);
3460    
3461                            if (orderByComparator != null) {
3462                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3463                                            orderByComparator);
3464                            }
3465    
3466                            else {
3467                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3468                            }
3469    
3470                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3471                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
3472                                            _FILTER_COLUMN_USERID, groupId);
3473    
3474                            SQLQuery q = session.createSQLQuery(sql);
3475    
3476                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
3477    
3478                            QueryPos qPos = QueryPos.getInstance(q);
3479    
3480                            qPos.add(groupId);
3481    
3482                            qPos.add(userId);
3483    
3484                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
3485                    }
3486                    catch (Exception e) {
3487                            throw processException(e);
3488                    }
3489                    finally {
3490                            closeSession(session);
3491                    }
3492            }
3493    
3494            /**
3495             * Finds all the message-boards messages where groupId = &#63; and categoryId = &#63;.
3496             *
3497             * @param groupId the group id to search with
3498             * @param categoryId the category id to search with
3499             * @return the matching message-boards messages
3500             * @throws SystemException if a system exception occurred
3501             */
3502            public List<MBMessage> findByG_C(long groupId, long categoryId)
3503                    throws SystemException {
3504                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
3505                            QueryUtil.ALL_POS, null);
3506            }
3507    
3508            /**
3509             * Finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
3510             *
3511             * <p>
3512             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3513             * </p>
3514             *
3515             * @param groupId the group id to search with
3516             * @param categoryId the category id to search with
3517             * @param start the lower bound of the range of message-boards messages to return
3518             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3519             * @return the range of matching message-boards messages
3520             * @throws SystemException if a system exception occurred
3521             */
3522            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
3523                    int end) throws SystemException {
3524                    return findByG_C(groupId, categoryId, start, end, null);
3525            }
3526    
3527            /**
3528             * Finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
3529             *
3530             * <p>
3531             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3532             * </p>
3533             *
3534             * @param groupId the group id to search with
3535             * @param categoryId the category id to search with
3536             * @param start the lower bound of the range of message-boards messages to return
3537             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3538             * @param orderByComparator the comparator to order the results by
3539             * @return the ordered range of matching message-boards messages
3540             * @throws SystemException if a system exception occurred
3541             */
3542            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
3543                    int end, OrderByComparator orderByComparator) throws SystemException {
3544                    Object[] finderArgs = new Object[] {
3545                                    groupId, categoryId,
3546                                    
3547                                    String.valueOf(start), String.valueOf(end),
3548                                    String.valueOf(orderByComparator)
3549                            };
3550    
3551                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
3552                                    finderArgs, this);
3553    
3554                    if (list == null) {
3555                            Session session = null;
3556    
3557                            try {
3558                                    session = openSession();
3559    
3560                                    StringBundler query = null;
3561    
3562                                    if (orderByComparator != null) {
3563                                            query = new StringBundler(4 +
3564                                                            (orderByComparator.getOrderByFields().length * 3));
3565                                    }
3566                                    else {
3567                                            query = new StringBundler(4);
3568                                    }
3569    
3570                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3571    
3572                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3573    
3574                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3575    
3576                                    if (orderByComparator != null) {
3577                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3578                                                    orderByComparator);
3579                                    }
3580    
3581                                    else {
3582                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3583                                    }
3584    
3585                                    String sql = query.toString();
3586    
3587                                    Query q = session.createQuery(sql);
3588    
3589                                    QueryPos qPos = QueryPos.getInstance(q);
3590    
3591                                    qPos.add(groupId);
3592    
3593                                    qPos.add(categoryId);
3594    
3595                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3596                                                    end);
3597                            }
3598                            catch (Exception e) {
3599                                    throw processException(e);
3600                            }
3601                            finally {
3602                                    if (list == null) {
3603                                            list = new ArrayList<MBMessage>();
3604                                    }
3605    
3606                                    cacheResult(list);
3607    
3608                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
3609                                            list);
3610    
3611                                    closeSession(session);
3612                            }
3613                    }
3614    
3615                    return list;
3616            }
3617    
3618            /**
3619             * Finds the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
3620             *
3621             * <p>
3622             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3623             * </p>
3624             *
3625             * @param groupId the group id to search with
3626             * @param categoryId the category id to search with
3627             * @param orderByComparator the comparator to order the set by
3628             * @return the first matching message-boards message
3629             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3630             * @throws SystemException if a system exception occurred
3631             */
3632            public MBMessage findByG_C_First(long groupId, long categoryId,
3633                    OrderByComparator orderByComparator)
3634                    throws NoSuchMessageException, SystemException {
3635                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
3636                                    orderByComparator);
3637    
3638                    if (list.isEmpty()) {
3639                            StringBundler msg = new StringBundler(6);
3640    
3641                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3642    
3643                            msg.append("groupId=");
3644                            msg.append(groupId);
3645    
3646                            msg.append(", categoryId=");
3647                            msg.append(categoryId);
3648    
3649                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3650    
3651                            throw new NoSuchMessageException(msg.toString());
3652                    }
3653                    else {
3654                            return list.get(0);
3655                    }
3656            }
3657    
3658            /**
3659             * Finds the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
3660             *
3661             * <p>
3662             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3663             * </p>
3664             *
3665             * @param groupId the group id to search with
3666             * @param categoryId the category id to search with
3667             * @param orderByComparator the comparator to order the set by
3668             * @return the last matching message-boards message
3669             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3670             * @throws SystemException if a system exception occurred
3671             */
3672            public MBMessage findByG_C_Last(long groupId, long categoryId,
3673                    OrderByComparator orderByComparator)
3674                    throws NoSuchMessageException, SystemException {
3675                    int count = countByG_C(groupId, categoryId);
3676    
3677                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
3678                                    orderByComparator);
3679    
3680                    if (list.isEmpty()) {
3681                            StringBundler msg = new StringBundler(6);
3682    
3683                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3684    
3685                            msg.append("groupId=");
3686                            msg.append(groupId);
3687    
3688                            msg.append(", categoryId=");
3689                            msg.append(categoryId);
3690    
3691                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3692    
3693                            throw new NoSuchMessageException(msg.toString());
3694                    }
3695                    else {
3696                            return list.get(0);
3697                    }
3698            }
3699    
3700            /**
3701             * Finds the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
3702             *
3703             * <p>
3704             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3705             * </p>
3706             *
3707             * @param messageId the primary key of the current message-boards message
3708             * @param groupId the group id to search with
3709             * @param categoryId the category id to search with
3710             * @param orderByComparator the comparator to order the set by
3711             * @return the previous, current, and next message-boards message
3712             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3713             * @throws SystemException if a system exception occurred
3714             */
3715            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
3716                    long categoryId, OrderByComparator orderByComparator)
3717                    throws NoSuchMessageException, SystemException {
3718                    MBMessage mbMessage = findByPrimaryKey(messageId);
3719    
3720                    Session session = null;
3721    
3722                    try {
3723                            session = openSession();
3724    
3725                            MBMessage[] array = new MBMessageImpl[3];
3726    
3727                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
3728                                            categoryId, orderByComparator, true);
3729    
3730                            array[1] = mbMessage;
3731    
3732                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
3733                                            categoryId, orderByComparator, false);
3734    
3735                            return array;
3736                    }
3737                    catch (Exception e) {
3738                            throw processException(e);
3739                    }
3740                    finally {
3741                            closeSession(session);
3742                    }
3743            }
3744    
3745            protected MBMessage getByG_C_PrevAndNext(Session session,
3746                    MBMessage mbMessage, long groupId, long categoryId,
3747                    OrderByComparator orderByComparator, boolean previous) {
3748                    StringBundler query = null;
3749    
3750                    if (orderByComparator != null) {
3751                            query = new StringBundler(6 +
3752                                            (orderByComparator.getOrderByFields().length * 6));
3753                    }
3754                    else {
3755                            query = new StringBundler(3);
3756                    }
3757    
3758                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3759    
3760                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3761    
3762                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3763    
3764                    if (orderByComparator != null) {
3765                            String[] orderByFields = orderByComparator.getOrderByFields();
3766    
3767                            if (orderByFields.length > 0) {
3768                                    query.append(WHERE_AND);
3769                            }
3770    
3771                            for (int i = 0; i < orderByFields.length; i++) {
3772                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3773                                    query.append(orderByFields[i]);
3774    
3775                                    if ((i + 1) < orderByFields.length) {
3776                                            if (orderByComparator.isAscending() ^ previous) {
3777                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3778                                            }
3779                                            else {
3780                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3781                                            }
3782                                    }
3783                                    else {
3784                                            if (orderByComparator.isAscending() ^ previous) {
3785                                                    query.append(WHERE_GREATER_THAN);
3786                                            }
3787                                            else {
3788                                                    query.append(WHERE_LESSER_THAN);
3789                                            }
3790                                    }
3791                            }
3792    
3793                            query.append(ORDER_BY_CLAUSE);
3794    
3795                            for (int i = 0; i < orderByFields.length; i++) {
3796                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3797                                    query.append(orderByFields[i]);
3798    
3799                                    if ((i + 1) < orderByFields.length) {
3800                                            if (orderByComparator.isAscending() ^ previous) {
3801                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3802                                            }
3803                                            else {
3804                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3805                                            }
3806                                    }
3807                                    else {
3808                                            if (orderByComparator.isAscending() ^ previous) {
3809                                                    query.append(ORDER_BY_ASC);
3810                                            }
3811                                            else {
3812                                                    query.append(ORDER_BY_DESC);
3813                                            }
3814                                    }
3815                            }
3816                    }
3817    
3818                    else {
3819                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3820                    }
3821    
3822                    String sql = query.toString();
3823    
3824                    Query q = session.createQuery(sql);
3825    
3826                    q.setFirstResult(0);
3827                    q.setMaxResults(2);
3828    
3829                    QueryPos qPos = QueryPos.getInstance(q);
3830    
3831                    qPos.add(groupId);
3832    
3833                    qPos.add(categoryId);
3834    
3835                    if (orderByComparator != null) {
3836                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
3837    
3838                            for (Object value : values) {
3839                                    qPos.add(value);
3840                            }
3841                    }
3842    
3843                    List<MBMessage> list = q.list();
3844    
3845                    if (list.size() == 2) {
3846                            return list.get(1);
3847                    }
3848                    else {
3849                            return null;
3850                    }
3851            }
3852    
3853            /**
3854             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and categoryId = &#63;.
3855             *
3856             * @param groupId the group id to search with
3857             * @param categoryId the category id to search with
3858             * @return the matching message-boards messages that the user has permission to view
3859             * @throws SystemException if a system exception occurred
3860             */
3861            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
3862                    throws SystemException {
3863                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
3864                            QueryUtil.ALL_POS, null);
3865            }
3866    
3867            /**
3868             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
3869             *
3870             * <p>
3871             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3872             * </p>
3873             *
3874             * @param groupId the group id to search with
3875             * @param categoryId the category id to search with
3876             * @param start the lower bound of the range of message-boards messages to return
3877             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3878             * @return the range of matching message-boards messages that the user has permission to view
3879             * @throws SystemException if a system exception occurred
3880             */
3881            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
3882                    int start, int end) throws SystemException {
3883                    return filterFindByG_C(groupId, categoryId, start, end, null);
3884            }
3885    
3886            /**
3887             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
3888             *
3889             * <p>
3890             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3891             * </p>
3892             *
3893             * @param groupId the group id to search with
3894             * @param categoryId the category id to search with
3895             * @param start the lower bound of the range of message-boards messages to return
3896             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3897             * @param orderByComparator the comparator to order the results by
3898             * @return the ordered range of matching message-boards messages that the user has permission to view
3899             * @throws SystemException if a system exception occurred
3900             */
3901            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
3902                    int start, int end, OrderByComparator orderByComparator)
3903                    throws SystemException {
3904                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3905                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
3906                    }
3907    
3908                    Session session = null;
3909    
3910                    try {
3911                            session = openSession();
3912    
3913                            StringBundler query = null;
3914    
3915                            if (orderByComparator != null) {
3916                                    query = new StringBundler(4 +
3917                                                    (orderByComparator.getOrderByFields().length * 3));
3918                            }
3919                            else {
3920                                    query = new StringBundler(4);
3921                            }
3922    
3923                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
3924    
3925                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3926    
3927                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3928    
3929                            if (orderByComparator != null) {
3930                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3931                                            orderByComparator);
3932                            }
3933    
3934                            else {
3935                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3936                            }
3937    
3938                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3939                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
3940                                            _FILTER_COLUMN_USERID, groupId);
3941    
3942                            SQLQuery q = session.createSQLQuery(sql);
3943    
3944                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
3945    
3946                            QueryPos qPos = QueryPos.getInstance(q);
3947    
3948                            qPos.add(groupId);
3949    
3950                            qPos.add(categoryId);
3951    
3952                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
3953                    }
3954                    catch (Exception e) {
3955                            throw processException(e);
3956                    }
3957                    finally {
3958                            closeSession(session);
3959                    }
3960            }
3961    
3962            /**
3963             * Finds all the message-boards messages where groupId = &#63; and status = &#63;.
3964             *
3965             * @param groupId the group id to search with
3966             * @param status the status to search with
3967             * @return the matching message-boards messages
3968             * @throws SystemException if a system exception occurred
3969             */
3970            public List<MBMessage> findByG_S(long groupId, int status)
3971                    throws SystemException {
3972                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3973                            null);
3974            }
3975    
3976            /**
3977             * Finds a range of all the message-boards messages where groupId = &#63; and status = &#63;.
3978             *
3979             * <p>
3980             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3981             * </p>
3982             *
3983             * @param groupId the group id to search with
3984             * @param status the status to search with
3985             * @param start the lower bound of the range of message-boards messages to return
3986             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
3987             * @return the range of matching message-boards messages
3988             * @throws SystemException if a system exception occurred
3989             */
3990            public List<MBMessage> findByG_S(long groupId, int status, int start,
3991                    int end) throws SystemException {
3992                    return findByG_S(groupId, status, start, end, null);
3993            }
3994    
3995            /**
3996             * Finds an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
3997             *
3998             * <p>
3999             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4000             * </p>
4001             *
4002             * @param groupId the group id to search with
4003             * @param status the status to search with
4004             * @param start the lower bound of the range of message-boards messages to return
4005             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4006             * @param orderByComparator the comparator to order the results by
4007             * @return the ordered range of matching message-boards messages
4008             * @throws SystemException if a system exception occurred
4009             */
4010            public List<MBMessage> findByG_S(long groupId, int status, int start,
4011                    int end, OrderByComparator orderByComparator) throws SystemException {
4012                    Object[] finderArgs = new Object[] {
4013                                    groupId, status,
4014                                    
4015                                    String.valueOf(start), String.valueOf(end),
4016                                    String.valueOf(orderByComparator)
4017                            };
4018    
4019                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
4020                                    finderArgs, this);
4021    
4022                    if (list == null) {
4023                            Session session = null;
4024    
4025                            try {
4026                                    session = openSession();
4027    
4028                                    StringBundler query = null;
4029    
4030                                    if (orderByComparator != null) {
4031                                            query = new StringBundler(4 +
4032                                                            (orderByComparator.getOrderByFields().length * 3));
4033                                    }
4034                                    else {
4035                                            query = new StringBundler(4);
4036                                    }
4037    
4038                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4039    
4040                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4041    
4042                                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4043    
4044                                    if (orderByComparator != null) {
4045                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4046                                                    orderByComparator);
4047                                    }
4048    
4049                                    else {
4050                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4051                                    }
4052    
4053                                    String sql = query.toString();
4054    
4055                                    Query q = session.createQuery(sql);
4056    
4057                                    QueryPos qPos = QueryPos.getInstance(q);
4058    
4059                                    qPos.add(groupId);
4060    
4061                                    qPos.add(status);
4062    
4063                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4064                                                    end);
4065                            }
4066                            catch (Exception e) {
4067                                    throw processException(e);
4068                            }
4069                            finally {
4070                                    if (list == null) {
4071                                            list = new ArrayList<MBMessage>();
4072                                    }
4073    
4074                                    cacheResult(list);
4075    
4076                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S, finderArgs,
4077                                            list);
4078    
4079                                    closeSession(session);
4080                            }
4081                    }
4082    
4083                    return list;
4084            }
4085    
4086            /**
4087             * Finds the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
4088             *
4089             * <p>
4090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4091             * </p>
4092             *
4093             * @param groupId the group id to search with
4094             * @param status the status to search with
4095             * @param orderByComparator the comparator to order the set by
4096             * @return the first matching message-boards message
4097             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4098             * @throws SystemException if a system exception occurred
4099             */
4100            public MBMessage findByG_S_First(long groupId, int status,
4101                    OrderByComparator orderByComparator)
4102                    throws NoSuchMessageException, SystemException {
4103                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
4104                                    orderByComparator);
4105    
4106                    if (list.isEmpty()) {
4107                            StringBundler msg = new StringBundler(6);
4108    
4109                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4110    
4111                            msg.append("groupId=");
4112                            msg.append(groupId);
4113    
4114                            msg.append(", status=");
4115                            msg.append(status);
4116    
4117                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4118    
4119                            throw new NoSuchMessageException(msg.toString());
4120                    }
4121                    else {
4122                            return list.get(0);
4123                    }
4124            }
4125    
4126            /**
4127             * Finds the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
4128             *
4129             * <p>
4130             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4131             * </p>
4132             *
4133             * @param groupId the group id to search with
4134             * @param status the status to search with
4135             * @param orderByComparator the comparator to order the set by
4136             * @return the last matching message-boards message
4137             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4138             * @throws SystemException if a system exception occurred
4139             */
4140            public MBMessage findByG_S_Last(long groupId, int status,
4141                    OrderByComparator orderByComparator)
4142                    throws NoSuchMessageException, SystemException {
4143                    int count = countByG_S(groupId, status);
4144    
4145                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
4146                                    orderByComparator);
4147    
4148                    if (list.isEmpty()) {
4149                            StringBundler msg = new StringBundler(6);
4150    
4151                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4152    
4153                            msg.append("groupId=");
4154                            msg.append(groupId);
4155    
4156                            msg.append(", status=");
4157                            msg.append(status);
4158    
4159                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4160    
4161                            throw new NoSuchMessageException(msg.toString());
4162                    }
4163                    else {
4164                            return list.get(0);
4165                    }
4166            }
4167    
4168            /**
4169             * Finds the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
4170             *
4171             * <p>
4172             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4173             * </p>
4174             *
4175             * @param messageId the primary key of the current message-boards message
4176             * @param groupId the group id to search with
4177             * @param status the status to search with
4178             * @param orderByComparator the comparator to order the set by
4179             * @return the previous, current, and next message-boards message
4180             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4181             * @throws SystemException if a system exception occurred
4182             */
4183            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
4184                    int status, OrderByComparator orderByComparator)
4185                    throws NoSuchMessageException, SystemException {
4186                    MBMessage mbMessage = findByPrimaryKey(messageId);
4187    
4188                    Session session = null;
4189    
4190                    try {
4191                            session = openSession();
4192    
4193                            MBMessage[] array = new MBMessageImpl[3];
4194    
4195                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
4196                                            status, orderByComparator, true);
4197    
4198                            array[1] = mbMessage;
4199    
4200                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
4201                                            status, orderByComparator, false);
4202    
4203                            return array;
4204                    }
4205                    catch (Exception e) {
4206                            throw processException(e);
4207                    }
4208                    finally {
4209                            closeSession(session);
4210                    }
4211            }
4212    
4213            protected MBMessage getByG_S_PrevAndNext(Session session,
4214                    MBMessage mbMessage, long groupId, int status,
4215                    OrderByComparator orderByComparator, boolean previous) {
4216                    StringBundler query = null;
4217    
4218                    if (orderByComparator != null) {
4219                            query = new StringBundler(6 +
4220                                            (orderByComparator.getOrderByFields().length * 6));
4221                    }
4222                    else {
4223                            query = new StringBundler(3);
4224                    }
4225    
4226                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4227    
4228                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4229    
4230                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4231    
4232                    if (orderByComparator != null) {
4233                            String[] orderByFields = orderByComparator.getOrderByFields();
4234    
4235                            if (orderByFields.length > 0) {
4236                                    query.append(WHERE_AND);
4237                            }
4238    
4239                            for (int i = 0; i < orderByFields.length; i++) {
4240                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4241                                    query.append(orderByFields[i]);
4242    
4243                                    if ((i + 1) < orderByFields.length) {
4244                                            if (orderByComparator.isAscending() ^ previous) {
4245                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4246                                            }
4247                                            else {
4248                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4249                                            }
4250                                    }
4251                                    else {
4252                                            if (orderByComparator.isAscending() ^ previous) {
4253                                                    query.append(WHERE_GREATER_THAN);
4254                                            }
4255                                            else {
4256                                                    query.append(WHERE_LESSER_THAN);
4257                                            }
4258                                    }
4259                            }
4260    
4261                            query.append(ORDER_BY_CLAUSE);
4262    
4263                            for (int i = 0; i < orderByFields.length; i++) {
4264                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4265                                    query.append(orderByFields[i]);
4266    
4267                                    if ((i + 1) < orderByFields.length) {
4268                                            if (orderByComparator.isAscending() ^ previous) {
4269                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4270                                            }
4271                                            else {
4272                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4273                                            }
4274                                    }
4275                                    else {
4276                                            if (orderByComparator.isAscending() ^ previous) {
4277                                                    query.append(ORDER_BY_ASC);
4278                                            }
4279                                            else {
4280                                                    query.append(ORDER_BY_DESC);
4281                                            }
4282                                    }
4283                            }
4284                    }
4285    
4286                    else {
4287                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4288                    }
4289    
4290                    String sql = query.toString();
4291    
4292                    Query q = session.createQuery(sql);
4293    
4294                    q.setFirstResult(0);
4295                    q.setMaxResults(2);
4296    
4297                    QueryPos qPos = QueryPos.getInstance(q);
4298    
4299                    qPos.add(groupId);
4300    
4301                    qPos.add(status);
4302    
4303                    if (orderByComparator != null) {
4304                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
4305    
4306                            for (Object value : values) {
4307                                    qPos.add(value);
4308                            }
4309                    }
4310    
4311                    List<MBMessage> list = q.list();
4312    
4313                    if (list.size() == 2) {
4314                            return list.get(1);
4315                    }
4316                    else {
4317                            return null;
4318                    }
4319            }
4320    
4321            /**
4322             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and status = &#63;.
4323             *
4324             * @param groupId the group id to search with
4325             * @param status the status to search with
4326             * @return the matching message-boards messages that the user has permission to view
4327             * @throws SystemException if a system exception occurred
4328             */
4329            public List<MBMessage> filterFindByG_S(long groupId, int status)
4330                    throws SystemException {
4331                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4332                            QueryUtil.ALL_POS, null);
4333            }
4334    
4335            /**
4336             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and status = &#63;.
4337             *
4338             * <p>
4339             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4340             * </p>
4341             *
4342             * @param groupId the group id to search with
4343             * @param status the status to search with
4344             * @param start the lower bound of the range of message-boards messages to return
4345             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4346             * @return the range of matching message-boards messages that the user has permission to view
4347             * @throws SystemException if a system exception occurred
4348             */
4349            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
4350                    int end) throws SystemException {
4351                    return filterFindByG_S(groupId, status, start, end, null);
4352            }
4353    
4354            /**
4355             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
4356             *
4357             * <p>
4358             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4359             * </p>
4360             *
4361             * @param groupId the group id to search with
4362             * @param status the status to search with
4363             * @param start the lower bound of the range of message-boards messages to return
4364             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4365             * @param orderByComparator the comparator to order the results by
4366             * @return the ordered range of matching message-boards messages that the user has permission to view
4367             * @throws SystemException if a system exception occurred
4368             */
4369            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
4370                    int end, OrderByComparator orderByComparator) throws SystemException {
4371                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4372                            return findByG_S(groupId, status, start, end, orderByComparator);
4373                    }
4374    
4375                    Session session = null;
4376    
4377                    try {
4378                            session = openSession();
4379    
4380                            StringBundler query = null;
4381    
4382                            if (orderByComparator != null) {
4383                                    query = new StringBundler(4 +
4384                                                    (orderByComparator.getOrderByFields().length * 3));
4385                            }
4386                            else {
4387                                    query = new StringBundler(4);
4388                            }
4389    
4390                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4391    
4392                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4393    
4394                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
4395    
4396                            if (orderByComparator != null) {
4397                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4398                                            orderByComparator);
4399                            }
4400    
4401                            else {
4402                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4403                            }
4404    
4405                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4406                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
4407                                            _FILTER_COLUMN_USERID, groupId);
4408    
4409                            SQLQuery q = session.createSQLQuery(sql);
4410    
4411                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4412    
4413                            QueryPos qPos = QueryPos.getInstance(q);
4414    
4415                            qPos.add(groupId);
4416    
4417                            qPos.add(status);
4418    
4419                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4420                    }
4421                    catch (Exception e) {
4422                            throw processException(e);
4423                    }
4424                    finally {
4425                            closeSession(session);
4426                    }
4427            }
4428    
4429            /**
4430             * Finds all the message-boards messages where companyId = &#63; and status = &#63;.
4431             *
4432             * @param companyId the company id to search with
4433             * @param status the status to search with
4434             * @return the matching message-boards messages
4435             * @throws SystemException if a system exception occurred
4436             */
4437            public List<MBMessage> findByC_S(long companyId, int status)
4438                    throws SystemException {
4439                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
4440                            QueryUtil.ALL_POS, null);
4441            }
4442    
4443            /**
4444             * Finds a range of all the message-boards messages where companyId = &#63; and status = &#63;.
4445             *
4446             * <p>
4447             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4448             * </p>
4449             *
4450             * @param companyId the company id to search with
4451             * @param status the status to search with
4452             * @param start the lower bound of the range of message-boards messages to return
4453             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4454             * @return the range of matching message-boards messages
4455             * @throws SystemException if a system exception occurred
4456             */
4457            public List<MBMessage> findByC_S(long companyId, int status, int start,
4458                    int end) throws SystemException {
4459                    return findByC_S(companyId, status, start, end, null);
4460            }
4461    
4462            /**
4463             * Finds an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
4464             *
4465             * <p>
4466             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4467             * </p>
4468             *
4469             * @param companyId the company id to search with
4470             * @param status the status to search with
4471             * @param start the lower bound of the range of message-boards messages to return
4472             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4473             * @param orderByComparator the comparator to order the results by
4474             * @return the ordered range of matching message-boards messages
4475             * @throws SystemException if a system exception occurred
4476             */
4477            public List<MBMessage> findByC_S(long companyId, int status, int start,
4478                    int end, OrderByComparator orderByComparator) throws SystemException {
4479                    Object[] finderArgs = new Object[] {
4480                                    companyId, status,
4481                                    
4482                                    String.valueOf(start), String.valueOf(end),
4483                                    String.valueOf(orderByComparator)
4484                            };
4485    
4486                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_S,
4487                                    finderArgs, this);
4488    
4489                    if (list == null) {
4490                            Session session = null;
4491    
4492                            try {
4493                                    session = openSession();
4494    
4495                                    StringBundler query = null;
4496    
4497                                    if (orderByComparator != null) {
4498                                            query = new StringBundler(4 +
4499                                                            (orderByComparator.getOrderByFields().length * 3));
4500                                    }
4501                                    else {
4502                                            query = new StringBundler(4);
4503                                    }
4504    
4505                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4506    
4507                                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
4508    
4509                                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
4510    
4511                                    if (orderByComparator != null) {
4512                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4513                                                    orderByComparator);
4514                                    }
4515    
4516                                    else {
4517                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4518                                    }
4519    
4520                                    String sql = query.toString();
4521    
4522                                    Query q = session.createQuery(sql);
4523    
4524                                    QueryPos qPos = QueryPos.getInstance(q);
4525    
4526                                    qPos.add(companyId);
4527    
4528                                    qPos.add(status);
4529    
4530                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4531                                                    end);
4532                            }
4533                            catch (Exception e) {
4534                                    throw processException(e);
4535                            }
4536                            finally {
4537                                    if (list == null) {
4538                                            list = new ArrayList<MBMessage>();
4539                                    }
4540    
4541                                    cacheResult(list);
4542    
4543                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_S, finderArgs,
4544                                            list);
4545    
4546                                    closeSession(session);
4547                            }
4548                    }
4549    
4550                    return list;
4551            }
4552    
4553            /**
4554             * Finds the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
4555             *
4556             * <p>
4557             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4558             * </p>
4559             *
4560             * @param companyId the company id to search with
4561             * @param status the status to search with
4562             * @param orderByComparator the comparator to order the set by
4563             * @return the first matching message-boards message
4564             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4565             * @throws SystemException if a system exception occurred
4566             */
4567            public MBMessage findByC_S_First(long companyId, int status,
4568                    OrderByComparator orderByComparator)
4569                    throws NoSuchMessageException, SystemException {
4570                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
4571                                    orderByComparator);
4572    
4573                    if (list.isEmpty()) {
4574                            StringBundler msg = new StringBundler(6);
4575    
4576                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4577    
4578                            msg.append("companyId=");
4579                            msg.append(companyId);
4580    
4581                            msg.append(", status=");
4582                            msg.append(status);
4583    
4584                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4585    
4586                            throw new NoSuchMessageException(msg.toString());
4587                    }
4588                    else {
4589                            return list.get(0);
4590                    }
4591            }
4592    
4593            /**
4594             * Finds the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
4595             *
4596             * <p>
4597             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4598             * </p>
4599             *
4600             * @param companyId the company id to search with
4601             * @param status the status to search with
4602             * @param orderByComparator the comparator to order the set by
4603             * @return the last matching message-boards message
4604             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4605             * @throws SystemException if a system exception occurred
4606             */
4607            public MBMessage findByC_S_Last(long companyId, int status,
4608                    OrderByComparator orderByComparator)
4609                    throws NoSuchMessageException, SystemException {
4610                    int count = countByC_S(companyId, status);
4611    
4612                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
4613                                    orderByComparator);
4614    
4615                    if (list.isEmpty()) {
4616                            StringBundler msg = new StringBundler(6);
4617    
4618                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4619    
4620                            msg.append("companyId=");
4621                            msg.append(companyId);
4622    
4623                            msg.append(", status=");
4624                            msg.append(status);
4625    
4626                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4627    
4628                            throw new NoSuchMessageException(msg.toString());
4629                    }
4630                    else {
4631                            return list.get(0);
4632                    }
4633            }
4634    
4635            /**
4636             * Finds the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
4637             *
4638             * <p>
4639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4640             * </p>
4641             *
4642             * @param messageId the primary key of the current message-boards message
4643             * @param companyId the company id to search with
4644             * @param status the status to search with
4645             * @param orderByComparator the comparator to order the set by
4646             * @return the previous, current, and next message-boards message
4647             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4648             * @throws SystemException if a system exception occurred
4649             */
4650            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
4651                    int status, OrderByComparator orderByComparator)
4652                    throws NoSuchMessageException, SystemException {
4653                    MBMessage mbMessage = findByPrimaryKey(messageId);
4654    
4655                    Session session = null;
4656    
4657                    try {
4658                            session = openSession();
4659    
4660                            MBMessage[] array = new MBMessageImpl[3];
4661    
4662                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
4663                                            status, orderByComparator, true);
4664    
4665                            array[1] = mbMessage;
4666    
4667                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
4668                                            status, orderByComparator, false);
4669    
4670                            return array;
4671                    }
4672                    catch (Exception e) {
4673                            throw processException(e);
4674                    }
4675                    finally {
4676                            closeSession(session);
4677                    }
4678            }
4679    
4680            protected MBMessage getByC_S_PrevAndNext(Session session,
4681                    MBMessage mbMessage, long companyId, int status,
4682                    OrderByComparator orderByComparator, boolean previous) {
4683                    StringBundler query = null;
4684    
4685                    if (orderByComparator != null) {
4686                            query = new StringBundler(6 +
4687                                            (orderByComparator.getOrderByFields().length * 6));
4688                    }
4689                    else {
4690                            query = new StringBundler(3);
4691                    }
4692    
4693                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4694    
4695                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
4696    
4697                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
4698    
4699                    if (orderByComparator != null) {
4700                            String[] orderByFields = orderByComparator.getOrderByFields();
4701    
4702                            if (orderByFields.length > 0) {
4703                                    query.append(WHERE_AND);
4704                            }
4705    
4706                            for (int i = 0; i < orderByFields.length; i++) {
4707                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4708                                    query.append(orderByFields[i]);
4709    
4710                                    if ((i + 1) < orderByFields.length) {
4711                                            if (orderByComparator.isAscending() ^ previous) {
4712                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4713                                            }
4714                                            else {
4715                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4716                                            }
4717                                    }
4718                                    else {
4719                                            if (orderByComparator.isAscending() ^ previous) {
4720                                                    query.append(WHERE_GREATER_THAN);
4721                                            }
4722                                            else {
4723                                                    query.append(WHERE_LESSER_THAN);
4724                                            }
4725                                    }
4726                            }
4727    
4728                            query.append(ORDER_BY_CLAUSE);
4729    
4730                            for (int i = 0; i < orderByFields.length; i++) {
4731                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4732                                    query.append(orderByFields[i]);
4733    
4734                                    if ((i + 1) < orderByFields.length) {
4735                                            if (orderByComparator.isAscending() ^ previous) {
4736                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4737                                            }
4738                                            else {
4739                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4740                                            }
4741                                    }
4742                                    else {
4743                                            if (orderByComparator.isAscending() ^ previous) {
4744                                                    query.append(ORDER_BY_ASC);
4745                                            }
4746                                            else {
4747                                                    query.append(ORDER_BY_DESC);
4748                                            }
4749                                    }
4750                            }
4751                    }
4752    
4753                    else {
4754                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4755                    }
4756    
4757                    String sql = query.toString();
4758    
4759                    Query q = session.createQuery(sql);
4760    
4761                    q.setFirstResult(0);
4762                    q.setMaxResults(2);
4763    
4764                    QueryPos qPos = QueryPos.getInstance(q);
4765    
4766                    qPos.add(companyId);
4767    
4768                    qPos.add(status);
4769    
4770                    if (orderByComparator != null) {
4771                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
4772    
4773                            for (Object value : values) {
4774                                    qPos.add(value);
4775                            }
4776                    }
4777    
4778                    List<MBMessage> list = q.list();
4779    
4780                    if (list.size() == 2) {
4781                            return list.get(1);
4782                    }
4783                    else {
4784                            return null;
4785                    }
4786            }
4787    
4788            /**
4789             * Finds all the message-boards messages where classNameId = &#63; and classPK = &#63;.
4790             *
4791             * @param classNameId the class name id to search with
4792             * @param classPK the class p k to search with
4793             * @return the matching message-boards messages
4794             * @throws SystemException if a system exception occurred
4795             */
4796            public List<MBMessage> findByC_C(long classNameId, long classPK)
4797                    throws SystemException {
4798                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
4799                            QueryUtil.ALL_POS, null);
4800            }
4801    
4802            /**
4803             * Finds a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
4804             *
4805             * <p>
4806             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4807             * </p>
4808             *
4809             * @param classNameId the class name id to search with
4810             * @param classPK the class p k to search with
4811             * @param start the lower bound of the range of message-boards messages to return
4812             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4813             * @return the range of matching message-boards messages
4814             * @throws SystemException if a system exception occurred
4815             */
4816            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
4817                    int end) throws SystemException {
4818                    return findByC_C(classNameId, classPK, start, end, null);
4819            }
4820    
4821            /**
4822             * Finds an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
4823             *
4824             * <p>
4825             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4826             * </p>
4827             *
4828             * @param classNameId the class name id to search with
4829             * @param classPK the class p k to search with
4830             * @param start the lower bound of the range of message-boards messages to return
4831             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
4832             * @param orderByComparator the comparator to order the results by
4833             * @return the ordered range of matching message-boards messages
4834             * @throws SystemException if a system exception occurred
4835             */
4836            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
4837                    int end, OrderByComparator orderByComparator) throws SystemException {
4838                    Object[] finderArgs = new Object[] {
4839                                    classNameId, classPK,
4840                                    
4841                                    String.valueOf(start), String.valueOf(end),
4842                                    String.valueOf(orderByComparator)
4843                            };
4844    
4845                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
4846                                    finderArgs, this);
4847    
4848                    if (list == null) {
4849                            Session session = null;
4850    
4851                            try {
4852                                    session = openSession();
4853    
4854                                    StringBundler query = null;
4855    
4856                                    if (orderByComparator != null) {
4857                                            query = new StringBundler(4 +
4858                                                            (orderByComparator.getOrderByFields().length * 3));
4859                                    }
4860                                    else {
4861                                            query = new StringBundler(4);
4862                                    }
4863    
4864                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4865    
4866                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
4867    
4868                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
4869    
4870                                    if (orderByComparator != null) {
4871                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4872                                                    orderByComparator);
4873                                    }
4874    
4875                                    else {
4876                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4877                                    }
4878    
4879                                    String sql = query.toString();
4880    
4881                                    Query q = session.createQuery(sql);
4882    
4883                                    QueryPos qPos = QueryPos.getInstance(q);
4884    
4885                                    qPos.add(classNameId);
4886    
4887                                    qPos.add(classPK);
4888    
4889                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4890                                                    end);
4891                            }
4892                            catch (Exception e) {
4893                                    throw processException(e);
4894                            }
4895                            finally {
4896                                    if (list == null) {
4897                                            list = new ArrayList<MBMessage>();
4898                                    }
4899    
4900                                    cacheResult(list);
4901    
4902                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
4903                                            list);
4904    
4905                                    closeSession(session);
4906                            }
4907                    }
4908    
4909                    return list;
4910            }
4911    
4912            /**
4913             * Finds the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
4914             *
4915             * <p>
4916             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4917             * </p>
4918             *
4919             * @param classNameId the class name id to search with
4920             * @param classPK the class p k to search with
4921             * @param orderByComparator the comparator to order the set by
4922             * @return the first matching message-boards message
4923             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4924             * @throws SystemException if a system exception occurred
4925             */
4926            public MBMessage findByC_C_First(long classNameId, long classPK,
4927                    OrderByComparator orderByComparator)
4928                    throws NoSuchMessageException, SystemException {
4929                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
4930                                    orderByComparator);
4931    
4932                    if (list.isEmpty()) {
4933                            StringBundler msg = new StringBundler(6);
4934    
4935                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4936    
4937                            msg.append("classNameId=");
4938                            msg.append(classNameId);
4939    
4940                            msg.append(", classPK=");
4941                            msg.append(classPK);
4942    
4943                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4944    
4945                            throw new NoSuchMessageException(msg.toString());
4946                    }
4947                    else {
4948                            return list.get(0);
4949                    }
4950            }
4951    
4952            /**
4953             * Finds the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
4954             *
4955             * <p>
4956             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4957             * </p>
4958             *
4959             * @param classNameId the class name id to search with
4960             * @param classPK the class p k to search with
4961             * @param orderByComparator the comparator to order the set by
4962             * @return the last matching message-boards message
4963             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4964             * @throws SystemException if a system exception occurred
4965             */
4966            public MBMessage findByC_C_Last(long classNameId, long classPK,
4967                    OrderByComparator orderByComparator)
4968                    throws NoSuchMessageException, SystemException {
4969                    int count = countByC_C(classNameId, classPK);
4970    
4971                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
4972                                    count, orderByComparator);
4973    
4974                    if (list.isEmpty()) {
4975                            StringBundler msg = new StringBundler(6);
4976    
4977                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4978    
4979                            msg.append("classNameId=");
4980                            msg.append(classNameId);
4981    
4982                            msg.append(", classPK=");
4983                            msg.append(classPK);
4984    
4985                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4986    
4987                            throw new NoSuchMessageException(msg.toString());
4988                    }
4989                    else {
4990                            return list.get(0);
4991                    }
4992            }
4993    
4994            /**
4995             * Finds the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
4996             *
4997             * <p>
4998             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4999             * </p>
5000             *
5001             * @param messageId the primary key of the current message-boards message
5002             * @param classNameId the class name id to search with
5003             * @param classPK the class p k to search with
5004             * @param orderByComparator the comparator to order the set by
5005             * @return the previous, current, and next message-boards message
5006             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5007             * @throws SystemException if a system exception occurred
5008             */
5009            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
5010                    long classPK, OrderByComparator orderByComparator)
5011                    throws NoSuchMessageException, SystemException {
5012                    MBMessage mbMessage = findByPrimaryKey(messageId);
5013    
5014                    Session session = null;
5015    
5016                    try {
5017                            session = openSession();
5018    
5019                            MBMessage[] array = new MBMessageImpl[3];
5020    
5021                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
5022                                            classPK, orderByComparator, true);
5023    
5024                            array[1] = mbMessage;
5025    
5026                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
5027                                            classPK, orderByComparator, false);
5028    
5029                            return array;
5030                    }
5031                    catch (Exception e) {
5032                            throw processException(e);
5033                    }
5034                    finally {
5035                            closeSession(session);
5036                    }
5037            }
5038    
5039            protected MBMessage getByC_C_PrevAndNext(Session session,
5040                    MBMessage mbMessage, long classNameId, long classPK,
5041                    OrderByComparator orderByComparator, boolean previous) {
5042                    StringBundler query = null;
5043    
5044                    if (orderByComparator != null) {
5045                            query = new StringBundler(6 +
5046                                            (orderByComparator.getOrderByFields().length * 6));
5047                    }
5048                    else {
5049                            query = new StringBundler(3);
5050                    }
5051    
5052                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5053    
5054                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
5055    
5056                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
5057    
5058                    if (orderByComparator != null) {
5059                            String[] orderByFields = orderByComparator.getOrderByFields();
5060    
5061                            if (orderByFields.length > 0) {
5062                                    query.append(WHERE_AND);
5063                            }
5064    
5065                            for (int i = 0; i < orderByFields.length; i++) {
5066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5067                                    query.append(orderByFields[i]);
5068    
5069                                    if ((i + 1) < orderByFields.length) {
5070                                            if (orderByComparator.isAscending() ^ previous) {
5071                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5072                                            }
5073                                            else {
5074                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5075                                            }
5076                                    }
5077                                    else {
5078                                            if (orderByComparator.isAscending() ^ previous) {
5079                                                    query.append(WHERE_GREATER_THAN);
5080                                            }
5081                                            else {
5082                                                    query.append(WHERE_LESSER_THAN);
5083                                            }
5084                                    }
5085                            }
5086    
5087                            query.append(ORDER_BY_CLAUSE);
5088    
5089                            for (int i = 0; i < orderByFields.length; i++) {
5090                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5091                                    query.append(orderByFields[i]);
5092    
5093                                    if ((i + 1) < orderByFields.length) {
5094                                            if (orderByComparator.isAscending() ^ previous) {
5095                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5096                                            }
5097                                            else {
5098                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5099                                            }
5100                                    }
5101                                    else {
5102                                            if (orderByComparator.isAscending() ^ previous) {
5103                                                    query.append(ORDER_BY_ASC);
5104                                            }
5105                                            else {
5106                                                    query.append(ORDER_BY_DESC);
5107                                            }
5108                                    }
5109                            }
5110                    }
5111    
5112                    else {
5113                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5114                    }
5115    
5116                    String sql = query.toString();
5117    
5118                    Query q = session.createQuery(sql);
5119    
5120                    q.setFirstResult(0);
5121                    q.setMaxResults(2);
5122    
5123                    QueryPos qPos = QueryPos.getInstance(q);
5124    
5125                    qPos.add(classNameId);
5126    
5127                    qPos.add(classPK);
5128    
5129                    if (orderByComparator != null) {
5130                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
5131    
5132                            for (Object value : values) {
5133                                    qPos.add(value);
5134                            }
5135                    }
5136    
5137                    List<MBMessage> list = q.list();
5138    
5139                    if (list.size() == 2) {
5140                            return list.get(1);
5141                    }
5142                    else {
5143                            return null;
5144                    }
5145            }
5146    
5147            /**
5148             * Finds all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
5149             *
5150             * @param threadId the thread id to search with
5151             * @param parentMessageId the parent message id to search with
5152             * @return the matching message-boards messages
5153             * @throws SystemException if a system exception occurred
5154             */
5155            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
5156                    throws SystemException {
5157                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
5158                            QueryUtil.ALL_POS, null);
5159            }
5160    
5161            /**
5162             * Finds a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
5163             *
5164             * <p>
5165             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5166             * </p>
5167             *
5168             * @param threadId the thread id to search with
5169             * @param parentMessageId the parent message id to search with
5170             * @param start the lower bound of the range of message-boards messages to return
5171             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
5172             * @return the range of matching message-boards messages
5173             * @throws SystemException if a system exception occurred
5174             */
5175            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
5176                    int start, int end) throws SystemException {
5177                    return findByT_P(threadId, parentMessageId, start, end, null);
5178            }
5179    
5180            /**
5181             * Finds an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
5182             *
5183             * <p>
5184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5185             * </p>
5186             *
5187             * @param threadId the thread id to search with
5188             * @param parentMessageId the parent message id to search with
5189             * @param start the lower bound of the range of message-boards messages to return
5190             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
5191             * @param orderByComparator the comparator to order the results by
5192             * @return the ordered range of matching message-boards messages
5193             * @throws SystemException if a system exception occurred
5194             */
5195            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
5196                    int start, int end, OrderByComparator orderByComparator)
5197                    throws SystemException {
5198                    Object[] finderArgs = new Object[] {
5199                                    threadId, parentMessageId,
5200                                    
5201                                    String.valueOf(start), String.valueOf(end),
5202                                    String.valueOf(orderByComparator)
5203                            };
5204    
5205                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_P,
5206                                    finderArgs, this);
5207    
5208                    if (list == null) {
5209                            Session session = null;
5210    
5211                            try {
5212                                    session = openSession();
5213    
5214                                    StringBundler query = null;
5215    
5216                                    if (orderByComparator != null) {
5217                                            query = new StringBundler(4 +
5218                                                            (orderByComparator.getOrderByFields().length * 3));
5219                                    }
5220                                    else {
5221                                            query = new StringBundler(4);
5222                                    }
5223    
5224                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5225    
5226                                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
5227    
5228                                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
5229    
5230                                    if (orderByComparator != null) {
5231                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5232                                                    orderByComparator);
5233                                    }
5234    
5235                                    else {
5236                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5237                                    }
5238    
5239                                    String sql = query.toString();
5240    
5241                                    Query q = session.createQuery(sql);
5242    
5243                                    QueryPos qPos = QueryPos.getInstance(q);
5244    
5245                                    qPos.add(threadId);
5246    
5247                                    qPos.add(parentMessageId);
5248    
5249                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5250                                                    end);
5251                            }
5252                            catch (Exception e) {
5253                                    throw processException(e);
5254                            }
5255                            finally {
5256                                    if (list == null) {
5257                                            list = new ArrayList<MBMessage>();
5258                                    }
5259    
5260                                    cacheResult(list);
5261    
5262                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_P, finderArgs,
5263                                            list);
5264    
5265                                    closeSession(session);
5266                            }
5267                    }
5268    
5269                    return list;
5270            }
5271    
5272            /**
5273             * Finds the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
5274             *
5275             * <p>
5276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5277             * </p>
5278             *
5279             * @param threadId the thread id to search with
5280             * @param parentMessageId the parent message id to search with
5281             * @param orderByComparator the comparator to order the set by
5282             * @return the first matching message-boards message
5283             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5284             * @throws SystemException if a system exception occurred
5285             */
5286            public MBMessage findByT_P_First(long threadId, long parentMessageId,
5287                    OrderByComparator orderByComparator)
5288                    throws NoSuchMessageException, SystemException {
5289                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
5290                                    orderByComparator);
5291    
5292                    if (list.isEmpty()) {
5293                            StringBundler msg = new StringBundler(6);
5294    
5295                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5296    
5297                            msg.append("threadId=");
5298                            msg.append(threadId);
5299    
5300                            msg.append(", parentMessageId=");
5301                            msg.append(parentMessageId);
5302    
5303                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5304    
5305                            throw new NoSuchMessageException(msg.toString());
5306                    }
5307                    else {
5308                            return list.get(0);
5309                    }
5310            }
5311    
5312            /**
5313             * Finds the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
5314             *
5315             * <p>
5316             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5317             * </p>
5318             *
5319             * @param threadId the thread id to search with
5320             * @param parentMessageId the parent message id to search with
5321             * @param orderByComparator the comparator to order the set by
5322             * @return the last matching message-boards message
5323             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5324             * @throws SystemException if a system exception occurred
5325             */
5326            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
5327                    OrderByComparator orderByComparator)
5328                    throws NoSuchMessageException, SystemException {
5329                    int count = countByT_P(threadId, parentMessageId);
5330    
5331                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
5332                                    count, orderByComparator);
5333    
5334                    if (list.isEmpty()) {
5335                            StringBundler msg = new StringBundler(6);
5336    
5337                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5338    
5339                            msg.append("threadId=");
5340                            msg.append(threadId);
5341    
5342                            msg.append(", parentMessageId=");
5343                            msg.append(parentMessageId);
5344    
5345                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5346    
5347                            throw new NoSuchMessageException(msg.toString());
5348                    }
5349                    else {
5350                            return list.get(0);
5351                    }
5352            }
5353    
5354            /**
5355             * Finds the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
5356             *
5357             * <p>
5358             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5359             * </p>
5360             *
5361             * @param messageId the primary key of the current message-boards message
5362             * @param threadId the thread id to search with
5363             * @param parentMessageId the parent message id to search with
5364             * @param orderByComparator the comparator to order the set by
5365             * @return the previous, current, and next message-boards message
5366             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5367             * @throws SystemException if a system exception occurred
5368             */
5369            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
5370                    long parentMessageId, OrderByComparator orderByComparator)
5371                    throws NoSuchMessageException, SystemException {
5372                    MBMessage mbMessage = findByPrimaryKey(messageId);
5373    
5374                    Session session = null;
5375    
5376                    try {
5377                            session = openSession();
5378    
5379                            MBMessage[] array = new MBMessageImpl[3];
5380    
5381                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
5382                                            parentMessageId, orderByComparator, true);
5383    
5384                            array[1] = mbMessage;
5385    
5386                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
5387                                            parentMessageId, orderByComparator, false);
5388    
5389                            return array;
5390                    }
5391                    catch (Exception e) {
5392                            throw processException(e);
5393                    }
5394                    finally {
5395                            closeSession(session);
5396                    }
5397            }
5398    
5399            protected MBMessage getByT_P_PrevAndNext(Session session,
5400                    MBMessage mbMessage, long threadId, long parentMessageId,
5401                    OrderByComparator orderByComparator, boolean previous) {
5402                    StringBundler query = null;
5403    
5404                    if (orderByComparator != null) {
5405                            query = new StringBundler(6 +
5406                                            (orderByComparator.getOrderByFields().length * 6));
5407                    }
5408                    else {
5409                            query = new StringBundler(3);
5410                    }
5411    
5412                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5413    
5414                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
5415    
5416                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
5417    
5418                    if (orderByComparator != null) {
5419                            String[] orderByFields = orderByComparator.getOrderByFields();
5420    
5421                            if (orderByFields.length > 0) {
5422                                    query.append(WHERE_AND);
5423                            }
5424    
5425                            for (int i = 0; i < orderByFields.length; i++) {
5426                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5427                                    query.append(orderByFields[i]);
5428    
5429                                    if ((i + 1) < orderByFields.length) {
5430                                            if (orderByComparator.isAscending() ^ previous) {
5431                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5432                                            }
5433                                            else {
5434                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5435                                            }
5436                                    }
5437                                    else {
5438                                            if (orderByComparator.isAscending() ^ previous) {
5439                                                    query.append(WHERE_GREATER_THAN);
5440                                            }
5441                                            else {
5442                                                    query.append(WHERE_LESSER_THAN);
5443                                            }
5444                                    }
5445                            }
5446    
5447                            query.append(ORDER_BY_CLAUSE);
5448    
5449                            for (int i = 0; i < orderByFields.length; i++) {
5450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5451                                    query.append(orderByFields[i]);
5452    
5453                                    if ((i + 1) < orderByFields.length) {
5454                                            if (orderByComparator.isAscending() ^ previous) {
5455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5456                                            }
5457                                            else {
5458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5459                                            }
5460                                    }
5461                                    else {
5462                                            if (orderByComparator.isAscending() ^ previous) {
5463                                                    query.append(ORDER_BY_ASC);
5464                                            }
5465                                            else {
5466                                                    query.append(ORDER_BY_DESC);
5467                                            }
5468                                    }
5469                            }
5470                    }
5471    
5472                    else {
5473                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5474                    }
5475    
5476                    String sql = query.toString();
5477    
5478                    Query q = session.createQuery(sql);
5479    
5480                    q.setFirstResult(0);
5481                    q.setMaxResults(2);
5482    
5483                    QueryPos qPos = QueryPos.getInstance(q);
5484    
5485                    qPos.add(threadId);
5486    
5487                    qPos.add(parentMessageId);
5488    
5489                    if (orderByComparator != null) {
5490                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
5491    
5492                            for (Object value : values) {
5493                                    qPos.add(value);
5494                            }
5495                    }
5496    
5497                    List<MBMessage> list = q.list();
5498    
5499                    if (list.size() == 2) {
5500                            return list.get(1);
5501                    }
5502                    else {
5503                            return null;
5504                    }
5505            }
5506    
5507            /**
5508             * Finds all the message-boards messages where threadId = &#63; and status = &#63;.
5509             *
5510             * @param threadId the thread id to search with
5511             * @param status the status to search with
5512             * @return the matching message-boards messages
5513             * @throws SystemException if a system exception occurred
5514             */
5515            public List<MBMessage> findByT_S(long threadId, int status)
5516                    throws SystemException {
5517                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
5518                            QueryUtil.ALL_POS, null);
5519            }
5520    
5521            /**
5522             * Finds a range of all the message-boards messages where threadId = &#63; and status = &#63;.
5523             *
5524             * <p>
5525             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5526             * </p>
5527             *
5528             * @param threadId the thread id to search with
5529             * @param status the status to search with
5530             * @param start the lower bound of the range of message-boards messages to return
5531             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
5532             * @return the range of matching message-boards messages
5533             * @throws SystemException if a system exception occurred
5534             */
5535            public List<MBMessage> findByT_S(long threadId, int status, int start,
5536                    int end) throws SystemException {
5537                    return findByT_S(threadId, status, start, end, null);
5538            }
5539    
5540            /**
5541             * Finds an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
5542             *
5543             * <p>
5544             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5545             * </p>
5546             *
5547             * @param threadId the thread id to search with
5548             * @param status the status to search with
5549             * @param start the lower bound of the range of message-boards messages to return
5550             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
5551             * @param orderByComparator the comparator to order the results by
5552             * @return the ordered range of matching message-boards messages
5553             * @throws SystemException if a system exception occurred
5554             */
5555            public List<MBMessage> findByT_S(long threadId, int status, int start,
5556                    int end, OrderByComparator orderByComparator) throws SystemException {
5557                    Object[] finderArgs = new Object[] {
5558                                    threadId, status,
5559                                    
5560                                    String.valueOf(start), String.valueOf(end),
5561                                    String.valueOf(orderByComparator)
5562                            };
5563    
5564                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_S,
5565                                    finderArgs, this);
5566    
5567                    if (list == null) {
5568                            Session session = null;
5569    
5570                            try {
5571                                    session = openSession();
5572    
5573                                    StringBundler query = null;
5574    
5575                                    if (orderByComparator != null) {
5576                                            query = new StringBundler(4 +
5577                                                            (orderByComparator.getOrderByFields().length * 3));
5578                                    }
5579                                    else {
5580                                            query = new StringBundler(4);
5581                                    }
5582    
5583                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5584    
5585                                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
5586    
5587                                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
5588    
5589                                    if (orderByComparator != null) {
5590                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5591                                                    orderByComparator);
5592                                    }
5593    
5594                                    else {
5595                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5596                                    }
5597    
5598                                    String sql = query.toString();
5599    
5600                                    Query q = session.createQuery(sql);
5601    
5602                                    QueryPos qPos = QueryPos.getInstance(q);
5603    
5604                                    qPos.add(threadId);
5605    
5606                                    qPos.add(status);
5607    
5608                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5609                                                    end);
5610                            }
5611                            catch (Exception e) {
5612                                    throw processException(e);
5613                            }
5614                            finally {
5615                                    if (list == null) {
5616                                            list = new ArrayList<MBMessage>();
5617                                    }
5618    
5619                                    cacheResult(list);
5620    
5621                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_S, finderArgs,
5622                                            list);
5623    
5624                                    closeSession(session);
5625                            }
5626                    }
5627    
5628                    return list;
5629            }
5630    
5631            /**
5632             * Finds the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
5633             *
5634             * <p>
5635             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5636             * </p>
5637             *
5638             * @param threadId the thread id to search with
5639             * @param status the status to search with
5640             * @param orderByComparator the comparator to order the set by
5641             * @return the first matching message-boards message
5642             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5643             * @throws SystemException if a system exception occurred
5644             */
5645            public MBMessage findByT_S_First(long threadId, int status,
5646                    OrderByComparator orderByComparator)
5647                    throws NoSuchMessageException, SystemException {
5648                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
5649                                    orderByComparator);
5650    
5651                    if (list.isEmpty()) {
5652                            StringBundler msg = new StringBundler(6);
5653    
5654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5655    
5656                            msg.append("threadId=");
5657                            msg.append(threadId);
5658    
5659                            msg.append(", status=");
5660                            msg.append(status);
5661    
5662                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5663    
5664                            throw new NoSuchMessageException(msg.toString());
5665                    }
5666                    else {
5667                            return list.get(0);
5668                    }
5669            }
5670    
5671            /**
5672             * Finds the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
5673             *
5674             * <p>
5675             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5676             * </p>
5677             *
5678             * @param threadId the thread id to search with
5679             * @param status the status to search with
5680             * @param orderByComparator the comparator to order the set by
5681             * @return the last matching message-boards message
5682             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5683             * @throws SystemException if a system exception occurred
5684             */
5685            public MBMessage findByT_S_Last(long threadId, int status,
5686                    OrderByComparator orderByComparator)
5687                    throws NoSuchMessageException, SystemException {
5688                    int count = countByT_S(threadId, status);
5689    
5690                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
5691                                    orderByComparator);
5692    
5693                    if (list.isEmpty()) {
5694                            StringBundler msg = new StringBundler(6);
5695    
5696                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5697    
5698                            msg.append("threadId=");
5699                            msg.append(threadId);
5700    
5701                            msg.append(", status=");
5702                            msg.append(status);
5703    
5704                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5705    
5706                            throw new NoSuchMessageException(msg.toString());
5707                    }
5708                    else {
5709                            return list.get(0);
5710                    }
5711            }
5712    
5713            /**
5714             * Finds the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
5715             *
5716             * <p>
5717             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5718             * </p>
5719             *
5720             * @param messageId the primary key of the current message-boards message
5721             * @param threadId the thread id to search with
5722             * @param status the status to search with
5723             * @param orderByComparator the comparator to order the set by
5724             * @return the previous, current, and next message-boards message
5725             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5726             * @throws SystemException if a system exception occurred
5727             */
5728            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
5729                    int status, OrderByComparator orderByComparator)
5730                    throws NoSuchMessageException, SystemException {
5731                    MBMessage mbMessage = findByPrimaryKey(messageId);
5732    
5733                    Session session = null;
5734    
5735                    try {
5736                            session = openSession();
5737    
5738                            MBMessage[] array = new MBMessageImpl[3];
5739    
5740                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
5741                                            status, orderByComparator, true);
5742    
5743                            array[1] = mbMessage;
5744    
5745                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
5746                                            status, orderByComparator, false);
5747    
5748                            return array;
5749                    }
5750                    catch (Exception e) {
5751                            throw processException(e);
5752                    }
5753                    finally {
5754                            closeSession(session);
5755                    }
5756            }
5757    
5758            protected MBMessage getByT_S_PrevAndNext(Session session,
5759                    MBMessage mbMessage, long threadId, int status,
5760                    OrderByComparator orderByComparator, boolean previous) {
5761                    StringBundler query = null;
5762    
5763                    if (orderByComparator != null) {
5764                            query = new StringBundler(6 +
5765                                            (orderByComparator.getOrderByFields().length * 6));
5766                    }
5767                    else {
5768                            query = new StringBundler(3);
5769                    }
5770    
5771                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5772    
5773                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
5774    
5775                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
5776    
5777                    if (orderByComparator != null) {
5778                            String[] orderByFields = orderByComparator.getOrderByFields();
5779    
5780                            if (orderByFields.length > 0) {
5781                                    query.append(WHERE_AND);
5782                            }
5783    
5784                            for (int i = 0; i < orderByFields.length; i++) {
5785                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5786                                    query.append(orderByFields[i]);
5787    
5788                                    if ((i + 1) < orderByFields.length) {
5789                                            if (orderByComparator.isAscending() ^ previous) {
5790                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5791                                            }
5792                                            else {
5793                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5794                                            }
5795                                    }
5796                                    else {
5797                                            if (orderByComparator.isAscending() ^ previous) {
5798                                                    query.append(WHERE_GREATER_THAN);
5799                                            }
5800                                            else {
5801                                                    query.append(WHERE_LESSER_THAN);
5802                                            }
5803                                    }
5804                            }
5805    
5806                            query.append(ORDER_BY_CLAUSE);
5807    
5808                            for (int i = 0; i < orderByFields.length; i++) {
5809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5810                                    query.append(orderByFields[i]);
5811    
5812                                    if ((i + 1) < orderByFields.length) {
5813                                            if (orderByComparator.isAscending() ^ previous) {
5814                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5815                                            }
5816                                            else {
5817                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5818                                            }
5819                                    }
5820                                    else {
5821                                            if (orderByComparator.isAscending() ^ previous) {
5822                                                    query.append(ORDER_BY_ASC);
5823                                            }
5824                                            else {
5825                                                    query.append(ORDER_BY_DESC);
5826                                            }
5827                                    }
5828                            }
5829                    }
5830    
5831                    else {
5832                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5833                    }
5834    
5835                    String sql = query.toString();
5836    
5837                    Query q = session.createQuery(sql);
5838    
5839                    q.setFirstResult(0);
5840                    q.setMaxResults(2);
5841    
5842                    QueryPos qPos = QueryPos.getInstance(q);
5843    
5844                    qPos.add(threadId);
5845    
5846                    qPos.add(status);
5847    
5848                    if (orderByComparator != null) {
5849                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
5850    
5851                            for (Object value : values) {
5852                                    qPos.add(value);
5853                            }
5854                    }
5855    
5856                    List<MBMessage> list = q.list();
5857    
5858                    if (list.size() == 2) {
5859                            return list.get(1);
5860                    }
5861                    else {
5862                            return null;
5863                    }
5864            }
5865    
5866            /**
5867             * Finds all the message-boards messages where threadId = &#63; and status = &#63;.
5868             *
5869             * @param threadId the thread id to search with
5870             * @param status the status to search with
5871             * @return the matching message-boards messages
5872             * @throws SystemException if a system exception occurred
5873             */
5874            public List<MBMessage> findByTR_S(long threadId, int status)
5875                    throws SystemException {
5876                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
5877                            QueryUtil.ALL_POS, null);
5878            }
5879    
5880            /**
5881             * Finds a range of all the message-boards messages where threadId = &#63; and status = &#63;.
5882             *
5883             * <p>
5884             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5885             * </p>
5886             *
5887             * @param threadId the thread id to search with
5888             * @param status the status to search with
5889             * @param start the lower bound of the range of message-boards messages to return
5890             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
5891             * @return the range of matching message-boards messages
5892             * @throws SystemException if a system exception occurred
5893             */
5894            public List<MBMessage> findByTR_S(long threadId, int status, int start,
5895                    int end) throws SystemException {
5896                    return findByTR_S(threadId, status, start, end, null);
5897            }
5898    
5899            /**
5900             * Finds an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
5901             *
5902             * <p>
5903             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5904             * </p>
5905             *
5906             * @param threadId the thread id to search with
5907             * @param status the status to search with
5908             * @param start the lower bound of the range of message-boards messages to return
5909             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
5910             * @param orderByComparator the comparator to order the results by
5911             * @return the ordered range of matching message-boards messages
5912             * @throws SystemException if a system exception occurred
5913             */
5914            public List<MBMessage> findByTR_S(long threadId, int status, int start,
5915                    int end, OrderByComparator orderByComparator) throws SystemException {
5916                    Object[] finderArgs = new Object[] {
5917                                    threadId, status,
5918                                    
5919                                    String.valueOf(start), String.valueOf(end),
5920                                    String.valueOf(orderByComparator)
5921                            };
5922    
5923                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TR_S,
5924                                    finderArgs, this);
5925    
5926                    if (list == null) {
5927                            Session session = null;
5928    
5929                            try {
5930                                    session = openSession();
5931    
5932                                    StringBundler query = null;
5933    
5934                                    if (orderByComparator != null) {
5935                                            query = new StringBundler(4 +
5936                                                            (orderByComparator.getOrderByFields().length * 3));
5937                                    }
5938                                    else {
5939                                            query = new StringBundler(4);
5940                                    }
5941    
5942                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5943    
5944                                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
5945    
5946                                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
5947    
5948                                    if (orderByComparator != null) {
5949                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5950                                                    orderByComparator);
5951                                    }
5952    
5953                                    else {
5954                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5955                                    }
5956    
5957                                    String sql = query.toString();
5958    
5959                                    Query q = session.createQuery(sql);
5960    
5961                                    QueryPos qPos = QueryPos.getInstance(q);
5962    
5963                                    qPos.add(threadId);
5964    
5965                                    qPos.add(status);
5966    
5967                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5968                                                    end);
5969                            }
5970                            catch (Exception e) {
5971                                    throw processException(e);
5972                            }
5973                            finally {
5974                                    if (list == null) {
5975                                            list = new ArrayList<MBMessage>();
5976                                    }
5977    
5978                                    cacheResult(list);
5979    
5980                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TR_S, finderArgs,
5981                                            list);
5982    
5983                                    closeSession(session);
5984                            }
5985                    }
5986    
5987                    return list;
5988            }
5989    
5990            /**
5991             * Finds the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
5992             *
5993             * <p>
5994             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5995             * </p>
5996             *
5997             * @param threadId the thread id to search with
5998             * @param status the status to search with
5999             * @param orderByComparator the comparator to order the set by
6000             * @return the first matching message-boards message
6001             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6002             * @throws SystemException if a system exception occurred
6003             */
6004            public MBMessage findByTR_S_First(long threadId, int status,
6005                    OrderByComparator orderByComparator)
6006                    throws NoSuchMessageException, SystemException {
6007                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
6008                                    orderByComparator);
6009    
6010                    if (list.isEmpty()) {
6011                            StringBundler msg = new StringBundler(6);
6012    
6013                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6014    
6015                            msg.append("threadId=");
6016                            msg.append(threadId);
6017    
6018                            msg.append(", status=");
6019                            msg.append(status);
6020    
6021                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6022    
6023                            throw new NoSuchMessageException(msg.toString());
6024                    }
6025                    else {
6026                            return list.get(0);
6027                    }
6028            }
6029    
6030            /**
6031             * Finds the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
6032             *
6033             * <p>
6034             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6035             * </p>
6036             *
6037             * @param threadId the thread id to search with
6038             * @param status the status to search with
6039             * @param orderByComparator the comparator to order the set by
6040             * @return the last matching message-boards message
6041             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6042             * @throws SystemException if a system exception occurred
6043             */
6044            public MBMessage findByTR_S_Last(long threadId, int status,
6045                    OrderByComparator orderByComparator)
6046                    throws NoSuchMessageException, SystemException {
6047                    int count = countByTR_S(threadId, status);
6048    
6049                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
6050                                    orderByComparator);
6051    
6052                    if (list.isEmpty()) {
6053                            StringBundler msg = new StringBundler(6);
6054    
6055                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6056    
6057                            msg.append("threadId=");
6058                            msg.append(threadId);
6059    
6060                            msg.append(", status=");
6061                            msg.append(status);
6062    
6063                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6064    
6065                            throw new NoSuchMessageException(msg.toString());
6066                    }
6067                    else {
6068                            return list.get(0);
6069                    }
6070            }
6071    
6072            /**
6073             * Finds the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
6074             *
6075             * <p>
6076             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6077             * </p>
6078             *
6079             * @param messageId the primary key of the current message-boards message
6080             * @param threadId the thread id to search with
6081             * @param status the status to search with
6082             * @param orderByComparator the comparator to order the set by
6083             * @return the previous, current, and next message-boards message
6084             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6085             * @throws SystemException if a system exception occurred
6086             */
6087            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
6088                    int status, OrderByComparator orderByComparator)
6089                    throws NoSuchMessageException, SystemException {
6090                    MBMessage mbMessage = findByPrimaryKey(messageId);
6091    
6092                    Session session = null;
6093    
6094                    try {
6095                            session = openSession();
6096    
6097                            MBMessage[] array = new MBMessageImpl[3];
6098    
6099                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
6100                                            status, orderByComparator, true);
6101    
6102                            array[1] = mbMessage;
6103    
6104                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
6105                                            status, orderByComparator, false);
6106    
6107                            return array;
6108                    }
6109                    catch (Exception e) {
6110                            throw processException(e);
6111                    }
6112                    finally {
6113                            closeSession(session);
6114                    }
6115            }
6116    
6117            protected MBMessage getByTR_S_PrevAndNext(Session session,
6118                    MBMessage mbMessage, long threadId, int status,
6119                    OrderByComparator orderByComparator, boolean previous) {
6120                    StringBundler query = null;
6121    
6122                    if (orderByComparator != null) {
6123                            query = new StringBundler(6 +
6124                                            (orderByComparator.getOrderByFields().length * 6));
6125                    }
6126                    else {
6127                            query = new StringBundler(3);
6128                    }
6129    
6130                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6131    
6132                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
6133    
6134                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
6135    
6136                    if (orderByComparator != null) {
6137                            String[] orderByFields = orderByComparator.getOrderByFields();
6138    
6139                            if (orderByFields.length > 0) {
6140                                    query.append(WHERE_AND);
6141                            }
6142    
6143                            for (int i = 0; i < orderByFields.length; i++) {
6144                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6145                                    query.append(orderByFields[i]);
6146    
6147                                    if ((i + 1) < orderByFields.length) {
6148                                            if (orderByComparator.isAscending() ^ previous) {
6149                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6150                                            }
6151                                            else {
6152                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6153                                            }
6154                                    }
6155                                    else {
6156                                            if (orderByComparator.isAscending() ^ previous) {
6157                                                    query.append(WHERE_GREATER_THAN);
6158                                            }
6159                                            else {
6160                                                    query.append(WHERE_LESSER_THAN);
6161                                            }
6162                                    }
6163                            }
6164    
6165                            query.append(ORDER_BY_CLAUSE);
6166    
6167                            for (int i = 0; i < orderByFields.length; i++) {
6168                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6169                                    query.append(orderByFields[i]);
6170    
6171                                    if ((i + 1) < orderByFields.length) {
6172                                            if (orderByComparator.isAscending() ^ previous) {
6173                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6174                                            }
6175                                            else {
6176                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6177                                            }
6178                                    }
6179                                    else {
6180                                            if (orderByComparator.isAscending() ^ previous) {
6181                                                    query.append(ORDER_BY_ASC);
6182                                            }
6183                                            else {
6184                                                    query.append(ORDER_BY_DESC);
6185                                            }
6186                                    }
6187                            }
6188                    }
6189    
6190                    else {
6191                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6192                    }
6193    
6194                    String sql = query.toString();
6195    
6196                    Query q = session.createQuery(sql);
6197    
6198                    q.setFirstResult(0);
6199                    q.setMaxResults(2);
6200    
6201                    QueryPos qPos = QueryPos.getInstance(q);
6202    
6203                    qPos.add(threadId);
6204    
6205                    qPos.add(status);
6206    
6207                    if (orderByComparator != null) {
6208                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
6209    
6210                            for (Object value : values) {
6211                                    qPos.add(value);
6212                            }
6213                    }
6214    
6215                    List<MBMessage> list = q.list();
6216    
6217                    if (list.size() == 2) {
6218                            return list.get(1);
6219                    }
6220                    else {
6221                            return null;
6222                    }
6223            }
6224    
6225            /**
6226             * Finds all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
6227             *
6228             * @param groupId the group id to search with
6229             * @param userId the user id to search with
6230             * @param status the status to search with
6231             * @return the matching message-boards messages
6232             * @throws SystemException if a system exception occurred
6233             */
6234            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
6235                    throws SystemException {
6236                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
6237                            QueryUtil.ALL_POS, null);
6238            }
6239    
6240            /**
6241             * Finds a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
6242             *
6243             * <p>
6244             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6245             * </p>
6246             *
6247             * @param groupId the group id to search with
6248             * @param userId the user id to search with
6249             * @param status the status to search with
6250             * @param start the lower bound of the range of message-boards messages to return
6251             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
6252             * @return the range of matching message-boards messages
6253             * @throws SystemException if a system exception occurred
6254             */
6255            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
6256                    int start, int end) throws SystemException {
6257                    return findByG_U_S(groupId, userId, status, start, end, null);
6258            }
6259    
6260            /**
6261             * Finds an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
6262             *
6263             * <p>
6264             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6265             * </p>
6266             *
6267             * @param groupId the group id to search with
6268             * @param userId the user id to search with
6269             * @param status the status to search with
6270             * @param start the lower bound of the range of message-boards messages to return
6271             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
6272             * @param orderByComparator the comparator to order the results by
6273             * @return the ordered range of matching message-boards messages
6274             * @throws SystemException if a system exception occurred
6275             */
6276            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
6277                    int start, int end, OrderByComparator orderByComparator)
6278                    throws SystemException {
6279                    Object[] finderArgs = new Object[] {
6280                                    groupId, userId, status,
6281                                    
6282                                    String.valueOf(start), String.valueOf(end),
6283                                    String.valueOf(orderByComparator)
6284                            };
6285    
6286                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U_S,
6287                                    finderArgs, this);
6288    
6289                    if (list == null) {
6290                            Session session = null;
6291    
6292                            try {
6293                                    session = openSession();
6294    
6295                                    StringBundler query = null;
6296    
6297                                    if (orderByComparator != null) {
6298                                            query = new StringBundler(5 +
6299                                                            (orderByComparator.getOrderByFields().length * 3));
6300                                    }
6301                                    else {
6302                                            query = new StringBundler(5);
6303                                    }
6304    
6305                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6306    
6307                                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
6308    
6309                                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
6310    
6311                                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
6312    
6313                                    if (orderByComparator != null) {
6314                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6315                                                    orderByComparator);
6316                                    }
6317    
6318                                    else {
6319                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6320                                    }
6321    
6322                                    String sql = query.toString();
6323    
6324                                    Query q = session.createQuery(sql);
6325    
6326                                    QueryPos qPos = QueryPos.getInstance(q);
6327    
6328                                    qPos.add(groupId);
6329    
6330                                    qPos.add(userId);
6331    
6332                                    qPos.add(status);
6333    
6334                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6335                                                    end);
6336                            }
6337                            catch (Exception e) {
6338                                    throw processException(e);
6339                            }
6340                            finally {
6341                                    if (list == null) {
6342                                            list = new ArrayList<MBMessage>();
6343                                    }
6344    
6345                                    cacheResult(list);
6346    
6347                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U_S,
6348                                            finderArgs, list);
6349    
6350                                    closeSession(session);
6351                            }
6352                    }
6353    
6354                    return list;
6355            }
6356    
6357            /**
6358             * Finds the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
6359             *
6360             * <p>
6361             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6362             * </p>
6363             *
6364             * @param groupId the group id to search with
6365             * @param userId the user id to search with
6366             * @param status the status to search with
6367             * @param orderByComparator the comparator to order the set by
6368             * @return the first matching message-boards message
6369             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6370             * @throws SystemException if a system exception occurred
6371             */
6372            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
6373                    OrderByComparator orderByComparator)
6374                    throws NoSuchMessageException, SystemException {
6375                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
6376                                    orderByComparator);
6377    
6378                    if (list.isEmpty()) {
6379                            StringBundler msg = new StringBundler(8);
6380    
6381                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6382    
6383                            msg.append("groupId=");
6384                            msg.append(groupId);
6385    
6386                            msg.append(", userId=");
6387                            msg.append(userId);
6388    
6389                            msg.append(", status=");
6390                            msg.append(status);
6391    
6392                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6393    
6394                            throw new NoSuchMessageException(msg.toString());
6395                    }
6396                    else {
6397                            return list.get(0);
6398                    }
6399            }
6400    
6401            /**
6402             * Finds the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
6403             *
6404             * <p>
6405             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6406             * </p>
6407             *
6408             * @param groupId the group id to search with
6409             * @param userId the user id to search with
6410             * @param status the status to search with
6411             * @param orderByComparator the comparator to order the set by
6412             * @return the last matching message-boards message
6413             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6414             * @throws SystemException if a system exception occurred
6415             */
6416            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
6417                    OrderByComparator orderByComparator)
6418                    throws NoSuchMessageException, SystemException {
6419                    int count = countByG_U_S(groupId, userId, status);
6420    
6421                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
6422                                    count, orderByComparator);
6423    
6424                    if (list.isEmpty()) {
6425                            StringBundler msg = new StringBundler(8);
6426    
6427                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6428    
6429                            msg.append("groupId=");
6430                            msg.append(groupId);
6431    
6432                            msg.append(", userId=");
6433                            msg.append(userId);
6434    
6435                            msg.append(", status=");
6436                            msg.append(status);
6437    
6438                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6439    
6440                            throw new NoSuchMessageException(msg.toString());
6441                    }
6442                    else {
6443                            return list.get(0);
6444                    }
6445            }
6446    
6447            /**
6448             * Finds 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;.
6449             *
6450             * <p>
6451             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6452             * </p>
6453             *
6454             * @param messageId the primary key of the current message-boards message
6455             * @param groupId the group id to search with
6456             * @param userId the user id to search with
6457             * @param status the status to search with
6458             * @param orderByComparator the comparator to order the set by
6459             * @return the previous, current, and next message-boards message
6460             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6461             * @throws SystemException if a system exception occurred
6462             */
6463            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
6464                    long userId, int status, OrderByComparator orderByComparator)
6465                    throws NoSuchMessageException, SystemException {
6466                    MBMessage mbMessage = findByPrimaryKey(messageId);
6467    
6468                    Session session = null;
6469    
6470                    try {
6471                            session = openSession();
6472    
6473                            MBMessage[] array = new MBMessageImpl[3];
6474    
6475                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
6476                                            userId, status, orderByComparator, true);
6477    
6478                            array[1] = mbMessage;
6479    
6480                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
6481                                            userId, status, orderByComparator, false);
6482    
6483                            return array;
6484                    }
6485                    catch (Exception e) {
6486                            throw processException(e);
6487                    }
6488                    finally {
6489                            closeSession(session);
6490                    }
6491            }
6492    
6493            protected MBMessage getByG_U_S_PrevAndNext(Session session,
6494                    MBMessage mbMessage, long groupId, long userId, int status,
6495                    OrderByComparator orderByComparator, boolean previous) {
6496                    StringBundler query = null;
6497    
6498                    if (orderByComparator != null) {
6499                            query = new StringBundler(6 +
6500                                            (orderByComparator.getOrderByFields().length * 6));
6501                    }
6502                    else {
6503                            query = new StringBundler(3);
6504                    }
6505    
6506                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6507    
6508                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
6509    
6510                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
6511    
6512                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
6513    
6514                    if (orderByComparator != null) {
6515                            String[] orderByFields = orderByComparator.getOrderByFields();
6516    
6517                            if (orderByFields.length > 0) {
6518                                    query.append(WHERE_AND);
6519                            }
6520    
6521                            for (int i = 0; i < orderByFields.length; i++) {
6522                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6523                                    query.append(orderByFields[i]);
6524    
6525                                    if ((i + 1) < orderByFields.length) {
6526                                            if (orderByComparator.isAscending() ^ previous) {
6527                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6528                                            }
6529                                            else {
6530                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6531                                            }
6532                                    }
6533                                    else {
6534                                            if (orderByComparator.isAscending() ^ previous) {
6535                                                    query.append(WHERE_GREATER_THAN);
6536                                            }
6537                                            else {
6538                                                    query.append(WHERE_LESSER_THAN);
6539                                            }
6540                                    }
6541                            }
6542    
6543                            query.append(ORDER_BY_CLAUSE);
6544    
6545                            for (int i = 0; i < orderByFields.length; i++) {
6546                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6547                                    query.append(orderByFields[i]);
6548    
6549                                    if ((i + 1) < orderByFields.length) {
6550                                            if (orderByComparator.isAscending() ^ previous) {
6551                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6552                                            }
6553                                            else {
6554                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6555                                            }
6556                                    }
6557                                    else {
6558                                            if (orderByComparator.isAscending() ^ previous) {
6559                                                    query.append(ORDER_BY_ASC);
6560                                            }
6561                                            else {
6562                                                    query.append(ORDER_BY_DESC);
6563                                            }
6564                                    }
6565                            }
6566                    }
6567    
6568                    else {
6569                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6570                    }
6571    
6572                    String sql = query.toString();
6573    
6574                    Query q = session.createQuery(sql);
6575    
6576                    q.setFirstResult(0);
6577                    q.setMaxResults(2);
6578    
6579                    QueryPos qPos = QueryPos.getInstance(q);
6580    
6581                    qPos.add(groupId);
6582    
6583                    qPos.add(userId);
6584    
6585                    qPos.add(status);
6586    
6587                    if (orderByComparator != null) {
6588                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
6589    
6590                            for (Object value : values) {
6591                                    qPos.add(value);
6592                            }
6593                    }
6594    
6595                    List<MBMessage> list = q.list();
6596    
6597                    if (list.size() == 2) {
6598                            return list.get(1);
6599                    }
6600                    else {
6601                            return null;
6602                    }
6603            }
6604    
6605            /**
6606             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
6607             *
6608             * @param groupId the group id to search with
6609             * @param userId the user id to search with
6610             * @param status the status to search with
6611             * @return the matching message-boards messages that the user has permission to view
6612             * @throws SystemException if a system exception occurred
6613             */
6614            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
6615                    int status) throws SystemException {
6616                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
6617                            QueryUtil.ALL_POS, null);
6618            }
6619    
6620            /**
6621             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
6622             *
6623             * <p>
6624             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6625             * </p>
6626             *
6627             * @param groupId the group id to search with
6628             * @param userId the user id to search with
6629             * @param status the status to search with
6630             * @param start the lower bound of the range of message-boards messages to return
6631             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
6632             * @return the range of matching message-boards messages that the user has permission to view
6633             * @throws SystemException if a system exception occurred
6634             */
6635            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
6636                    int status, int start, int end) throws SystemException {
6637                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
6638            }
6639    
6640            /**
6641             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
6642             *
6643             * <p>
6644             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6645             * </p>
6646             *
6647             * @param groupId the group id to search with
6648             * @param userId the user id to search with
6649             * @param status the status to search with
6650             * @param start the lower bound of the range of message-boards messages to return
6651             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
6652             * @param orderByComparator the comparator to order the results by
6653             * @return the ordered range of matching message-boards messages that the user has permission to view
6654             * @throws SystemException if a system exception occurred
6655             */
6656            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
6657                    int status, int start, int end, OrderByComparator orderByComparator)
6658                    throws SystemException {
6659                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6660                            return findByG_U_S(groupId, userId, status, start, end,
6661                                    orderByComparator);
6662                    }
6663    
6664                    Session session = null;
6665    
6666                    try {
6667                            session = openSession();
6668    
6669                            StringBundler query = null;
6670    
6671                            if (orderByComparator != null) {
6672                                    query = new StringBundler(5 +
6673                                                    (orderByComparator.getOrderByFields().length * 3));
6674                            }
6675                            else {
6676                                    query = new StringBundler(5);
6677                            }
6678    
6679                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6680    
6681                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
6682    
6683                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
6684    
6685                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
6686    
6687                            if (orderByComparator != null) {
6688                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6689                                            orderByComparator);
6690                            }
6691    
6692                            else {
6693                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6694                            }
6695    
6696                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6697                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
6698                                            _FILTER_COLUMN_USERID, groupId);
6699    
6700                            SQLQuery q = session.createSQLQuery(sql);
6701    
6702                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6703    
6704                            QueryPos qPos = QueryPos.getInstance(q);
6705    
6706                            qPos.add(groupId);
6707    
6708                            qPos.add(userId);
6709    
6710                            qPos.add(status);
6711    
6712                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6713                    }
6714                    catch (Exception e) {
6715                            throw processException(e);
6716                    }
6717                    finally {
6718                            closeSession(session);
6719                    }
6720            }
6721    
6722            /**
6723             * Finds all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
6724             *
6725             * @param groupId the group id to search with
6726             * @param categoryId the category id to search with
6727             * @param threadId the thread id to search with
6728             * @return the matching message-boards messages
6729             * @throws SystemException if a system exception occurred
6730             */
6731            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
6732                    long threadId) throws SystemException {
6733                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
6734                            QueryUtil.ALL_POS, null);
6735            }
6736    
6737            /**
6738             * Finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
6739             *
6740             * <p>
6741             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6742             * </p>
6743             *
6744             * @param groupId the group id to search with
6745             * @param categoryId the category id to search with
6746             * @param threadId the thread id to search with
6747             * @param start the lower bound of the range of message-boards messages to return
6748             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
6749             * @return the range of matching message-boards messages
6750             * @throws SystemException if a system exception occurred
6751             */
6752            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
6753                    long threadId, int start, int end) throws SystemException {
6754                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
6755            }
6756    
6757            /**
6758             * Finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
6759             *
6760             * <p>
6761             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6762             * </p>
6763             *
6764             * @param groupId the group id to search with
6765             * @param categoryId the category id to search with
6766             * @param threadId the thread id to search with
6767             * @param start the lower bound of the range of message-boards messages to return
6768             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
6769             * @param orderByComparator the comparator to order the results by
6770             * @return the ordered range of matching message-boards messages
6771             * @throws SystemException if a system exception occurred
6772             */
6773            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
6774                    long threadId, int start, int end, OrderByComparator orderByComparator)
6775                    throws SystemException {
6776                    Object[] finderArgs = new Object[] {
6777                                    groupId, categoryId, threadId,
6778                                    
6779                                    String.valueOf(start), String.valueOf(end),
6780                                    String.valueOf(orderByComparator)
6781                            };
6782    
6783                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_T,
6784                                    finderArgs, this);
6785    
6786                    if (list == null) {
6787                            Session session = null;
6788    
6789                            try {
6790                                    session = openSession();
6791    
6792                                    StringBundler query = null;
6793    
6794                                    if (orderByComparator != null) {
6795                                            query = new StringBundler(5 +
6796                                                            (orderByComparator.getOrderByFields().length * 3));
6797                                    }
6798                                    else {
6799                                            query = new StringBundler(5);
6800                                    }
6801    
6802                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6803    
6804                                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
6805    
6806                                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
6807    
6808                                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
6809    
6810                                    if (orderByComparator != null) {
6811                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6812                                                    orderByComparator);
6813                                    }
6814    
6815                                    else {
6816                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6817                                    }
6818    
6819                                    String sql = query.toString();
6820    
6821                                    Query q = session.createQuery(sql);
6822    
6823                                    QueryPos qPos = QueryPos.getInstance(q);
6824    
6825                                    qPos.add(groupId);
6826    
6827                                    qPos.add(categoryId);
6828    
6829                                    qPos.add(threadId);
6830    
6831                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6832                                                    end);
6833                            }
6834                            catch (Exception e) {
6835                                    throw processException(e);
6836                            }
6837                            finally {
6838                                    if (list == null) {
6839                                            list = new ArrayList<MBMessage>();
6840                                    }
6841    
6842                                    cacheResult(list);
6843    
6844                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_T,
6845                                            finderArgs, list);
6846    
6847                                    closeSession(session);
6848                            }
6849                    }
6850    
6851                    return list;
6852            }
6853    
6854            /**
6855             * Finds the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
6856             *
6857             * <p>
6858             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6859             * </p>
6860             *
6861             * @param groupId the group id to search with
6862             * @param categoryId the category id to search with
6863             * @param threadId the thread id to search with
6864             * @param orderByComparator the comparator to order the set by
6865             * @return the first matching message-boards message
6866             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6867             * @throws SystemException if a system exception occurred
6868             */
6869            public MBMessage findByG_C_T_First(long groupId, long categoryId,
6870                    long threadId, OrderByComparator orderByComparator)
6871                    throws NoSuchMessageException, SystemException {
6872                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
6873                                    orderByComparator);
6874    
6875                    if (list.isEmpty()) {
6876                            StringBundler msg = new StringBundler(8);
6877    
6878                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6879    
6880                            msg.append("groupId=");
6881                            msg.append(groupId);
6882    
6883                            msg.append(", categoryId=");
6884                            msg.append(categoryId);
6885    
6886                            msg.append(", threadId=");
6887                            msg.append(threadId);
6888    
6889                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6890    
6891                            throw new NoSuchMessageException(msg.toString());
6892                    }
6893                    else {
6894                            return list.get(0);
6895                    }
6896            }
6897    
6898            /**
6899             * Finds the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
6900             *
6901             * <p>
6902             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6903             * </p>
6904             *
6905             * @param groupId the group id to search with
6906             * @param categoryId the category id to search with
6907             * @param threadId the thread id to search with
6908             * @param orderByComparator the comparator to order the set by
6909             * @return the last matching message-boards message
6910             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6911             * @throws SystemException if a system exception occurred
6912             */
6913            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
6914                    long threadId, OrderByComparator orderByComparator)
6915                    throws NoSuchMessageException, SystemException {
6916                    int count = countByG_C_T(groupId, categoryId, threadId);
6917    
6918                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
6919                                    count - 1, count, orderByComparator);
6920    
6921                    if (list.isEmpty()) {
6922                            StringBundler msg = new StringBundler(8);
6923    
6924                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6925    
6926                            msg.append("groupId=");
6927                            msg.append(groupId);
6928    
6929                            msg.append(", categoryId=");
6930                            msg.append(categoryId);
6931    
6932                            msg.append(", threadId=");
6933                            msg.append(threadId);
6934    
6935                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6936    
6937                            throw new NoSuchMessageException(msg.toString());
6938                    }
6939                    else {
6940                            return list.get(0);
6941                    }
6942            }
6943    
6944            /**
6945             * Finds 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;.
6946             *
6947             * <p>
6948             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6949             * </p>
6950             *
6951             * @param messageId the primary key of the current message-boards message
6952             * @param groupId the group id to search with
6953             * @param categoryId the category id to search with
6954             * @param threadId the thread id to search with
6955             * @param orderByComparator the comparator to order the set by
6956             * @return the previous, current, and next message-boards message
6957             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6958             * @throws SystemException if a system exception occurred
6959             */
6960            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
6961                    long categoryId, long threadId, OrderByComparator orderByComparator)
6962                    throws NoSuchMessageException, SystemException {
6963                    MBMessage mbMessage = findByPrimaryKey(messageId);
6964    
6965                    Session session = null;
6966    
6967                    try {
6968                            session = openSession();
6969    
6970                            MBMessage[] array = new MBMessageImpl[3];
6971    
6972                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
6973                                            categoryId, threadId, orderByComparator, true);
6974    
6975                            array[1] = mbMessage;
6976    
6977                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
6978                                            categoryId, threadId, orderByComparator, false);
6979    
6980                            return array;
6981                    }
6982                    catch (Exception e) {
6983                            throw processException(e);
6984                    }
6985                    finally {
6986                            closeSession(session);
6987                    }
6988            }
6989    
6990            protected MBMessage getByG_C_T_PrevAndNext(Session session,
6991                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
6992                    OrderByComparator orderByComparator, boolean previous) {
6993                    StringBundler query = null;
6994    
6995                    if (orderByComparator != null) {
6996                            query = new StringBundler(6 +
6997                                            (orderByComparator.getOrderByFields().length * 6));
6998                    }
6999                    else {
7000                            query = new StringBundler(3);
7001                    }
7002    
7003                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7004    
7005                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
7006    
7007                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
7008    
7009                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
7010    
7011                    if (orderByComparator != null) {
7012                            String[] orderByFields = orderByComparator.getOrderByFields();
7013    
7014                            if (orderByFields.length > 0) {
7015                                    query.append(WHERE_AND);
7016                            }
7017    
7018                            for (int i = 0; i < orderByFields.length; i++) {
7019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7020                                    query.append(orderByFields[i]);
7021    
7022                                    if ((i + 1) < orderByFields.length) {
7023                                            if (orderByComparator.isAscending() ^ previous) {
7024                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7025                                            }
7026                                            else {
7027                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7028                                            }
7029                                    }
7030                                    else {
7031                                            if (orderByComparator.isAscending() ^ previous) {
7032                                                    query.append(WHERE_GREATER_THAN);
7033                                            }
7034                                            else {
7035                                                    query.append(WHERE_LESSER_THAN);
7036                                            }
7037                                    }
7038                            }
7039    
7040                            query.append(ORDER_BY_CLAUSE);
7041    
7042                            for (int i = 0; i < orderByFields.length; i++) {
7043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7044                                    query.append(orderByFields[i]);
7045    
7046                                    if ((i + 1) < orderByFields.length) {
7047                                            if (orderByComparator.isAscending() ^ previous) {
7048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7049                                            }
7050                                            else {
7051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7052                                            }
7053                                    }
7054                                    else {
7055                                            if (orderByComparator.isAscending() ^ previous) {
7056                                                    query.append(ORDER_BY_ASC);
7057                                            }
7058                                            else {
7059                                                    query.append(ORDER_BY_DESC);
7060                                            }
7061                                    }
7062                            }
7063                    }
7064    
7065                    else {
7066                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7067                    }
7068    
7069                    String sql = query.toString();
7070    
7071                    Query q = session.createQuery(sql);
7072    
7073                    q.setFirstResult(0);
7074                    q.setMaxResults(2);
7075    
7076                    QueryPos qPos = QueryPos.getInstance(q);
7077    
7078                    qPos.add(groupId);
7079    
7080                    qPos.add(categoryId);
7081    
7082                    qPos.add(threadId);
7083    
7084                    if (orderByComparator != null) {
7085                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
7086    
7087                            for (Object value : values) {
7088                                    qPos.add(value);
7089                            }
7090                    }
7091    
7092                    List<MBMessage> list = q.list();
7093    
7094                    if (list.size() == 2) {
7095                            return list.get(1);
7096                    }
7097                    else {
7098                            return null;
7099                    }
7100            }
7101    
7102            /**
7103             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
7104             *
7105             * @param groupId the group id to search with
7106             * @param categoryId the category id to search with
7107             * @param threadId the thread id to search with
7108             * @return the matching message-boards messages that the user has permission to view
7109             * @throws SystemException if a system exception occurred
7110             */
7111            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
7112                    long threadId) throws SystemException {
7113                    return filterFindByG_C_T(groupId, categoryId, threadId,
7114                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7115            }
7116    
7117            /**
7118             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
7119             *
7120             * <p>
7121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7122             * </p>
7123             *
7124             * @param groupId the group id to search with
7125             * @param categoryId the category id to search with
7126             * @param threadId the thread id to search with
7127             * @param start the lower bound of the range of message-boards messages to return
7128             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7129             * @return the range of matching message-boards messages that the user has permission to view
7130             * @throws SystemException if a system exception occurred
7131             */
7132            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
7133                    long threadId, int start, int end) throws SystemException {
7134                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
7135            }
7136    
7137            /**
7138             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
7139             *
7140             * <p>
7141             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7142             * </p>
7143             *
7144             * @param groupId the group id to search with
7145             * @param categoryId the category id to search with
7146             * @param threadId the thread id to search with
7147             * @param start the lower bound of the range of message-boards messages to return
7148             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7149             * @param orderByComparator the comparator to order the results by
7150             * @return the ordered range of matching message-boards messages that the user has permission to view
7151             * @throws SystemException if a system exception occurred
7152             */
7153            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
7154                    long threadId, int start, int end, OrderByComparator orderByComparator)
7155                    throws SystemException {
7156                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7157                            return findByG_C_T(groupId, categoryId, threadId, start, end,
7158                                    orderByComparator);
7159                    }
7160    
7161                    Session session = null;
7162    
7163                    try {
7164                            session = openSession();
7165    
7166                            StringBundler query = null;
7167    
7168                            if (orderByComparator != null) {
7169                                    query = new StringBundler(5 +
7170                                                    (orderByComparator.getOrderByFields().length * 3));
7171                            }
7172                            else {
7173                                    query = new StringBundler(5);
7174                            }
7175    
7176                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
7177    
7178                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
7179    
7180                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
7181    
7182                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
7183    
7184                            if (orderByComparator != null) {
7185                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7186                                            orderByComparator);
7187                            }
7188    
7189                            else {
7190                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7191                            }
7192    
7193                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7194                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
7195                                            _FILTER_COLUMN_USERID, groupId);
7196    
7197                            SQLQuery q = session.createSQLQuery(sql);
7198    
7199                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
7200    
7201                            QueryPos qPos = QueryPos.getInstance(q);
7202    
7203                            qPos.add(groupId);
7204    
7205                            qPos.add(categoryId);
7206    
7207                            qPos.add(threadId);
7208    
7209                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
7210                    }
7211                    catch (Exception e) {
7212                            throw processException(e);
7213                    }
7214                    finally {
7215                            closeSession(session);
7216                    }
7217            }
7218    
7219            /**
7220             * Finds all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
7221             *
7222             * @param groupId the group id to search with
7223             * @param categoryId the category id to search with
7224             * @param status the status to search with
7225             * @return the matching message-boards messages
7226             * @throws SystemException if a system exception occurred
7227             */
7228            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
7229                    throws SystemException {
7230                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
7231                            QueryUtil.ALL_POS, null);
7232            }
7233    
7234            /**
7235             * Finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
7236             *
7237             * <p>
7238             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7239             * </p>
7240             *
7241             * @param groupId the group id to search with
7242             * @param categoryId the category id to search with
7243             * @param status the status to search with
7244             * @param start the lower bound of the range of message-boards messages to return
7245             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7246             * @return the range of matching message-boards messages
7247             * @throws SystemException if a system exception occurred
7248             */
7249            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
7250                    int status, int start, int end) throws SystemException {
7251                    return findByG_C_S(groupId, categoryId, status, start, end, null);
7252            }
7253    
7254            /**
7255             * Finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
7256             *
7257             * <p>
7258             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7259             * </p>
7260             *
7261             * @param groupId the group id to search with
7262             * @param categoryId the category id to search with
7263             * @param status the status to search with
7264             * @param start the lower bound of the range of message-boards messages to return
7265             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7266             * @param orderByComparator the comparator to order the results by
7267             * @return the ordered range of matching message-boards messages
7268             * @throws SystemException if a system exception occurred
7269             */
7270            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
7271                    int status, int start, int end, OrderByComparator orderByComparator)
7272                    throws SystemException {
7273                    Object[] finderArgs = new Object[] {
7274                                    groupId, categoryId, status,
7275                                    
7276                                    String.valueOf(start), String.valueOf(end),
7277                                    String.valueOf(orderByComparator)
7278                            };
7279    
7280                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
7281                                    finderArgs, this);
7282    
7283                    if (list == null) {
7284                            Session session = null;
7285    
7286                            try {
7287                                    session = openSession();
7288    
7289                                    StringBundler query = null;
7290    
7291                                    if (orderByComparator != null) {
7292                                            query = new StringBundler(5 +
7293                                                            (orderByComparator.getOrderByFields().length * 3));
7294                                    }
7295                                    else {
7296                                            query = new StringBundler(5);
7297                                    }
7298    
7299                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7300    
7301                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7302    
7303                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7304    
7305                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7306    
7307                                    if (orderByComparator != null) {
7308                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7309                                                    orderByComparator);
7310                                    }
7311    
7312                                    else {
7313                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7314                                    }
7315    
7316                                    String sql = query.toString();
7317    
7318                                    Query q = session.createQuery(sql);
7319    
7320                                    QueryPos qPos = QueryPos.getInstance(q);
7321    
7322                                    qPos.add(groupId);
7323    
7324                                    qPos.add(categoryId);
7325    
7326                                    qPos.add(status);
7327    
7328                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7329                                                    end);
7330                            }
7331                            catch (Exception e) {
7332                                    throw processException(e);
7333                            }
7334                            finally {
7335                                    if (list == null) {
7336                                            list = new ArrayList<MBMessage>();
7337                                    }
7338    
7339                                    cacheResult(list);
7340    
7341                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
7342                                            finderArgs, list);
7343    
7344                                    closeSession(session);
7345                            }
7346                    }
7347    
7348                    return list;
7349            }
7350    
7351            /**
7352             * Finds the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7353             *
7354             * <p>
7355             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7356             * </p>
7357             *
7358             * @param groupId the group id to search with
7359             * @param categoryId the category id to search with
7360             * @param status the status to search with
7361             * @param orderByComparator the comparator to order the set by
7362             * @return the first matching message-boards message
7363             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7364             * @throws SystemException if a system exception occurred
7365             */
7366            public MBMessage findByG_C_S_First(long groupId, long categoryId,
7367                    int status, OrderByComparator orderByComparator)
7368                    throws NoSuchMessageException, SystemException {
7369                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
7370                                    orderByComparator);
7371    
7372                    if (list.isEmpty()) {
7373                            StringBundler msg = new StringBundler(8);
7374    
7375                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7376    
7377                            msg.append("groupId=");
7378                            msg.append(groupId);
7379    
7380                            msg.append(", categoryId=");
7381                            msg.append(categoryId);
7382    
7383                            msg.append(", status=");
7384                            msg.append(status);
7385    
7386                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7387    
7388                            throw new NoSuchMessageException(msg.toString());
7389                    }
7390                    else {
7391                            return list.get(0);
7392                    }
7393            }
7394    
7395            /**
7396             * Finds the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7397             *
7398             * <p>
7399             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7400             * </p>
7401             *
7402             * @param groupId the group id to search with
7403             * @param categoryId the category id to search with
7404             * @param status the status to search with
7405             * @param orderByComparator the comparator to order the set by
7406             * @return the last matching message-boards message
7407             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7408             * @throws SystemException if a system exception occurred
7409             */
7410            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
7411                    int status, OrderByComparator orderByComparator)
7412                    throws NoSuchMessageException, SystemException {
7413                    int count = countByG_C_S(groupId, categoryId, status);
7414    
7415                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
7416                                    count - 1, count, orderByComparator);
7417    
7418                    if (list.isEmpty()) {
7419                            StringBundler msg = new StringBundler(8);
7420    
7421                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7422    
7423                            msg.append("groupId=");
7424                            msg.append(groupId);
7425    
7426                            msg.append(", categoryId=");
7427                            msg.append(categoryId);
7428    
7429                            msg.append(", status=");
7430                            msg.append(status);
7431    
7432                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7433    
7434                            throw new NoSuchMessageException(msg.toString());
7435                    }
7436                    else {
7437                            return list.get(0);
7438                    }
7439            }
7440    
7441            /**
7442             * Finds 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;.
7443             *
7444             * <p>
7445             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7446             * </p>
7447             *
7448             * @param messageId the primary key of the current message-boards message
7449             * @param groupId the group id to search with
7450             * @param categoryId the category id to search with
7451             * @param status the status to search with
7452             * @param orderByComparator the comparator to order the set by
7453             * @return the previous, current, and next message-boards message
7454             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7455             * @throws SystemException if a system exception occurred
7456             */
7457            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
7458                    long categoryId, int status, OrderByComparator orderByComparator)
7459                    throws NoSuchMessageException, SystemException {
7460                    MBMessage mbMessage = findByPrimaryKey(messageId);
7461    
7462                    Session session = null;
7463    
7464                    try {
7465                            session = openSession();
7466    
7467                            MBMessage[] array = new MBMessageImpl[3];
7468    
7469                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
7470                                            categoryId, status, orderByComparator, true);
7471    
7472                            array[1] = mbMessage;
7473    
7474                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
7475                                            categoryId, status, orderByComparator, false);
7476    
7477                            return array;
7478                    }
7479                    catch (Exception e) {
7480                            throw processException(e);
7481                    }
7482                    finally {
7483                            closeSession(session);
7484                    }
7485            }
7486    
7487            protected MBMessage getByG_C_S_PrevAndNext(Session session,
7488                    MBMessage mbMessage, long groupId, long categoryId, int status,
7489                    OrderByComparator orderByComparator, boolean previous) {
7490                    StringBundler query = null;
7491    
7492                    if (orderByComparator != null) {
7493                            query = new StringBundler(6 +
7494                                            (orderByComparator.getOrderByFields().length * 6));
7495                    }
7496                    else {
7497                            query = new StringBundler(3);
7498                    }
7499    
7500                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7501    
7502                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7503    
7504                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7505    
7506                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7507    
7508                    if (orderByComparator != null) {
7509                            String[] orderByFields = orderByComparator.getOrderByFields();
7510    
7511                            if (orderByFields.length > 0) {
7512                                    query.append(WHERE_AND);
7513                            }
7514    
7515                            for (int i = 0; i < orderByFields.length; i++) {
7516                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7517                                    query.append(orderByFields[i]);
7518    
7519                                    if ((i + 1) < orderByFields.length) {
7520                                            if (orderByComparator.isAscending() ^ previous) {
7521                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7522                                            }
7523                                            else {
7524                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7525                                            }
7526                                    }
7527                                    else {
7528                                            if (orderByComparator.isAscending() ^ previous) {
7529                                                    query.append(WHERE_GREATER_THAN);
7530                                            }
7531                                            else {
7532                                                    query.append(WHERE_LESSER_THAN);
7533                                            }
7534                                    }
7535                            }
7536    
7537                            query.append(ORDER_BY_CLAUSE);
7538    
7539                            for (int i = 0; i < orderByFields.length; i++) {
7540                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7541                                    query.append(orderByFields[i]);
7542    
7543                                    if ((i + 1) < orderByFields.length) {
7544                                            if (orderByComparator.isAscending() ^ previous) {
7545                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7546                                            }
7547                                            else {
7548                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7549                                            }
7550                                    }
7551                                    else {
7552                                            if (orderByComparator.isAscending() ^ previous) {
7553                                                    query.append(ORDER_BY_ASC);
7554                                            }
7555                                            else {
7556                                                    query.append(ORDER_BY_DESC);
7557                                            }
7558                                    }
7559                            }
7560                    }
7561    
7562                    else {
7563                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7564                    }
7565    
7566                    String sql = query.toString();
7567    
7568                    Query q = session.createQuery(sql);
7569    
7570                    q.setFirstResult(0);
7571                    q.setMaxResults(2);
7572    
7573                    QueryPos qPos = QueryPos.getInstance(q);
7574    
7575                    qPos.add(groupId);
7576    
7577                    qPos.add(categoryId);
7578    
7579                    qPos.add(status);
7580    
7581                    if (orderByComparator != null) {
7582                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
7583    
7584                            for (Object value : values) {
7585                                    qPos.add(value);
7586                            }
7587                    }
7588    
7589                    List<MBMessage> list = q.list();
7590    
7591                    if (list.size() == 2) {
7592                            return list.get(1);
7593                    }
7594                    else {
7595                            return null;
7596                    }
7597            }
7598    
7599            /**
7600             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
7601             *
7602             * @param groupId the group id to search with
7603             * @param categoryId the category id to search with
7604             * @param status the status to search with
7605             * @return the matching message-boards messages that the user has permission to view
7606             * @throws SystemException if a system exception occurred
7607             */
7608            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
7609                    int status) throws SystemException {
7610                    return filterFindByG_C_S(groupId, categoryId, status,
7611                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7612            }
7613    
7614            /**
7615             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
7616             *
7617             * <p>
7618             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7619             * </p>
7620             *
7621             * @param groupId the group id to search with
7622             * @param categoryId the category id to search with
7623             * @param status the status to search with
7624             * @param start the lower bound of the range of message-boards messages to return
7625             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7626             * @return the range of matching message-boards messages that the user has permission to view
7627             * @throws SystemException if a system exception occurred
7628             */
7629            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
7630                    int status, int start, int end) throws SystemException {
7631                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
7632            }
7633    
7634            /**
7635             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
7636             *
7637             * <p>
7638             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7639             * </p>
7640             *
7641             * @param groupId the group id to search with
7642             * @param categoryId the category id to search with
7643             * @param status the status to search with
7644             * @param start the lower bound of the range of message-boards messages to return
7645             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7646             * @param orderByComparator the comparator to order the results by
7647             * @return the ordered range of matching message-boards messages that the user has permission to view
7648             * @throws SystemException if a system exception occurred
7649             */
7650            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
7651                    int status, int start, int end, OrderByComparator orderByComparator)
7652                    throws SystemException {
7653                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7654                            return findByG_C_S(groupId, categoryId, status, start, end,
7655                                    orderByComparator);
7656                    }
7657    
7658                    Session session = null;
7659    
7660                    try {
7661                            session = openSession();
7662    
7663                            StringBundler query = null;
7664    
7665                            if (orderByComparator != null) {
7666                                    query = new StringBundler(5 +
7667                                                    (orderByComparator.getOrderByFields().length * 3));
7668                            }
7669                            else {
7670                                    query = new StringBundler(5);
7671                            }
7672    
7673                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
7674    
7675                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7676    
7677                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7678    
7679                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7680    
7681                            if (orderByComparator != null) {
7682                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7683                                            orderByComparator);
7684                            }
7685    
7686                            else {
7687                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7688                            }
7689    
7690                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7691                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
7692                                            _FILTER_COLUMN_USERID, groupId);
7693    
7694                            SQLQuery q = session.createSQLQuery(sql);
7695    
7696                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
7697    
7698                            QueryPos qPos = QueryPos.getInstance(q);
7699    
7700                            qPos.add(groupId);
7701    
7702                            qPos.add(categoryId);
7703    
7704                            qPos.add(status);
7705    
7706                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
7707                    }
7708                    catch (Exception e) {
7709                            throw processException(e);
7710                    }
7711                    finally {
7712                            closeSession(session);
7713                    }
7714            }
7715    
7716            /**
7717             * Finds all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
7718             *
7719             * @param classNameId the class name id to search with
7720             * @param classPK the class p k to search with
7721             * @param status the status to search with
7722             * @return the matching message-boards messages
7723             * @throws SystemException if a system exception occurred
7724             */
7725            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
7726                    int status) throws SystemException {
7727                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
7728                            QueryUtil.ALL_POS, null);
7729            }
7730    
7731            /**
7732             * Finds a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
7733             *
7734             * <p>
7735             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7736             * </p>
7737             *
7738             * @param classNameId the class name id to search with
7739             * @param classPK the class p k to search with
7740             * @param status the status to search with
7741             * @param start the lower bound of the range of message-boards messages to return
7742             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7743             * @return the range of matching message-boards messages
7744             * @throws SystemException if a system exception occurred
7745             */
7746            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
7747                    int status, int start, int end) throws SystemException {
7748                    return findByC_C_S(classNameId, classPK, status, start, end, null);
7749            }
7750    
7751            /**
7752             * Finds an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
7753             *
7754             * <p>
7755             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7756             * </p>
7757             *
7758             * @param classNameId the class name id to search with
7759             * @param classPK the class p k to search with
7760             * @param status the status to search with
7761             * @param start the lower bound of the range of message-boards messages to return
7762             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
7763             * @param orderByComparator the comparator to order the results by
7764             * @return the ordered range of matching message-boards messages
7765             * @throws SystemException if a system exception occurred
7766             */
7767            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
7768                    int status, int start, int end, OrderByComparator orderByComparator)
7769                    throws SystemException {
7770                    Object[] finderArgs = new Object[] {
7771                                    classNameId, classPK, status,
7772                                    
7773                                    String.valueOf(start), String.valueOf(end),
7774                                    String.valueOf(orderByComparator)
7775                            };
7776    
7777                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_S,
7778                                    finderArgs, this);
7779    
7780                    if (list == null) {
7781                            Session session = null;
7782    
7783                            try {
7784                                    session = openSession();
7785    
7786                                    StringBundler query = null;
7787    
7788                                    if (orderByComparator != null) {
7789                                            query = new StringBundler(5 +
7790                                                            (orderByComparator.getOrderByFields().length * 3));
7791                                    }
7792                                    else {
7793                                            query = new StringBundler(5);
7794                                    }
7795    
7796                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7797    
7798                                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
7799    
7800                                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
7801    
7802                                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
7803    
7804                                    if (orderByComparator != null) {
7805                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7806                                                    orderByComparator);
7807                                    }
7808    
7809                                    else {
7810                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7811                                    }
7812    
7813                                    String sql = query.toString();
7814    
7815                                    Query q = session.createQuery(sql);
7816    
7817                                    QueryPos qPos = QueryPos.getInstance(q);
7818    
7819                                    qPos.add(classNameId);
7820    
7821                                    qPos.add(classPK);
7822    
7823                                    qPos.add(status);
7824    
7825                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7826                                                    end);
7827                            }
7828                            catch (Exception e) {
7829                                    throw processException(e);
7830                            }
7831                            finally {
7832                                    if (list == null) {
7833                                            list = new ArrayList<MBMessage>();
7834                                    }
7835    
7836                                    cacheResult(list);
7837    
7838                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_S,
7839                                            finderArgs, list);
7840    
7841                                    closeSession(session);
7842                            }
7843                    }
7844    
7845                    return list;
7846            }
7847    
7848            /**
7849             * Finds the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
7850             *
7851             * <p>
7852             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7853             * </p>
7854             *
7855             * @param classNameId the class name id to search with
7856             * @param classPK the class p k to search with
7857             * @param status the status to search with
7858             * @param orderByComparator the comparator to order the set by
7859             * @return the first matching message-boards message
7860             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7861             * @throws SystemException if a system exception occurred
7862             */
7863            public MBMessage findByC_C_S_First(long classNameId, long classPK,
7864                    int status, OrderByComparator orderByComparator)
7865                    throws NoSuchMessageException, SystemException {
7866                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
7867                                    orderByComparator);
7868    
7869                    if (list.isEmpty()) {
7870                            StringBundler msg = new StringBundler(8);
7871    
7872                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7873    
7874                            msg.append("classNameId=");
7875                            msg.append(classNameId);
7876    
7877                            msg.append(", classPK=");
7878                            msg.append(classPK);
7879    
7880                            msg.append(", status=");
7881                            msg.append(status);
7882    
7883                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7884    
7885                            throw new NoSuchMessageException(msg.toString());
7886                    }
7887                    else {
7888                            return list.get(0);
7889                    }
7890            }
7891    
7892            /**
7893             * Finds the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
7894             *
7895             * <p>
7896             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7897             * </p>
7898             *
7899             * @param classNameId the class name id to search with
7900             * @param classPK the class p k to search with
7901             * @param status the status to search with
7902             * @param orderByComparator the comparator to order the set by
7903             * @return the last matching message-boards message
7904             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7905             * @throws SystemException if a system exception occurred
7906             */
7907            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
7908                    int status, OrderByComparator orderByComparator)
7909                    throws NoSuchMessageException, SystemException {
7910                    int count = countByC_C_S(classNameId, classPK, status);
7911    
7912                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
7913                                    count - 1, count, orderByComparator);
7914    
7915                    if (list.isEmpty()) {
7916                            StringBundler msg = new StringBundler(8);
7917    
7918                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7919    
7920                            msg.append("classNameId=");
7921                            msg.append(classNameId);
7922    
7923                            msg.append(", classPK=");
7924                            msg.append(classPK);
7925    
7926                            msg.append(", status=");
7927                            msg.append(status);
7928    
7929                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7930    
7931                            throw new NoSuchMessageException(msg.toString());
7932                    }
7933                    else {
7934                            return list.get(0);
7935                    }
7936            }
7937    
7938            /**
7939             * Finds 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;.
7940             *
7941             * <p>
7942             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7943             * </p>
7944             *
7945             * @param messageId the primary key of the current message-boards message
7946             * @param classNameId the class name id to search with
7947             * @param classPK the class p k to search with
7948             * @param status the status to search with
7949             * @param orderByComparator the comparator to order the set by
7950             * @return the previous, current, and next message-boards message
7951             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7952             * @throws SystemException if a system exception occurred
7953             */
7954            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
7955                    long classNameId, long classPK, int status,
7956                    OrderByComparator orderByComparator)
7957                    throws NoSuchMessageException, SystemException {
7958                    MBMessage mbMessage = findByPrimaryKey(messageId);
7959    
7960                    Session session = null;
7961    
7962                    try {
7963                            session = openSession();
7964    
7965                            MBMessage[] array = new MBMessageImpl[3];
7966    
7967                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
7968                                            classPK, status, orderByComparator, true);
7969    
7970                            array[1] = mbMessage;
7971    
7972                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
7973                                            classPK, status, orderByComparator, false);
7974    
7975                            return array;
7976                    }
7977                    catch (Exception e) {
7978                            throw processException(e);
7979                    }
7980                    finally {
7981                            closeSession(session);
7982                    }
7983            }
7984    
7985            protected MBMessage getByC_C_S_PrevAndNext(Session session,
7986                    MBMessage mbMessage, long classNameId, long classPK, int status,
7987                    OrderByComparator orderByComparator, boolean previous) {
7988                    StringBundler query = null;
7989    
7990                    if (orderByComparator != null) {
7991                            query = new StringBundler(6 +
7992                                            (orderByComparator.getOrderByFields().length * 6));
7993                    }
7994                    else {
7995                            query = new StringBundler(3);
7996                    }
7997    
7998                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7999    
8000                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
8001    
8002                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
8003    
8004                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
8005    
8006                    if (orderByComparator != null) {
8007                            String[] orderByFields = orderByComparator.getOrderByFields();
8008    
8009                            if (orderByFields.length > 0) {
8010                                    query.append(WHERE_AND);
8011                            }
8012    
8013                            for (int i = 0; i < orderByFields.length; i++) {
8014                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8015                                    query.append(orderByFields[i]);
8016    
8017                                    if ((i + 1) < orderByFields.length) {
8018                                            if (orderByComparator.isAscending() ^ previous) {
8019                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8020                                            }
8021                                            else {
8022                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8023                                            }
8024                                    }
8025                                    else {
8026                                            if (orderByComparator.isAscending() ^ previous) {
8027                                                    query.append(WHERE_GREATER_THAN);
8028                                            }
8029                                            else {
8030                                                    query.append(WHERE_LESSER_THAN);
8031                                            }
8032                                    }
8033                            }
8034    
8035                            query.append(ORDER_BY_CLAUSE);
8036    
8037                            for (int i = 0; i < orderByFields.length; i++) {
8038                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8039                                    query.append(orderByFields[i]);
8040    
8041                                    if ((i + 1) < orderByFields.length) {
8042                                            if (orderByComparator.isAscending() ^ previous) {
8043                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8044                                            }
8045                                            else {
8046                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8047                                            }
8048                                    }
8049                                    else {
8050                                            if (orderByComparator.isAscending() ^ previous) {
8051                                                    query.append(ORDER_BY_ASC);
8052                                            }
8053                                            else {
8054                                                    query.append(ORDER_BY_DESC);
8055                                            }
8056                                    }
8057                            }
8058                    }
8059    
8060                    else {
8061                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8062                    }
8063    
8064                    String sql = query.toString();
8065    
8066                    Query q = session.createQuery(sql);
8067    
8068                    q.setFirstResult(0);
8069                    q.setMaxResults(2);
8070    
8071                    QueryPos qPos = QueryPos.getInstance(q);
8072    
8073                    qPos.add(classNameId);
8074    
8075                    qPos.add(classPK);
8076    
8077                    qPos.add(status);
8078    
8079                    if (orderByComparator != null) {
8080                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
8081    
8082                            for (Object value : values) {
8083                                    qPos.add(value);
8084                            }
8085                    }
8086    
8087                    List<MBMessage> list = q.list();
8088    
8089                    if (list.size() == 2) {
8090                            return list.get(1);
8091                    }
8092                    else {
8093                            return null;
8094                    }
8095            }
8096    
8097            /**
8098             * Finds all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8099             *
8100             * @param groupId the group id to search with
8101             * @param categoryId the category id to search with
8102             * @param threadId the thread id to search with
8103             * @param status the status to search with
8104             * @return the matching message-boards messages
8105             * @throws SystemException if a system exception occurred
8106             */
8107            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
8108                    long threadId, int status) throws SystemException {
8109                    return findByG_C_T_S(groupId, categoryId, threadId, status,
8110                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8111            }
8112    
8113            /**
8114             * Finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8115             *
8116             * <p>
8117             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8118             * </p>
8119             *
8120             * @param groupId the group id to search with
8121             * @param categoryId the category id to search with
8122             * @param threadId the thread id to search with
8123             * @param status the status to search with
8124             * @param start the lower bound of the range of message-boards messages to return
8125             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
8126             * @return the range of matching message-boards messages
8127             * @throws SystemException if a system exception occurred
8128             */
8129            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
8130                    long threadId, int status, int start, int end)
8131                    throws SystemException {
8132                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
8133                            null);
8134            }
8135    
8136            /**
8137             * Finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8138             *
8139             * <p>
8140             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8141             * </p>
8142             *
8143             * @param groupId the group id to search with
8144             * @param categoryId the category id to search with
8145             * @param threadId the thread id to search with
8146             * @param status the status to search with
8147             * @param start the lower bound of the range of message-boards messages to return
8148             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
8149             * @param orderByComparator the comparator to order the results by
8150             * @return the ordered range of matching message-boards messages
8151             * @throws SystemException if a system exception occurred
8152             */
8153            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
8154                    long threadId, int status, int start, int end,
8155                    OrderByComparator orderByComparator) throws SystemException {
8156                    Object[] finderArgs = new Object[] {
8157                                    groupId, categoryId, threadId, status,
8158                                    
8159                                    String.valueOf(start), String.valueOf(end),
8160                                    String.valueOf(orderByComparator)
8161                            };
8162    
8163                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_T_S,
8164                                    finderArgs, this);
8165    
8166                    if (list == null) {
8167                            Session session = null;
8168    
8169                            try {
8170                                    session = openSession();
8171    
8172                                    StringBundler query = null;
8173    
8174                                    if (orderByComparator != null) {
8175                                            query = new StringBundler(6 +
8176                                                            (orderByComparator.getOrderByFields().length * 3));
8177                                    }
8178                                    else {
8179                                            query = new StringBundler(6);
8180                                    }
8181    
8182                                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8183    
8184                                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
8185    
8186                                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
8187    
8188                                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
8189    
8190                                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
8191    
8192                                    if (orderByComparator != null) {
8193                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8194                                                    orderByComparator);
8195                                    }
8196    
8197                                    else {
8198                                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8199                                    }
8200    
8201                                    String sql = query.toString();
8202    
8203                                    Query q = session.createQuery(sql);
8204    
8205                                    QueryPos qPos = QueryPos.getInstance(q);
8206    
8207                                    qPos.add(groupId);
8208    
8209                                    qPos.add(categoryId);
8210    
8211                                    qPos.add(threadId);
8212    
8213                                    qPos.add(status);
8214    
8215                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8216                                                    end);
8217                            }
8218                            catch (Exception e) {
8219                                    throw processException(e);
8220                            }
8221                            finally {
8222                                    if (list == null) {
8223                                            list = new ArrayList<MBMessage>();
8224                                    }
8225    
8226                                    cacheResult(list);
8227    
8228                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_T_S,
8229                                            finderArgs, list);
8230    
8231                                    closeSession(session);
8232                            }
8233                    }
8234    
8235                    return list;
8236            }
8237    
8238            /**
8239             * Finds the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8240             *
8241             * <p>
8242             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8243             * </p>
8244             *
8245             * @param groupId the group id to search with
8246             * @param categoryId the category id to search with
8247             * @param threadId the thread id to search with
8248             * @param status the status to search with
8249             * @param orderByComparator the comparator to order the set by
8250             * @return the first matching message-boards message
8251             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8252             * @throws SystemException if a system exception occurred
8253             */
8254            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
8255                    long threadId, int status, OrderByComparator orderByComparator)
8256                    throws NoSuchMessageException, SystemException {
8257                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
8258                                    status, 0, 1, orderByComparator);
8259    
8260                    if (list.isEmpty()) {
8261                            StringBundler msg = new StringBundler(10);
8262    
8263                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8264    
8265                            msg.append("groupId=");
8266                            msg.append(groupId);
8267    
8268                            msg.append(", categoryId=");
8269                            msg.append(categoryId);
8270    
8271                            msg.append(", threadId=");
8272                            msg.append(threadId);
8273    
8274                            msg.append(", status=");
8275                            msg.append(status);
8276    
8277                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8278    
8279                            throw new NoSuchMessageException(msg.toString());
8280                    }
8281                    else {
8282                            return list.get(0);
8283                    }
8284            }
8285    
8286            /**
8287             * Finds the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8288             *
8289             * <p>
8290             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8291             * </p>
8292             *
8293             * @param groupId the group id to search with
8294             * @param categoryId the category id to search with
8295             * @param threadId the thread id to search with
8296             * @param status the status to search with
8297             * @param orderByComparator the comparator to order the set by
8298             * @return the last matching message-boards message
8299             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8300             * @throws SystemException if a system exception occurred
8301             */
8302            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
8303                    long threadId, int status, OrderByComparator orderByComparator)
8304                    throws NoSuchMessageException, SystemException {
8305                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
8306    
8307                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
8308                                    status, count - 1, count, orderByComparator);
8309    
8310                    if (list.isEmpty()) {
8311                            StringBundler msg = new StringBundler(10);
8312    
8313                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8314    
8315                            msg.append("groupId=");
8316                            msg.append(groupId);
8317    
8318                            msg.append(", categoryId=");
8319                            msg.append(categoryId);
8320    
8321                            msg.append(", threadId=");
8322                            msg.append(threadId);
8323    
8324                            msg.append(", status=");
8325                            msg.append(status);
8326    
8327                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8328    
8329                            throw new NoSuchMessageException(msg.toString());
8330                    }
8331                    else {
8332                            return list.get(0);
8333                    }
8334            }
8335    
8336            /**
8337             * Finds 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;.
8338             *
8339             * <p>
8340             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8341             * </p>
8342             *
8343             * @param messageId the primary key of the current message-boards message
8344             * @param groupId the group id to search with
8345             * @param categoryId the category id to search with
8346             * @param threadId the thread id to search with
8347             * @param status the status to search with
8348             * @param orderByComparator the comparator to order the set by
8349             * @return the previous, current, and next message-boards message
8350             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8351             * @throws SystemException if a system exception occurred
8352             */
8353            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
8354                    long categoryId, long threadId, int status,
8355                    OrderByComparator orderByComparator)
8356                    throws NoSuchMessageException, SystemException {
8357                    MBMessage mbMessage = findByPrimaryKey(messageId);
8358    
8359                    Session session = null;
8360    
8361                    try {
8362                            session = openSession();
8363    
8364                            MBMessage[] array = new MBMessageImpl[3];
8365    
8366                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
8367                                            categoryId, threadId, status, orderByComparator, true);
8368    
8369                            array[1] = mbMessage;
8370    
8371                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
8372                                            categoryId, threadId, status, orderByComparator, false);
8373    
8374                            return array;
8375                    }
8376                    catch (Exception e) {
8377                            throw processException(e);
8378                    }
8379                    finally {
8380                            closeSession(session);
8381                    }
8382            }
8383    
8384            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
8385                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
8386                    int status, OrderByComparator orderByComparator, boolean previous) {
8387                    StringBundler query = null;
8388    
8389                    if (orderByComparator != null) {
8390                            query = new StringBundler(6 +
8391                                            (orderByComparator.getOrderByFields().length * 6));
8392                    }
8393                    else {
8394                            query = new StringBundler(3);
8395                    }
8396    
8397                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8398    
8399                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
8400    
8401                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
8402    
8403                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
8404    
8405                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
8406    
8407                    if (orderByComparator != null) {
8408                            String[] orderByFields = orderByComparator.getOrderByFields();
8409    
8410                            if (orderByFields.length > 0) {
8411                                    query.append(WHERE_AND);
8412                            }
8413    
8414                            for (int i = 0; i < orderByFields.length; i++) {
8415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8416                                    query.append(orderByFields[i]);
8417    
8418                                    if ((i + 1) < orderByFields.length) {
8419                                            if (orderByComparator.isAscending() ^ previous) {
8420                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8421                                            }
8422                                            else {
8423                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8424                                            }
8425                                    }
8426                                    else {
8427                                            if (orderByComparator.isAscending() ^ previous) {
8428                                                    query.append(WHERE_GREATER_THAN);
8429                                            }
8430                                            else {
8431                                                    query.append(WHERE_LESSER_THAN);
8432                                            }
8433                                    }
8434                            }
8435    
8436                            query.append(ORDER_BY_CLAUSE);
8437    
8438                            for (int i = 0; i < orderByFields.length; i++) {
8439                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8440                                    query.append(orderByFields[i]);
8441    
8442                                    if ((i + 1) < orderByFields.length) {
8443                                            if (orderByComparator.isAscending() ^ previous) {
8444                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8445                                            }
8446                                            else {
8447                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8448                                            }
8449                                    }
8450                                    else {
8451                                            if (orderByComparator.isAscending() ^ previous) {
8452                                                    query.append(ORDER_BY_ASC);
8453                                            }
8454                                            else {
8455                                                    query.append(ORDER_BY_DESC);
8456                                            }
8457                                    }
8458                            }
8459                    }
8460    
8461                    else {
8462                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8463                    }
8464    
8465                    String sql = query.toString();
8466    
8467                    Query q = session.createQuery(sql);
8468    
8469                    q.setFirstResult(0);
8470                    q.setMaxResults(2);
8471    
8472                    QueryPos qPos = QueryPos.getInstance(q);
8473    
8474                    qPos.add(groupId);
8475    
8476                    qPos.add(categoryId);
8477    
8478                    qPos.add(threadId);
8479    
8480                    qPos.add(status);
8481    
8482                    if (orderByComparator != null) {
8483                            Object[] values = orderByComparator.getOrderByValues(mbMessage);
8484    
8485                            for (Object value : values) {
8486                                    qPos.add(value);
8487                            }
8488                    }
8489    
8490                    List<MBMessage> list = q.list();
8491    
8492                    if (list.size() == 2) {
8493                            return list.get(1);
8494                    }
8495                    else {
8496                            return null;
8497                    }
8498            }
8499    
8500            /**
8501             * Filters by the user's permissions and finds all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8502             *
8503             * @param groupId the group id to search with
8504             * @param categoryId the category id to search with
8505             * @param threadId the thread id to search with
8506             * @param status the status to search with
8507             * @return the matching message-boards messages that the user has permission to view
8508             * @throws SystemException if a system exception occurred
8509             */
8510            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
8511                    long threadId, int status) throws SystemException {
8512                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
8513                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8514            }
8515    
8516            /**
8517             * Filters by the user's permissions and finds a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8521             * </p>
8522             *
8523             * @param groupId the group id to search with
8524             * @param categoryId the category id to search with
8525             * @param threadId the thread id to search with
8526             * @param status the status to search with
8527             * @param start the lower bound of the range of message-boards messages to return
8528             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
8529             * @return the range of matching message-boards messages that the user has permission to view
8530             * @throws SystemException if a system exception occurred
8531             */
8532            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
8533                    long threadId, int status, int start, int end)
8534                    throws SystemException {
8535                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
8536                            start, end, null);
8537            }
8538    
8539            /**
8540             * Filters by the user's permissions and finds an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
8541             *
8542             * <p>
8543             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8544             * </p>
8545             *
8546             * @param groupId the group id to search with
8547             * @param categoryId the category id to search with
8548             * @param threadId the thread id to search with
8549             * @param status the status to search with
8550             * @param start the lower bound of the range of message-boards messages to return
8551             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
8552             * @param orderByComparator the comparator to order the results by
8553             * @return the ordered range of matching message-boards messages that the user has permission to view
8554             * @throws SystemException if a system exception occurred
8555             */
8556            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
8557                    long threadId, int status, int start, int end,
8558                    OrderByComparator orderByComparator) throws SystemException {
8559                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8560                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
8561                                    end, orderByComparator);
8562                    }
8563    
8564                    Session session = null;
8565    
8566                    try {
8567                            session = openSession();
8568    
8569                            StringBundler query = null;
8570    
8571                            if (orderByComparator != null) {
8572                                    query = new StringBundler(6 +
8573                                                    (orderByComparator.getOrderByFields().length * 3));
8574                            }
8575                            else {
8576                                    query = new StringBundler(6);
8577                            }
8578    
8579                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
8580    
8581                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
8582    
8583                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
8584    
8585                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
8586    
8587                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
8588    
8589                            if (orderByComparator != null) {
8590                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8591                                            orderByComparator);
8592                            }
8593    
8594                            else {
8595                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8596                            }
8597    
8598                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8599                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
8600                                            _FILTER_COLUMN_USERID, groupId);
8601    
8602                            SQLQuery q = session.createSQLQuery(sql);
8603    
8604                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
8605    
8606                            QueryPos qPos = QueryPos.getInstance(q);
8607    
8608                            qPos.add(groupId);
8609    
8610                            qPos.add(categoryId);
8611    
8612                            qPos.add(threadId);
8613    
8614                            qPos.add(status);
8615    
8616                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
8617                    }
8618                    catch (Exception e) {
8619                            throw processException(e);
8620                    }
8621                    finally {
8622                            closeSession(session);
8623                    }
8624            }
8625    
8626            /**
8627             * Finds all the message-boards messages.
8628             *
8629             * @return the message-boards messages
8630             * @throws SystemException if a system exception occurred
8631             */
8632            public List<MBMessage> findAll() throws SystemException {
8633                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8634            }
8635    
8636            /**
8637             * Finds a range of all the message-boards messages.
8638             *
8639             * <p>
8640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8641             * </p>
8642             *
8643             * @param start the lower bound of the range of message-boards messages to return
8644             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
8645             * @return the range of message-boards messages
8646             * @throws SystemException if a system exception occurred
8647             */
8648            public List<MBMessage> findAll(int start, int end)
8649                    throws SystemException {
8650                    return findAll(start, end, null);
8651            }
8652    
8653            /**
8654             * Finds an ordered range of all the message-boards messages.
8655             *
8656             * <p>
8657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8658             * </p>
8659             *
8660             * @param start the lower bound of the range of message-boards messages to return
8661             * @param end the upper bound of the range of message-boards messages to return (not inclusive)
8662             * @param orderByComparator the comparator to order the results by
8663             * @return the ordered range of message-boards messages
8664             * @throws SystemException if a system exception occurred
8665             */
8666            public List<MBMessage> findAll(int start, int end,
8667                    OrderByComparator orderByComparator) throws SystemException {
8668                    Object[] finderArgs = new Object[] {
8669                                    String.valueOf(start), String.valueOf(end),
8670                                    String.valueOf(orderByComparator)
8671                            };
8672    
8673                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
8674                                    finderArgs, this);
8675    
8676                    if (list == null) {
8677                            Session session = null;
8678    
8679                            try {
8680                                    session = openSession();
8681    
8682                                    StringBundler query = null;
8683                                    String sql = null;
8684    
8685                                    if (orderByComparator != null) {
8686                                            query = new StringBundler(2 +
8687                                                            (orderByComparator.getOrderByFields().length * 3));
8688    
8689                                            query.append(_SQL_SELECT_MBMESSAGE);
8690    
8691                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8692                                                    orderByComparator);
8693    
8694                                            sql = query.toString();
8695                                    }
8696                                    else {
8697                                            sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
8698                                    }
8699    
8700                                    Query q = session.createQuery(sql);
8701    
8702                                    if (orderByComparator == null) {
8703                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8704                                                            start, end, false);
8705    
8706                                            Collections.sort(list);
8707                                    }
8708                                    else {
8709                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8710                                                            start, end);
8711                                    }
8712                            }
8713                            catch (Exception e) {
8714                                    throw processException(e);
8715                            }
8716                            finally {
8717                                    if (list == null) {
8718                                            list = new ArrayList<MBMessage>();
8719                                    }
8720    
8721                                    cacheResult(list);
8722    
8723                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
8724    
8725                                    closeSession(session);
8726                            }
8727                    }
8728    
8729                    return list;
8730            }
8731    
8732            /**
8733             * Removes all the message-boards messages where uuid = &#63; from the database.
8734             *
8735             * @param uuid the uuid to search with
8736             * @throws SystemException if a system exception occurred
8737             */
8738            public void removeByUuid(String uuid) throws SystemException {
8739                    for (MBMessage mbMessage : findByUuid(uuid)) {
8740                            remove(mbMessage);
8741                    }
8742            }
8743    
8744            /**
8745             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
8746             *
8747             * @param uuid the uuid to search with
8748             * @param groupId the group id to search with
8749             * @throws SystemException if a system exception occurred
8750             */
8751            public void removeByUUID_G(String uuid, long groupId)
8752                    throws NoSuchMessageException, SystemException {
8753                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
8754    
8755                    remove(mbMessage);
8756            }
8757    
8758            /**
8759             * Removes all the message-boards messages where groupId = &#63; from the database.
8760             *
8761             * @param groupId the group id to search with
8762             * @throws SystemException if a system exception occurred
8763             */
8764            public void removeByGroupId(long groupId) throws SystemException {
8765                    for (MBMessage mbMessage : findByGroupId(groupId)) {
8766                            remove(mbMessage);
8767                    }
8768            }
8769    
8770            /**
8771             * Removes all the message-boards messages where companyId = &#63; from the database.
8772             *
8773             * @param companyId the company id to search with
8774             * @throws SystemException if a system exception occurred
8775             */
8776            public void removeByCompanyId(long companyId) throws SystemException {
8777                    for (MBMessage mbMessage : findByCompanyId(companyId)) {
8778                            remove(mbMessage);
8779                    }
8780            }
8781    
8782            /**
8783             * Removes all the message-boards messages where threadId = &#63; from the database.
8784             *
8785             * @param threadId the thread id to search with
8786             * @throws SystemException if a system exception occurred
8787             */
8788            public void removeByThreadId(long threadId) throws SystemException {
8789                    for (MBMessage mbMessage : findByThreadId(threadId)) {
8790                            remove(mbMessage);
8791                    }
8792            }
8793    
8794            /**
8795             * Removes all the message-boards messages where threadId = &#63; from the database.
8796             *
8797             * @param threadId the thread id to search with
8798             * @throws SystemException if a system exception occurred
8799             */
8800            public void removeByThreadReplies(long threadId) throws SystemException {
8801                    for (MBMessage mbMessage : findByThreadReplies(threadId)) {
8802                            remove(mbMessage);
8803                    }
8804            }
8805    
8806            /**
8807             * Removes all the message-boards messages where userId = &#63; from the database.
8808             *
8809             * @param userId the user id to search with
8810             * @throws SystemException if a system exception occurred
8811             */
8812            public void removeByUserId(long userId) throws SystemException {
8813                    for (MBMessage mbMessage : findByUserId(userId)) {
8814                            remove(mbMessage);
8815                    }
8816            }
8817    
8818            /**
8819             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
8820             *
8821             * @param groupId the group id to search with
8822             * @param userId the user id to search with
8823             * @throws SystemException if a system exception occurred
8824             */
8825            public void removeByG_U(long groupId, long userId)
8826                    throws SystemException {
8827                    for (MBMessage mbMessage : findByG_U(groupId, userId)) {
8828                            remove(mbMessage);
8829                    }
8830            }
8831    
8832            /**
8833             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
8834             *
8835             * @param groupId the group id to search with
8836             * @param categoryId the category id to search with
8837             * @throws SystemException if a system exception occurred
8838             */
8839            public void removeByG_C(long groupId, long categoryId)
8840                    throws SystemException {
8841                    for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
8842                            remove(mbMessage);
8843                    }
8844            }
8845    
8846            /**
8847             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
8848             *
8849             * @param groupId the group id to search with
8850             * @param status the status to search with
8851             * @throws SystemException if a system exception occurred
8852             */
8853            public void removeByG_S(long groupId, int status) throws SystemException {
8854                    for (MBMessage mbMessage : findByG_S(groupId, status)) {
8855                            remove(mbMessage);
8856                    }
8857            }
8858    
8859            /**
8860             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
8861             *
8862             * @param companyId the company id to search with
8863             * @param status the status to search with
8864             * @throws SystemException if a system exception occurred
8865             */
8866            public void removeByC_S(long companyId, int status)
8867                    throws SystemException {
8868                    for (MBMessage mbMessage : findByC_S(companyId, status)) {
8869                            remove(mbMessage);
8870                    }
8871            }
8872    
8873            /**
8874             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8875             *
8876             * @param classNameId the class name id to search with
8877             * @param classPK the class p k to search with
8878             * @throws SystemException if a system exception occurred
8879             */
8880            public void removeByC_C(long classNameId, long classPK)
8881                    throws SystemException {
8882                    for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
8883                            remove(mbMessage);
8884                    }
8885            }
8886    
8887            /**
8888             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
8889             *
8890             * @param threadId the thread id to search with
8891             * @param parentMessageId the parent message id to search with
8892             * @throws SystemException if a system exception occurred
8893             */
8894            public void removeByT_P(long threadId, long parentMessageId)
8895                    throws SystemException {
8896                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
8897                            remove(mbMessage);
8898                    }
8899            }
8900    
8901            /**
8902             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
8903             *
8904             * @param threadId the thread id to search with
8905             * @param status the status to search with
8906             * @throws SystemException if a system exception occurred
8907             */
8908            public void removeByT_S(long threadId, int status)
8909                    throws SystemException {
8910                    for (MBMessage mbMessage : findByT_S(threadId, status)) {
8911                            remove(mbMessage);
8912                    }
8913            }
8914    
8915            /**
8916             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
8917             *
8918             * @param threadId the thread id to search with
8919             * @param status the status to search with
8920             * @throws SystemException if a system exception occurred
8921             */
8922            public void removeByTR_S(long threadId, int status)
8923                    throws SystemException {
8924                    for (MBMessage mbMessage : findByTR_S(threadId, status)) {
8925                            remove(mbMessage);
8926                    }
8927            }
8928    
8929            /**
8930             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
8931             *
8932             * @param groupId the group id to search with
8933             * @param userId the user id to search with
8934             * @param status the status to search with
8935             * @throws SystemException if a system exception occurred
8936             */
8937            public void removeByG_U_S(long groupId, long userId, int status)
8938                    throws SystemException {
8939                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
8940                            remove(mbMessage);
8941                    }
8942            }
8943    
8944            /**
8945             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
8946             *
8947             * @param groupId the group id to search with
8948             * @param categoryId the category id to search with
8949             * @param threadId the thread id to search with
8950             * @throws SystemException if a system exception occurred
8951             */
8952            public void removeByG_C_T(long groupId, long categoryId, long threadId)
8953                    throws SystemException {
8954                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
8955                            remove(mbMessage);
8956                    }
8957            }
8958    
8959            /**
8960             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
8961             *
8962             * @param groupId the group id to search with
8963             * @param categoryId the category id to search with
8964             * @param status the status to search with
8965             * @throws SystemException if a system exception occurred
8966             */
8967            public void removeByG_C_S(long groupId, long categoryId, int status)
8968                    throws SystemException {
8969                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
8970                            remove(mbMessage);
8971                    }
8972            }
8973    
8974            /**
8975             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
8976             *
8977             * @param classNameId the class name id to search with
8978             * @param classPK the class p k to search with
8979             * @param status the status to search with
8980             * @throws SystemException if a system exception occurred
8981             */
8982            public void removeByC_C_S(long classNameId, long classPK, int status)
8983                    throws SystemException {
8984                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
8985                            remove(mbMessage);
8986                    }
8987            }
8988    
8989            /**
8990             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
8991             *
8992             * @param groupId the group id to search with
8993             * @param categoryId the category id to search with
8994             * @param threadId the thread id to search with
8995             * @param status the status to search with
8996             * @throws SystemException if a system exception occurred
8997             */
8998            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
8999                    int status) throws SystemException {
9000                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
9001                                    status)) {
9002                            remove(mbMessage);
9003                    }
9004            }
9005    
9006            /**
9007             * Removes all the message-boards messages from the database.
9008             *
9009             * @throws SystemException if a system exception occurred
9010             */
9011            public void removeAll() throws SystemException {
9012                    for (MBMessage mbMessage : findAll()) {
9013                            remove(mbMessage);
9014                    }
9015            }
9016    
9017            /**
9018             * Counts all the message-boards messages where uuid = &#63;.
9019             *
9020             * @param uuid the uuid to search with
9021             * @return the number of matching message-boards messages
9022             * @throws SystemException if a system exception occurred
9023             */
9024            public int countByUuid(String uuid) throws SystemException {
9025                    Object[] finderArgs = new Object[] { uuid };
9026    
9027                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
9028                                    finderArgs, this);
9029    
9030                    if (count == null) {
9031                            Session session = null;
9032    
9033                            try {
9034                                    session = openSession();
9035    
9036                                    StringBundler query = new StringBundler(2);
9037    
9038                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9039    
9040                                    if (uuid == null) {
9041                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
9042                                    }
9043                                    else {
9044                                            if (uuid.equals(StringPool.BLANK)) {
9045                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
9046                                            }
9047                                            else {
9048                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
9049                                            }
9050                                    }
9051    
9052                                    String sql = query.toString();
9053    
9054                                    Query q = session.createQuery(sql);
9055    
9056                                    QueryPos qPos = QueryPos.getInstance(q);
9057    
9058                                    if (uuid != null) {
9059                                            qPos.add(uuid);
9060                                    }
9061    
9062                                    count = (Long)q.uniqueResult();
9063                            }
9064                            catch (Exception e) {
9065                                    throw processException(e);
9066                            }
9067                            finally {
9068                                    if (count == null) {
9069                                            count = Long.valueOf(0);
9070                                    }
9071    
9072                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
9073                                            finderArgs, count);
9074    
9075                                    closeSession(session);
9076                            }
9077                    }
9078    
9079                    return count.intValue();
9080            }
9081    
9082            /**
9083             * Counts all the message-boards messages where uuid = &#63; and groupId = &#63;.
9084             *
9085             * @param uuid the uuid to search with
9086             * @param groupId the group id to search with
9087             * @return the number of matching message-boards messages
9088             * @throws SystemException if a system exception occurred
9089             */
9090            public int countByUUID_G(String uuid, long groupId)
9091                    throws SystemException {
9092                    Object[] finderArgs = new Object[] { uuid, groupId };
9093    
9094                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
9095                                    finderArgs, this);
9096    
9097                    if (count == null) {
9098                            Session session = null;
9099    
9100                            try {
9101                                    session = openSession();
9102    
9103                                    StringBundler query = new StringBundler(3);
9104    
9105                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9106    
9107                                    if (uuid == null) {
9108                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
9109                                    }
9110                                    else {
9111                                            if (uuid.equals(StringPool.BLANK)) {
9112                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
9113                                            }
9114                                            else {
9115                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
9116                                            }
9117                                    }
9118    
9119                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
9120    
9121                                    String sql = query.toString();
9122    
9123                                    Query q = session.createQuery(sql);
9124    
9125                                    QueryPos qPos = QueryPos.getInstance(q);
9126    
9127                                    if (uuid != null) {
9128                                            qPos.add(uuid);
9129                                    }
9130    
9131                                    qPos.add(groupId);
9132    
9133                                    count = (Long)q.uniqueResult();
9134                            }
9135                            catch (Exception e) {
9136                                    throw processException(e);
9137                            }
9138                            finally {
9139                                    if (count == null) {
9140                                            count = Long.valueOf(0);
9141                                    }
9142    
9143                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
9144                                            finderArgs, count);
9145    
9146                                    closeSession(session);
9147                            }
9148                    }
9149    
9150                    return count.intValue();
9151            }
9152    
9153            /**
9154             * Counts all the message-boards messages where groupId = &#63;.
9155             *
9156             * @param groupId the group id to search with
9157             * @return the number of matching message-boards messages
9158             * @throws SystemException if a system exception occurred
9159             */
9160            public int countByGroupId(long groupId) throws SystemException {
9161                    Object[] finderArgs = new Object[] { groupId };
9162    
9163                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
9164                                    finderArgs, this);
9165    
9166                    if (count == null) {
9167                            Session session = null;
9168    
9169                            try {
9170                                    session = openSession();
9171    
9172                                    StringBundler query = new StringBundler(2);
9173    
9174                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9175    
9176                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
9177    
9178                                    String sql = query.toString();
9179    
9180                                    Query q = session.createQuery(sql);
9181    
9182                                    QueryPos qPos = QueryPos.getInstance(q);
9183    
9184                                    qPos.add(groupId);
9185    
9186                                    count = (Long)q.uniqueResult();
9187                            }
9188                            catch (Exception e) {
9189                                    throw processException(e);
9190                            }
9191                            finally {
9192                                    if (count == null) {
9193                                            count = Long.valueOf(0);
9194                                    }
9195    
9196                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
9197                                            finderArgs, count);
9198    
9199                                    closeSession(session);
9200                            }
9201                    }
9202    
9203                    return count.intValue();
9204            }
9205    
9206            /**
9207             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63;.
9208             *
9209             * @param groupId the group id to search with
9210             * @return the number of matching message-boards messages that the user has permission to view
9211             * @throws SystemException if a system exception occurred
9212             */
9213            public int filterCountByGroupId(long groupId) throws SystemException {
9214                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9215                            return countByGroupId(groupId);
9216                    }
9217    
9218                    Session session = null;
9219    
9220                    try {
9221                            session = openSession();
9222    
9223                            StringBundler query = new StringBundler(2);
9224    
9225                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9226    
9227                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
9228    
9229                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9230                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
9231                                            _FILTER_COLUMN_USERID, groupId);
9232    
9233                            SQLQuery q = session.createSQLQuery(sql);
9234    
9235                            q.addScalar(COUNT_COLUMN_NAME,
9236                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9237    
9238                            QueryPos qPos = QueryPos.getInstance(q);
9239    
9240                            qPos.add(groupId);
9241    
9242                            Long count = (Long)q.uniqueResult();
9243    
9244                            return count.intValue();
9245                    }
9246                    catch (Exception e) {
9247                            throw processException(e);
9248                    }
9249                    finally {
9250                            closeSession(session);
9251                    }
9252            }
9253    
9254            /**
9255             * Counts all the message-boards messages where companyId = &#63;.
9256             *
9257             * @param companyId the company id to search with
9258             * @return the number of matching message-boards messages
9259             * @throws SystemException if a system exception occurred
9260             */
9261            public int countByCompanyId(long companyId) throws SystemException {
9262                    Object[] finderArgs = new Object[] { companyId };
9263    
9264                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
9265                                    finderArgs, this);
9266    
9267                    if (count == null) {
9268                            Session session = null;
9269    
9270                            try {
9271                                    session = openSession();
9272    
9273                                    StringBundler query = new StringBundler(2);
9274    
9275                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9276    
9277                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
9278    
9279                                    String sql = query.toString();
9280    
9281                                    Query q = session.createQuery(sql);
9282    
9283                                    QueryPos qPos = QueryPos.getInstance(q);
9284    
9285                                    qPos.add(companyId);
9286    
9287                                    count = (Long)q.uniqueResult();
9288                            }
9289                            catch (Exception e) {
9290                                    throw processException(e);
9291                            }
9292                            finally {
9293                                    if (count == null) {
9294                                            count = Long.valueOf(0);
9295                                    }
9296    
9297                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
9298                                            finderArgs, count);
9299    
9300                                    closeSession(session);
9301                            }
9302                    }
9303    
9304                    return count.intValue();
9305            }
9306    
9307            /**
9308             * Counts all the message-boards messages where threadId = &#63;.
9309             *
9310             * @param threadId the thread id to search with
9311             * @return the number of matching message-boards messages
9312             * @throws SystemException if a system exception occurred
9313             */
9314            public int countByThreadId(long threadId) throws SystemException {
9315                    Object[] finderArgs = new Object[] { threadId };
9316    
9317                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
9318                                    finderArgs, this);
9319    
9320                    if (count == null) {
9321                            Session session = null;
9322    
9323                            try {
9324                                    session = openSession();
9325    
9326                                    StringBundler query = new StringBundler(2);
9327    
9328                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9329    
9330                                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
9331    
9332                                    String sql = query.toString();
9333    
9334                                    Query q = session.createQuery(sql);
9335    
9336                                    QueryPos qPos = QueryPos.getInstance(q);
9337    
9338                                    qPos.add(threadId);
9339    
9340                                    count = (Long)q.uniqueResult();
9341                            }
9342                            catch (Exception e) {
9343                                    throw processException(e);
9344                            }
9345                            finally {
9346                                    if (count == null) {
9347                                            count = Long.valueOf(0);
9348                                    }
9349    
9350                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
9351                                            finderArgs, count);
9352    
9353                                    closeSession(session);
9354                            }
9355                    }
9356    
9357                    return count.intValue();
9358            }
9359    
9360            /**
9361             * Counts all the message-boards messages where threadId = &#63;.
9362             *
9363             * @param threadId the thread id to search with
9364             * @return the number of matching message-boards messages
9365             * @throws SystemException if a system exception occurred
9366             */
9367            public int countByThreadReplies(long threadId) throws SystemException {
9368                    Object[] finderArgs = new Object[] { threadId };
9369    
9370                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
9371                                    finderArgs, this);
9372    
9373                    if (count == null) {
9374                            Session session = null;
9375    
9376                            try {
9377                                    session = openSession();
9378    
9379                                    StringBundler query = new StringBundler(2);
9380    
9381                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9382    
9383                                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
9384    
9385                                    String sql = query.toString();
9386    
9387                                    Query q = session.createQuery(sql);
9388    
9389                                    QueryPos qPos = QueryPos.getInstance(q);
9390    
9391                                    qPos.add(threadId);
9392    
9393                                    count = (Long)q.uniqueResult();
9394                            }
9395                            catch (Exception e) {
9396                                    throw processException(e);
9397                            }
9398                            finally {
9399                                    if (count == null) {
9400                                            count = Long.valueOf(0);
9401                                    }
9402    
9403                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
9404                                            finderArgs, count);
9405    
9406                                    closeSession(session);
9407                            }
9408                    }
9409    
9410                    return count.intValue();
9411            }
9412    
9413            /**
9414             * Counts all the message-boards messages where userId = &#63;.
9415             *
9416             * @param userId the user id to search with
9417             * @return the number of matching message-boards messages
9418             * @throws SystemException if a system exception occurred
9419             */
9420            public int countByUserId(long userId) throws SystemException {
9421                    Object[] finderArgs = new Object[] { userId };
9422    
9423                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
9424                                    finderArgs, this);
9425    
9426                    if (count == null) {
9427                            Session session = null;
9428    
9429                            try {
9430                                    session = openSession();
9431    
9432                                    StringBundler query = new StringBundler(2);
9433    
9434                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9435    
9436                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
9437    
9438                                    String sql = query.toString();
9439    
9440                                    Query q = session.createQuery(sql);
9441    
9442                                    QueryPos qPos = QueryPos.getInstance(q);
9443    
9444                                    qPos.add(userId);
9445    
9446                                    count = (Long)q.uniqueResult();
9447                            }
9448                            catch (Exception e) {
9449                                    throw processException(e);
9450                            }
9451                            finally {
9452                                    if (count == null) {
9453                                            count = Long.valueOf(0);
9454                                    }
9455    
9456                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
9457                                            finderArgs, count);
9458    
9459                                    closeSession(session);
9460                            }
9461                    }
9462    
9463                    return count.intValue();
9464            }
9465    
9466            /**
9467             * Counts all the message-boards messages where groupId = &#63; and userId = &#63;.
9468             *
9469             * @param groupId the group id to search with
9470             * @param userId the user id to search with
9471             * @return the number of matching message-boards messages
9472             * @throws SystemException if a system exception occurred
9473             */
9474            public int countByG_U(long groupId, long userId) throws SystemException {
9475                    Object[] finderArgs = new Object[] { groupId, userId };
9476    
9477                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
9478                                    finderArgs, this);
9479    
9480                    if (count == null) {
9481                            Session session = null;
9482    
9483                            try {
9484                                    session = openSession();
9485    
9486                                    StringBundler query = new StringBundler(3);
9487    
9488                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9489    
9490                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
9491    
9492                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
9493    
9494                                    String sql = query.toString();
9495    
9496                                    Query q = session.createQuery(sql);
9497    
9498                                    QueryPos qPos = QueryPos.getInstance(q);
9499    
9500                                    qPos.add(groupId);
9501    
9502                                    qPos.add(userId);
9503    
9504                                    count = (Long)q.uniqueResult();
9505                            }
9506                            catch (Exception e) {
9507                                    throw processException(e);
9508                            }
9509                            finally {
9510                                    if (count == null) {
9511                                            count = Long.valueOf(0);
9512                                    }
9513    
9514                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
9515                                            count);
9516    
9517                                    closeSession(session);
9518                            }
9519                    }
9520    
9521                    return count.intValue();
9522            }
9523    
9524            /**
9525             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and userId = &#63;.
9526             *
9527             * @param groupId the group id to search with
9528             * @param userId the user id to search with
9529             * @return the number of matching message-boards messages that the user has permission to view
9530             * @throws SystemException if a system exception occurred
9531             */
9532            public int filterCountByG_U(long groupId, long userId)
9533                    throws SystemException {
9534                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9535                            return countByG_U(groupId, userId);
9536                    }
9537    
9538                    Session session = null;
9539    
9540                    try {
9541                            session = openSession();
9542    
9543                            StringBundler query = new StringBundler(3);
9544    
9545                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9546    
9547                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
9548    
9549                            query.append(_FINDER_COLUMN_G_U_USERID_2);
9550    
9551                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9552                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
9553                                            _FILTER_COLUMN_USERID, groupId);
9554    
9555                            SQLQuery q = session.createSQLQuery(sql);
9556    
9557                            q.addScalar(COUNT_COLUMN_NAME,
9558                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9559    
9560                            QueryPos qPos = QueryPos.getInstance(q);
9561    
9562                            qPos.add(groupId);
9563    
9564                            qPos.add(userId);
9565    
9566                            Long count = (Long)q.uniqueResult();
9567    
9568                            return count.intValue();
9569                    }
9570                    catch (Exception e) {
9571                            throw processException(e);
9572                    }
9573                    finally {
9574                            closeSession(session);
9575                    }
9576            }
9577    
9578            /**
9579             * Counts all the message-boards messages where groupId = &#63; and categoryId = &#63;.
9580             *
9581             * @param groupId the group id to search with
9582             * @param categoryId the category id to search with
9583             * @return the number of matching message-boards messages
9584             * @throws SystemException if a system exception occurred
9585             */
9586            public int countByG_C(long groupId, long categoryId)
9587                    throws SystemException {
9588                    Object[] finderArgs = new Object[] { groupId, categoryId };
9589    
9590                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
9591                                    finderArgs, this);
9592    
9593                    if (count == null) {
9594                            Session session = null;
9595    
9596                            try {
9597                                    session = openSession();
9598    
9599                                    StringBundler query = new StringBundler(3);
9600    
9601                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9602    
9603                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
9604    
9605                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
9606    
9607                                    String sql = query.toString();
9608    
9609                                    Query q = session.createQuery(sql);
9610    
9611                                    QueryPos qPos = QueryPos.getInstance(q);
9612    
9613                                    qPos.add(groupId);
9614    
9615                                    qPos.add(categoryId);
9616    
9617                                    count = (Long)q.uniqueResult();
9618                            }
9619                            catch (Exception e) {
9620                                    throw processException(e);
9621                            }
9622                            finally {
9623                                    if (count == null) {
9624                                            count = Long.valueOf(0);
9625                                    }
9626    
9627                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
9628                                            count);
9629    
9630                                    closeSession(session);
9631                            }
9632                    }
9633    
9634                    return count.intValue();
9635            }
9636    
9637            /**
9638             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and categoryId = &#63;.
9639             *
9640             * @param groupId the group id to search with
9641             * @param categoryId the category id to search with
9642             * @return the number of matching message-boards messages that the user has permission to view
9643             * @throws SystemException if a system exception occurred
9644             */
9645            public int filterCountByG_C(long groupId, long categoryId)
9646                    throws SystemException {
9647                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9648                            return countByG_C(groupId, categoryId);
9649                    }
9650    
9651                    Session session = null;
9652    
9653                    try {
9654                            session = openSession();
9655    
9656                            StringBundler query = new StringBundler(3);
9657    
9658                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9659    
9660                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
9661    
9662                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
9663    
9664                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9665                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
9666                                            _FILTER_COLUMN_USERID, groupId);
9667    
9668                            SQLQuery q = session.createSQLQuery(sql);
9669    
9670                            q.addScalar(COUNT_COLUMN_NAME,
9671                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9672    
9673                            QueryPos qPos = QueryPos.getInstance(q);
9674    
9675                            qPos.add(groupId);
9676    
9677                            qPos.add(categoryId);
9678    
9679                            Long count = (Long)q.uniqueResult();
9680    
9681                            return count.intValue();
9682                    }
9683                    catch (Exception e) {
9684                            throw processException(e);
9685                    }
9686                    finally {
9687                            closeSession(session);
9688                    }
9689            }
9690    
9691            /**
9692             * Counts all the message-boards messages where groupId = &#63; and status = &#63;.
9693             *
9694             * @param groupId the group id to search with
9695             * @param status the status to search with
9696             * @return the number of matching message-boards messages
9697             * @throws SystemException if a system exception occurred
9698             */
9699            public int countByG_S(long groupId, int status) throws SystemException {
9700                    Object[] finderArgs = new Object[] { groupId, status };
9701    
9702                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
9703                                    finderArgs, this);
9704    
9705                    if (count == null) {
9706                            Session session = null;
9707    
9708                            try {
9709                                    session = openSession();
9710    
9711                                    StringBundler query = new StringBundler(3);
9712    
9713                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9714    
9715                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
9716    
9717                                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
9718    
9719                                    String sql = query.toString();
9720    
9721                                    Query q = session.createQuery(sql);
9722    
9723                                    QueryPos qPos = QueryPos.getInstance(q);
9724    
9725                                    qPos.add(groupId);
9726    
9727                                    qPos.add(status);
9728    
9729                                    count = (Long)q.uniqueResult();
9730                            }
9731                            catch (Exception e) {
9732                                    throw processException(e);
9733                            }
9734                            finally {
9735                                    if (count == null) {
9736                                            count = Long.valueOf(0);
9737                                    }
9738    
9739                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
9740                                            count);
9741    
9742                                    closeSession(session);
9743                            }
9744                    }
9745    
9746                    return count.intValue();
9747            }
9748    
9749            /**
9750             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and status = &#63;.
9751             *
9752             * @param groupId the group id to search with
9753             * @param status the status to search with
9754             * @return the number of matching message-boards messages that the user has permission to view
9755             * @throws SystemException if a system exception occurred
9756             */
9757            public int filterCountByG_S(long groupId, int status)
9758                    throws SystemException {
9759                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9760                            return countByG_S(groupId, status);
9761                    }
9762    
9763                    Session session = null;
9764    
9765                    try {
9766                            session = openSession();
9767    
9768                            StringBundler query = new StringBundler(3);
9769    
9770                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9771    
9772                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
9773    
9774                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
9775    
9776                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9777                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
9778                                            _FILTER_COLUMN_USERID, groupId);
9779    
9780                            SQLQuery q = session.createSQLQuery(sql);
9781    
9782                            q.addScalar(COUNT_COLUMN_NAME,
9783                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9784    
9785                            QueryPos qPos = QueryPos.getInstance(q);
9786    
9787                            qPos.add(groupId);
9788    
9789                            qPos.add(status);
9790    
9791                            Long count = (Long)q.uniqueResult();
9792    
9793                            return count.intValue();
9794                    }
9795                    catch (Exception e) {
9796                            throw processException(e);
9797                    }
9798                    finally {
9799                            closeSession(session);
9800                    }
9801            }
9802    
9803            /**
9804             * Counts all the message-boards messages where companyId = &#63; and status = &#63;.
9805             *
9806             * @param companyId the company id to search with
9807             * @param status the status to search with
9808             * @return the number of matching message-boards messages
9809             * @throws SystemException if a system exception occurred
9810             */
9811            public int countByC_S(long companyId, int status) throws SystemException {
9812                    Object[] finderArgs = new Object[] { companyId, status };
9813    
9814                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
9815                                    finderArgs, this);
9816    
9817                    if (count == null) {
9818                            Session session = null;
9819    
9820                            try {
9821                                    session = openSession();
9822    
9823                                    StringBundler query = new StringBundler(3);
9824    
9825                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9826    
9827                                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
9828    
9829                                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
9830    
9831                                    String sql = query.toString();
9832    
9833                                    Query q = session.createQuery(sql);
9834    
9835                                    QueryPos qPos = QueryPos.getInstance(q);
9836    
9837                                    qPos.add(companyId);
9838    
9839                                    qPos.add(status);
9840    
9841                                    count = (Long)q.uniqueResult();
9842                            }
9843                            catch (Exception e) {
9844                                    throw processException(e);
9845                            }
9846                            finally {
9847                                    if (count == null) {
9848                                            count = Long.valueOf(0);
9849                                    }
9850    
9851                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
9852                                            count);
9853    
9854                                    closeSession(session);
9855                            }
9856                    }
9857    
9858                    return count.intValue();
9859            }
9860    
9861            /**
9862             * Counts all the message-boards messages where classNameId = &#63; and classPK = &#63;.
9863             *
9864             * @param classNameId the class name id to search with
9865             * @param classPK the class p k to search with
9866             * @return the number of matching message-boards messages
9867             * @throws SystemException if a system exception occurred
9868             */
9869            public int countByC_C(long classNameId, long classPK)
9870                    throws SystemException {
9871                    Object[] finderArgs = new Object[] { classNameId, classPK };
9872    
9873                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
9874                                    finderArgs, this);
9875    
9876                    if (count == null) {
9877                            Session session = null;
9878    
9879                            try {
9880                                    session = openSession();
9881    
9882                                    StringBundler query = new StringBundler(3);
9883    
9884                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9885    
9886                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
9887    
9888                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
9889    
9890                                    String sql = query.toString();
9891    
9892                                    Query q = session.createQuery(sql);
9893    
9894                                    QueryPos qPos = QueryPos.getInstance(q);
9895    
9896                                    qPos.add(classNameId);
9897    
9898                                    qPos.add(classPK);
9899    
9900                                    count = (Long)q.uniqueResult();
9901                            }
9902                            catch (Exception e) {
9903                                    throw processException(e);
9904                            }
9905                            finally {
9906                                    if (count == null) {
9907                                            count = Long.valueOf(0);
9908                                    }
9909    
9910                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
9911                                            count);
9912    
9913                                    closeSession(session);
9914                            }
9915                    }
9916    
9917                    return count.intValue();
9918            }
9919    
9920            /**
9921             * Counts all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9922             *
9923             * @param threadId the thread id to search with
9924             * @param parentMessageId the parent message id to search with
9925             * @return the number of matching message-boards messages
9926             * @throws SystemException if a system exception occurred
9927             */
9928            public int countByT_P(long threadId, long parentMessageId)
9929                    throws SystemException {
9930                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9931    
9932                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
9933                                    finderArgs, this);
9934    
9935                    if (count == null) {
9936                            Session session = null;
9937    
9938                            try {
9939                                    session = openSession();
9940    
9941                                    StringBundler query = new StringBundler(3);
9942    
9943                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9944    
9945                                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9946    
9947                                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9948    
9949                                    String sql = query.toString();
9950    
9951                                    Query q = session.createQuery(sql);
9952    
9953                                    QueryPos qPos = QueryPos.getInstance(q);
9954    
9955                                    qPos.add(threadId);
9956    
9957                                    qPos.add(parentMessageId);
9958    
9959                                    count = (Long)q.uniqueResult();
9960                            }
9961                            catch (Exception e) {
9962                                    throw processException(e);
9963                            }
9964                            finally {
9965                                    if (count == null) {
9966                                            count = Long.valueOf(0);
9967                                    }
9968    
9969                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
9970                                            count);
9971    
9972                                    closeSession(session);
9973                            }
9974                    }
9975    
9976                    return count.intValue();
9977            }
9978    
9979            /**
9980             * Counts all the message-boards messages where threadId = &#63; and status = &#63;.
9981             *
9982             * @param threadId the thread id to search with
9983             * @param status the status to search with
9984             * @return the number of matching message-boards messages
9985             * @throws SystemException if a system exception occurred
9986             */
9987            public int countByT_S(long threadId, int status) throws SystemException {
9988                    Object[] finderArgs = new Object[] { threadId, status };
9989    
9990                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
9991                                    finderArgs, this);
9992    
9993                    if (count == null) {
9994                            Session session = null;
9995    
9996                            try {
9997                                    session = openSession();
9998    
9999                                    StringBundler query = new StringBundler(3);
10000    
10001                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10002    
10003                                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10004    
10005                                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10006    
10007                                    String sql = query.toString();
10008    
10009                                    Query q = session.createQuery(sql);
10010    
10011                                    QueryPos qPos = QueryPos.getInstance(q);
10012    
10013                                    qPos.add(threadId);
10014    
10015                                    qPos.add(status);
10016    
10017                                    count = (Long)q.uniqueResult();
10018                            }
10019                            catch (Exception e) {
10020                                    throw processException(e);
10021                            }
10022                            finally {
10023                                    if (count == null) {
10024                                            count = Long.valueOf(0);
10025                                    }
10026    
10027                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
10028                                            count);
10029    
10030                                    closeSession(session);
10031                            }
10032                    }
10033    
10034                    return count.intValue();
10035            }
10036    
10037            /**
10038             * Counts all the message-boards messages where threadId = &#63; and status = &#63;.
10039             *
10040             * @param threadId the thread id to search with
10041             * @param status the status to search with
10042             * @return the number of matching message-boards messages
10043             * @throws SystemException if a system exception occurred
10044             */
10045            public int countByTR_S(long threadId, int status) throws SystemException {
10046                    Object[] finderArgs = new Object[] { threadId, status };
10047    
10048                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
10049                                    finderArgs, this);
10050    
10051                    if (count == null) {
10052                            Session session = null;
10053    
10054                            try {
10055                                    session = openSession();
10056    
10057                                    StringBundler query = new StringBundler(3);
10058    
10059                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10060    
10061                                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10062    
10063                                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10064    
10065                                    String sql = query.toString();
10066    
10067                                    Query q = session.createQuery(sql);
10068    
10069                                    QueryPos qPos = QueryPos.getInstance(q);
10070    
10071                                    qPos.add(threadId);
10072    
10073                                    qPos.add(status);
10074    
10075                                    count = (Long)q.uniqueResult();
10076                            }
10077                            catch (Exception e) {
10078                                    throw processException(e);
10079                            }
10080                            finally {
10081                                    if (count == null) {
10082                                            count = Long.valueOf(0);
10083                                    }
10084    
10085                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
10086                                            finderArgs, count);
10087    
10088                                    closeSession(session);
10089                            }
10090                    }
10091    
10092                    return count.intValue();
10093            }
10094    
10095            /**
10096             * Counts all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10097             *
10098             * @param groupId the group id to search with
10099             * @param userId the user id to search with
10100             * @param status the status to search with
10101             * @return the number of matching message-boards messages
10102             * @throws SystemException if a system exception occurred
10103             */
10104            public int countByG_U_S(long groupId, long userId, int status)
10105                    throws SystemException {
10106                    Object[] finderArgs = new Object[] { groupId, userId, status };
10107    
10108                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
10109                                    finderArgs, this);
10110    
10111                    if (count == null) {
10112                            Session session = null;
10113    
10114                            try {
10115                                    session = openSession();
10116    
10117                                    StringBundler query = new StringBundler(4);
10118    
10119                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10120    
10121                                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10122    
10123                                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10124    
10125                                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10126    
10127                                    String sql = query.toString();
10128    
10129                                    Query q = session.createQuery(sql);
10130    
10131                                    QueryPos qPos = QueryPos.getInstance(q);
10132    
10133                                    qPos.add(groupId);
10134    
10135                                    qPos.add(userId);
10136    
10137                                    qPos.add(status);
10138    
10139                                    count = (Long)q.uniqueResult();
10140                            }
10141                            catch (Exception e) {
10142                                    throw processException(e);
10143                            }
10144                            finally {
10145                                    if (count == null) {
10146                                            count = Long.valueOf(0);
10147                                    }
10148    
10149                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
10150                                            finderArgs, count);
10151    
10152                                    closeSession(session);
10153                            }
10154                    }
10155    
10156                    return count.intValue();
10157            }
10158    
10159            /**
10160             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10161             *
10162             * @param groupId the group id to search with
10163             * @param userId the user id to search with
10164             * @param status the status to search with
10165             * @return the number of matching message-boards messages that the user has permission to view
10166             * @throws SystemException if a system exception occurred
10167             */
10168            public int filterCountByG_U_S(long groupId, long userId, int status)
10169                    throws SystemException {
10170                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10171                            return countByG_U_S(groupId, userId, status);
10172                    }
10173    
10174                    Session session = null;
10175    
10176                    try {
10177                            session = openSession();
10178    
10179                            StringBundler query = new StringBundler(4);
10180    
10181                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10182    
10183                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10184    
10185                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10186    
10187                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10188    
10189                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10190                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
10191                                            _FILTER_COLUMN_USERID, groupId);
10192    
10193                            SQLQuery q = session.createSQLQuery(sql);
10194    
10195                            q.addScalar(COUNT_COLUMN_NAME,
10196                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10197    
10198                            QueryPos qPos = QueryPos.getInstance(q);
10199    
10200                            qPos.add(groupId);
10201    
10202                            qPos.add(userId);
10203    
10204                            qPos.add(status);
10205    
10206                            Long count = (Long)q.uniqueResult();
10207    
10208                            return count.intValue();
10209                    }
10210                    catch (Exception e) {
10211                            throw processException(e);
10212                    }
10213                    finally {
10214                            closeSession(session);
10215                    }
10216            }
10217    
10218            /**
10219             * Counts all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10220             *
10221             * @param groupId the group id to search with
10222             * @param categoryId the category id to search with
10223             * @param threadId the thread id to search with
10224             * @return the number of matching message-boards messages
10225             * @throws SystemException if a system exception occurred
10226             */
10227            public int countByG_C_T(long groupId, long categoryId, long threadId)
10228                    throws SystemException {
10229                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
10230    
10231                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
10232                                    finderArgs, this);
10233    
10234                    if (count == null) {
10235                            Session session = null;
10236    
10237                            try {
10238                                    session = openSession();
10239    
10240                                    StringBundler query = new StringBundler(4);
10241    
10242                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10243    
10244                                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10245    
10246                                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10247    
10248                                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10249    
10250                                    String sql = query.toString();
10251    
10252                                    Query q = session.createQuery(sql);
10253    
10254                                    QueryPos qPos = QueryPos.getInstance(q);
10255    
10256                                    qPos.add(groupId);
10257    
10258                                    qPos.add(categoryId);
10259    
10260                                    qPos.add(threadId);
10261    
10262                                    count = (Long)q.uniqueResult();
10263                            }
10264                            catch (Exception e) {
10265                                    throw processException(e);
10266                            }
10267                            finally {
10268                                    if (count == null) {
10269                                            count = Long.valueOf(0);
10270                                    }
10271    
10272                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
10273                                            finderArgs, count);
10274    
10275                                    closeSession(session);
10276                            }
10277                    }
10278    
10279                    return count.intValue();
10280            }
10281    
10282            /**
10283             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10284             *
10285             * @param groupId the group id to search with
10286             * @param categoryId the category id to search with
10287             * @param threadId the thread id to search with
10288             * @return the number of matching message-boards messages that the user has permission to view
10289             * @throws SystemException if a system exception occurred
10290             */
10291            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
10292                    throws SystemException {
10293                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10294                            return countByG_C_T(groupId, categoryId, threadId);
10295                    }
10296    
10297                    Session session = null;
10298    
10299                    try {
10300                            session = openSession();
10301    
10302                            StringBundler query = new StringBundler(4);
10303    
10304                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10305    
10306                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10307    
10308                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10309    
10310                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10311    
10312                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10313                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
10314                                            _FILTER_COLUMN_USERID, groupId);
10315    
10316                            SQLQuery q = session.createSQLQuery(sql);
10317    
10318                            q.addScalar(COUNT_COLUMN_NAME,
10319                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10320    
10321                            QueryPos qPos = QueryPos.getInstance(q);
10322    
10323                            qPos.add(groupId);
10324    
10325                            qPos.add(categoryId);
10326    
10327                            qPos.add(threadId);
10328    
10329                            Long count = (Long)q.uniqueResult();
10330    
10331                            return count.intValue();
10332                    }
10333                    catch (Exception e) {
10334                            throw processException(e);
10335                    }
10336                    finally {
10337                            closeSession(session);
10338                    }
10339            }
10340    
10341            /**
10342             * Counts all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10343             *
10344             * @param groupId the group id to search with
10345             * @param categoryId the category id to search with
10346             * @param status the status to search with
10347             * @return the number of matching message-boards messages
10348             * @throws SystemException if a system exception occurred
10349             */
10350            public int countByG_C_S(long groupId, long categoryId, int status)
10351                    throws SystemException {
10352                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
10353    
10354                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
10355                                    finderArgs, this);
10356    
10357                    if (count == null) {
10358                            Session session = null;
10359    
10360                            try {
10361                                    session = openSession();
10362    
10363                                    StringBundler query = new StringBundler(4);
10364    
10365                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10366    
10367                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10368    
10369                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10370    
10371                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10372    
10373                                    String sql = query.toString();
10374    
10375                                    Query q = session.createQuery(sql);
10376    
10377                                    QueryPos qPos = QueryPos.getInstance(q);
10378    
10379                                    qPos.add(groupId);
10380    
10381                                    qPos.add(categoryId);
10382    
10383                                    qPos.add(status);
10384    
10385                                    count = (Long)q.uniqueResult();
10386                            }
10387                            catch (Exception e) {
10388                                    throw processException(e);
10389                            }
10390                            finally {
10391                                    if (count == null) {
10392                                            count = Long.valueOf(0);
10393                                    }
10394    
10395                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
10396                                            finderArgs, count);
10397    
10398                                    closeSession(session);
10399                            }
10400                    }
10401    
10402                    return count.intValue();
10403            }
10404    
10405            /**
10406             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10407             *
10408             * @param groupId the group id to search with
10409             * @param categoryId the category id to search with
10410             * @param status the status to search with
10411             * @return the number of matching message-boards messages that the user has permission to view
10412             * @throws SystemException if a system exception occurred
10413             */
10414            public int filterCountByG_C_S(long groupId, long categoryId, int status)
10415                    throws SystemException {
10416                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10417                            return countByG_C_S(groupId, categoryId, status);
10418                    }
10419    
10420                    Session session = null;
10421    
10422                    try {
10423                            session = openSession();
10424    
10425                            StringBundler query = new StringBundler(4);
10426    
10427                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10428    
10429                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10430    
10431                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10432    
10433                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10434    
10435                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10436                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
10437                                            _FILTER_COLUMN_USERID, groupId);
10438    
10439                            SQLQuery q = session.createSQLQuery(sql);
10440    
10441                            q.addScalar(COUNT_COLUMN_NAME,
10442                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10443    
10444                            QueryPos qPos = QueryPos.getInstance(q);
10445    
10446                            qPos.add(groupId);
10447    
10448                            qPos.add(categoryId);
10449    
10450                            qPos.add(status);
10451    
10452                            Long count = (Long)q.uniqueResult();
10453    
10454                            return count.intValue();
10455                    }
10456                    catch (Exception e) {
10457                            throw processException(e);
10458                    }
10459                    finally {
10460                            closeSession(session);
10461                    }
10462            }
10463    
10464            /**
10465             * Counts all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
10466             *
10467             * @param classNameId the class name id to search with
10468             * @param classPK the class p k to search with
10469             * @param status the status to search with
10470             * @return the number of matching message-boards messages
10471             * @throws SystemException if a system exception occurred
10472             */
10473            public int countByC_C_S(long classNameId, long classPK, int status)
10474                    throws SystemException {
10475                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
10476    
10477                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
10478                                    finderArgs, this);
10479    
10480                    if (count == null) {
10481                            Session session = null;
10482    
10483                            try {
10484                                    session = openSession();
10485    
10486                                    StringBundler query = new StringBundler(4);
10487    
10488                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10489    
10490                                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
10491    
10492                                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
10493    
10494                                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
10495    
10496                                    String sql = query.toString();
10497    
10498                                    Query q = session.createQuery(sql);
10499    
10500                                    QueryPos qPos = QueryPos.getInstance(q);
10501    
10502                                    qPos.add(classNameId);
10503    
10504                                    qPos.add(classPK);
10505    
10506                                    qPos.add(status);
10507    
10508                                    count = (Long)q.uniqueResult();
10509                            }
10510                            catch (Exception e) {
10511                                    throw processException(e);
10512                            }
10513                            finally {
10514                                    if (count == null) {
10515                                            count = Long.valueOf(0);
10516                                    }
10517    
10518                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
10519                                            finderArgs, count);
10520    
10521                                    closeSession(session);
10522                            }
10523                    }
10524    
10525                    return count.intValue();
10526            }
10527    
10528            /**
10529             * Counts all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
10530             *
10531             * @param groupId the group id to search with
10532             * @param categoryId the category id to search with
10533             * @param threadId the thread id to search with
10534             * @param status the status to search with
10535             * @return the number of matching message-boards messages
10536             * @throws SystemException if a system exception occurred
10537             */
10538            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
10539                    int status) throws SystemException {
10540                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
10541    
10542                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
10543                                    finderArgs, this);
10544    
10545                    if (count == null) {
10546                            Session session = null;
10547    
10548                            try {
10549                                    session = openSession();
10550    
10551                                    StringBundler query = new StringBundler(5);
10552    
10553                                    query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10554    
10555                                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
10556    
10557                                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
10558    
10559                                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
10560    
10561                                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
10562    
10563                                    String sql = query.toString();
10564    
10565                                    Query q = session.createQuery(sql);
10566    
10567                                    QueryPos qPos = QueryPos.getInstance(q);
10568    
10569                                    qPos.add(groupId);
10570    
10571                                    qPos.add(categoryId);
10572    
10573                                    qPos.add(threadId);
10574    
10575                                    qPos.add(status);
10576    
10577                                    count = (Long)q.uniqueResult();
10578                            }
10579                            catch (Exception e) {
10580                                    throw processException(e);
10581                            }
10582                            finally {
10583                                    if (count == null) {
10584                                            count = Long.valueOf(0);
10585                                    }
10586    
10587                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
10588                                            finderArgs, count);
10589    
10590                                    closeSession(session);
10591                            }
10592                    }
10593    
10594                    return count.intValue();
10595            }
10596    
10597            /**
10598             * Filters by the user's permissions and counts all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
10599             *
10600             * @param groupId the group id to search with
10601             * @param categoryId the category id to search with
10602             * @param threadId the thread id to search with
10603             * @param status the status to search with
10604             * @return the number of matching message-boards messages that the user has permission to view
10605             * @throws SystemException if a system exception occurred
10606             */
10607            public int filterCountByG_C_T_S(long groupId, long categoryId,
10608                    long threadId, int status) throws SystemException {
10609                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10610                            return countByG_C_T_S(groupId, categoryId, threadId, status);
10611                    }
10612    
10613                    Session session = null;
10614    
10615                    try {
10616                            session = openSession();
10617    
10618                            StringBundler query = new StringBundler(5);
10619    
10620                            query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10621    
10622                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
10623    
10624                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
10625    
10626                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
10627    
10628                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
10629    
10630                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10631                                            MBMessage.class.getName(), _FILTER_COLUMN_PK,
10632                                            _FILTER_COLUMN_USERID, groupId);
10633    
10634                            SQLQuery q = session.createSQLQuery(sql);
10635    
10636                            q.addScalar(COUNT_COLUMN_NAME,
10637                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10638    
10639                            QueryPos qPos = QueryPos.getInstance(q);
10640    
10641                            qPos.add(groupId);
10642    
10643                            qPos.add(categoryId);
10644    
10645                            qPos.add(threadId);
10646    
10647                            qPos.add(status);
10648    
10649                            Long count = (Long)q.uniqueResult();
10650    
10651                            return count.intValue();
10652                    }
10653                    catch (Exception e) {
10654                            throw processException(e);
10655                    }
10656                    finally {
10657                            closeSession(session);
10658                    }
10659            }
10660    
10661            /**
10662             * Counts all the message-boards messages.
10663             *
10664             * @return the number of message-boards messages
10665             * @throws SystemException if a system exception occurred
10666             */
10667            public int countAll() throws SystemException {
10668                    Object[] finderArgs = new Object[0];
10669    
10670                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
10671                                    finderArgs, this);
10672    
10673                    if (count == null) {
10674                            Session session = null;
10675    
10676                            try {
10677                                    session = openSession();
10678    
10679                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
10680    
10681                                    count = (Long)q.uniqueResult();
10682                            }
10683                            catch (Exception e) {
10684                                    throw processException(e);
10685                            }
10686                            finally {
10687                                    if (count == null) {
10688                                            count = Long.valueOf(0);
10689                                    }
10690    
10691                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
10692                                            count);
10693    
10694                                    closeSession(session);
10695                            }
10696                    }
10697    
10698                    return count.intValue();
10699            }
10700    
10701            /**
10702             * Initializes the message-boards message persistence.
10703             */
10704            public void afterPropertiesSet() {
10705                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
10706                                            com.liferay.portal.util.PropsUtil.get(
10707                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
10708    
10709                    if (listenerClassNames.length > 0) {
10710                            try {
10711                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
10712    
10713                                    for (String listenerClassName : listenerClassNames) {
10714                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
10715                                                            listenerClassName));
10716                                    }
10717    
10718                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
10719                            }
10720                            catch (Exception e) {
10721                                    _log.error(e);
10722                            }
10723                    }
10724            }
10725    
10726            @BeanReference(type = MBBanPersistence.class)
10727            protected MBBanPersistence mbBanPersistence;
10728            @BeanReference(type = MBCategoryPersistence.class)
10729            protected MBCategoryPersistence mbCategoryPersistence;
10730            @BeanReference(type = MBDiscussionPersistence.class)
10731            protected MBDiscussionPersistence mbDiscussionPersistence;
10732            @BeanReference(type = MBMailingListPersistence.class)
10733            protected MBMailingListPersistence mbMailingListPersistence;
10734            @BeanReference(type = MBMessagePersistence.class)
10735            protected MBMessagePersistence mbMessagePersistence;
10736            @BeanReference(type = MBMessageFlagPersistence.class)
10737            protected MBMessageFlagPersistence mbMessageFlagPersistence;
10738            @BeanReference(type = MBStatsUserPersistence.class)
10739            protected MBStatsUserPersistence mbStatsUserPersistence;
10740            @BeanReference(type = MBThreadPersistence.class)
10741            protected MBThreadPersistence mbThreadPersistence;
10742            @BeanReference(type = CompanyPersistence.class)
10743            protected CompanyPersistence companyPersistence;
10744            @BeanReference(type = GroupPersistence.class)
10745            protected GroupPersistence groupPersistence;
10746            @BeanReference(type = LockPersistence.class)
10747            protected LockPersistence lockPersistence;
10748            @BeanReference(type = PortletPreferencesPersistence.class)
10749            protected PortletPreferencesPersistence portletPreferencesPersistence;
10750            @BeanReference(type = ResourcePersistence.class)
10751            protected ResourcePersistence resourcePersistence;
10752            @BeanReference(type = SubscriptionPersistence.class)
10753            protected SubscriptionPersistence subscriptionPersistence;
10754            @BeanReference(type = UserPersistence.class)
10755            protected UserPersistence userPersistence;
10756            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
10757            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
10758            @BeanReference(type = AssetEntryPersistence.class)
10759            protected AssetEntryPersistence assetEntryPersistence;
10760            @BeanReference(type = AssetTagPersistence.class)
10761            protected AssetTagPersistence assetTagPersistence;
10762            @BeanReference(type = BlogsEntryPersistence.class)
10763            protected BlogsEntryPersistence blogsEntryPersistence;
10764            @BeanReference(type = ExpandoValuePersistence.class)
10765            protected ExpandoValuePersistence expandoValuePersistence;
10766            @BeanReference(type = RatingsStatsPersistence.class)
10767            protected RatingsStatsPersistence ratingsStatsPersistence;
10768            @BeanReference(type = SocialActivityPersistence.class)
10769            protected SocialActivityPersistence socialActivityPersistence;
10770            @BeanReference(type = SocialEquityLogPersistence.class)
10771            protected SocialEquityLogPersistence socialEquityLogPersistence;
10772            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
10773            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
10774            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
10775            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
10776            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
10777            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
10778            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
10779            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
10780            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
10781            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
10782            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
10783            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ?";
10784            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ?";
10785            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
10786            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
10787            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ?";
10788            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
10789            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ?";
10790            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
10791            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
10792            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
10793            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ?";
10794            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
10795            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ?";
10796            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
10797            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
10798            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
10799            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
10800            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10801            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10802            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10803            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10804            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
10805            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
10806            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ?";
10807            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
10808            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
10809            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
10810            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
10811            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
10812            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
10813            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
10814            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
10815            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
10816            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
10817            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
10818            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10819            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
10820            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
10821            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
10822            private static final String _FILTER_COLUMN_PK = "mbMessage.rootMessageId";
10823            private static final String _FILTER_COLUMN_USERID = "mbMessage.userId";
10824            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
10825            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
10826            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
10827            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
10828            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
10829    }