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