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