001    /**
002     * Copyright (c) 2000-2013 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.bean.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.sanitizer.Sanitizer;
032    import com.liferay.portal.kernel.sanitizer.SanitizerException;
033    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
034    import com.liferay.portal.kernel.util.ArrayUtil;
035    import com.liferay.portal.kernel.util.ContentTypes;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.StringBundler;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.BatchSessionUtil;
049    import com.liferay.portal.service.persistence.CompanyPersistence;
050    import com.liferay.portal.service.persistence.GroupPersistence;
051    import com.liferay.portal.service.persistence.LockPersistence;
052    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
053    import com.liferay.portal.service.persistence.ResourcePersistence;
054    import com.liferay.portal.service.persistence.SubscriptionPersistence;
055    import com.liferay.portal.service.persistence.UserPersistence;
056    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
057    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
058    
059    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
060    import com.liferay.portlet.asset.service.persistence.AssetLinkPersistence;
061    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
062    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
063    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
064    import com.liferay.portlet.messageboards.NoSuchMessageException;
065    import com.liferay.portlet.messageboards.model.MBMessage;
066    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
067    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
068    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
069    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
070    import com.liferay.portlet.wiki.service.persistence.WikiPagePersistence;
071    
072    import java.io.Serializable;
073    
074    import java.util.ArrayList;
075    import java.util.Collections;
076    import java.util.List;
077    
078    /**
079     * The persistence implementation for the message-boards message service.
080     *
081     * <p>
082     * Caching information and settings can be found in <code>portal.properties</code>
083     * </p>
084     *
085     * @author Brian Wing Shun Chan
086     * @see MBMessagePersistence
087     * @see MBMessageUtil
088     * @generated
089     */
090    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
091            implements MBMessagePersistence {
092            /*
093             * NOTE FOR DEVELOPERS:
094             *
095             * 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.
096             */
097            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
098            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
099                    ".List1";
100            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
101                    ".List2";
102            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
103                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
105                            new String[] {
106                                    String.class.getName(),
107                                    
108                            "java.lang.Integer", "java.lang.Integer",
109                                    "com.liferay.portal.kernel.util.OrderByComparator"
110                            });
111            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
112                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
114                            new String[] { String.class.getName() },
115                            MBMessageModelImpl.UUID_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
119                            new String[] { String.class.getName() });
120            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
121                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
122                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
123                            new String[] { String.class.getName(), Long.class.getName() },
124                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
125                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
126            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
127                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
129                            new String[] { String.class.getName(), Long.class.getName() });
130            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
131                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
132                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
133                            new String[] {
134                                    Long.class.getName(),
135                                    
136                            "java.lang.Integer", "java.lang.Integer",
137                                    "com.liferay.portal.kernel.util.OrderByComparator"
138                            });
139            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
140                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
141                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
143                            new String[] { Long.class.getName() },
144                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
145            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
146                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
147                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
148                            new String[] { Long.class.getName() });
149            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
150                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
151                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
153                            new String[] {
154                                    Long.class.getName(),
155                                    
156                            "java.lang.Integer", "java.lang.Integer",
157                                    "com.liferay.portal.kernel.util.OrderByComparator"
158                            });
159            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
160                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
161                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
162                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
163                            new String[] { Long.class.getName() },
164                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK);
165            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
168                            new String[] { Long.class.getName() });
169            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
170                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
171                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
172                            new String[] {
173                                    Long.class.getName(),
174                                    
175                            "java.lang.Integer", "java.lang.Integer",
176                                    "com.liferay.portal.kernel.util.OrderByComparator"
177                            });
178            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
179                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
180                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
182                            new String[] { Long.class.getName() },
183                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
184            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
186                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
187                            new String[] { Long.class.getName() });
188            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
189                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
190                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
191                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
192                            new String[] {
193                                    Long.class.getName(),
194                                    
195                            "java.lang.Integer", "java.lang.Integer",
196                                    "com.liferay.portal.kernel.util.OrderByComparator"
197                            });
198            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
199                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
200                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
202                            new String[] { Long.class.getName() },
203                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
204            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
205                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
206                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
207                            new String[] { Long.class.getName() });
208            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
209                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
210                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
211                            new String[] {
212                                    Long.class.getName(),
213                                    
214                            "java.lang.Integer", "java.lang.Integer",
215                                    "com.liferay.portal.kernel.util.OrderByComparator"
216                            });
217            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
218                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
219                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
220                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
221                            new String[] { Long.class.getName() },
222                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
223            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
224                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
225                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
226                            new String[] { Long.class.getName() });
227            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
228                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
229                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
230                            new String[] {
231                                    Long.class.getName(), Long.class.getName(),
232                                    
233                            "java.lang.Integer", "java.lang.Integer",
234                                    "com.liferay.portal.kernel.util.OrderByComparator"
235                            });
236            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
237                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
238                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
239                            new String[] { Long.class.getName(), Long.class.getName() },
240                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
241                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
242            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
243                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
244                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
245                            new String[] { Long.class.getName(), Long.class.getName() });
246            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
247                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
248                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
249                            new String[] {
250                                    Long.class.getName(), Long.class.getName(),
251                                    
252                            "java.lang.Integer", "java.lang.Integer",
253                                    "com.liferay.portal.kernel.util.OrderByComparator"
254                            });
255            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
256                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
257                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
258                            new String[] { Long.class.getName(), Long.class.getName() },
259                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
260                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK);
261            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
262                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
263                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
264                            new String[] { Long.class.getName(), Long.class.getName() });
265            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
266                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
267                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
268                            new String[] {
269                                    Long.class.getName(), Integer.class.getName(),
270                                    
271                            "java.lang.Integer", "java.lang.Integer",
272                                    "com.liferay.portal.kernel.util.OrderByComparator"
273                            });
274            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
275                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
276                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
277                            new String[] { Long.class.getName(), Integer.class.getName() },
278                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
279                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
280            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
281                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
282                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
283                            new String[] { Long.class.getName(), Integer.class.getName() });
284            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
285                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
286                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
287                            new String[] {
288                                    Long.class.getName(), Integer.class.getName(),
289                                    
290                            "java.lang.Integer", "java.lang.Integer",
291                                    "com.liferay.portal.kernel.util.OrderByComparator"
292                            });
293            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
294                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
295                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
296                            new String[] { Long.class.getName(), Integer.class.getName() },
297                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
298                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
299            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
300                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
301                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
302                            new String[] { Long.class.getName(), Integer.class.getName() });
303            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
304                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
305                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
306                            new String[] {
307                                    Long.class.getName(), Long.class.getName(),
308                                    
309                            "java.lang.Integer", "java.lang.Integer",
310                                    "com.liferay.portal.kernel.util.OrderByComparator"
311                            });
312            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
313                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
314                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
315                            new String[] { Long.class.getName(), Long.class.getName() },
316                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
317                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK);
318            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
319                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
320                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
321                            new String[] { Long.class.getName(), Long.class.getName() });
322            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
323                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
324                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
325                            new String[] { Long.class.getName(), Long.class.getName() });
326            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
327                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
328                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
329                            new String[] {
330                                    Long.class.getName(), Long.class.getName(),
331                                    
332                            "java.lang.Integer", "java.lang.Integer",
333                                    "com.liferay.portal.kernel.util.OrderByComparator"
334                            });
335            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
336                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
337                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
338                            new String[] { Long.class.getName(), Long.class.getName() },
339                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
340                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
341            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
342                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
343                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
344                            new String[] { Long.class.getName(), Long.class.getName() });
345            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
346                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
347                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
348                            new String[] {
349                                    Long.class.getName(), Long.class.getName(),
350                                    
351                            "java.lang.Integer", "java.lang.Integer",
352                                    "com.liferay.portal.kernel.util.OrderByComparator"
353                            });
354            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
355                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
356                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
357                            new String[] { Long.class.getName(), Long.class.getName() },
358                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
359                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK);
360            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
361                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
362                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
363                            new String[] { Long.class.getName(), Long.class.getName() });
364            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
365                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
366                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
367                            new String[] {
368                                    Long.class.getName(), Boolean.class.getName(),
369                                    
370                            "java.lang.Integer", "java.lang.Integer",
371                                    "com.liferay.portal.kernel.util.OrderByComparator"
372                            });
373            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
374                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
375                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
376                            new String[] { Long.class.getName(), Boolean.class.getName() },
377                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
378                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
379            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
380                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
381                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
382                            new String[] { Long.class.getName(), Boolean.class.getName() });
383            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
384                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
385                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
386                            new String[] {
387                                    Long.class.getName(), Integer.class.getName(),
388                                    
389                            "java.lang.Integer", "java.lang.Integer",
390                                    "com.liferay.portal.kernel.util.OrderByComparator"
391                            });
392            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
393                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
394                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
395                            new String[] { Long.class.getName(), Integer.class.getName() },
396                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
397                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
398            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
399                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
400                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
401                            new String[] { Long.class.getName(), Integer.class.getName() });
402            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
403                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
404                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
405                            new String[] {
406                                    Long.class.getName(), Integer.class.getName(),
407                                    
408                            "java.lang.Integer", "java.lang.Integer",
409                                    "com.liferay.portal.kernel.util.OrderByComparator"
410                            });
411            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
412                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
413                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
414                            new String[] { Long.class.getName(), Integer.class.getName() },
415                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
416                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
417            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
418                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
419                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
420                            new String[] { Long.class.getName(), Integer.class.getName() });
421            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
422                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
423                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
424                            new String[] {
425                                    Long.class.getName(), Long.class.getName(),
426                                    Integer.class.getName(),
427                                    
428                            "java.lang.Integer", "java.lang.Integer",
429                                    "com.liferay.portal.kernel.util.OrderByComparator"
430                            });
431            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
432                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
433                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
434                            new String[] {
435                                    Long.class.getName(), Long.class.getName(),
436                                    Integer.class.getName()
437                            },
438                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
439                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
440                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
441            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
442                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
443                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
444                            new String[] {
445                                    Long.class.getName(), Long.class.getName(),
446                                    Integer.class.getName()
447                            });
448            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
449                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
450                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
451                            new String[] {
452                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
453                                    
454                            "java.lang.Integer", "java.lang.Integer",
455                                    "com.liferay.portal.kernel.util.OrderByComparator"
456                            });
457            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
458                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
459                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
460                            new String[] {
461                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
462                            },
463                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
464                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
465                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
466            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
467                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
468                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
469                            new String[] {
470                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
471                            });
472            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
473                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
474                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
475                            new String[] {
476                                    Long.class.getName(), Long.class.getName(),
477                                    Integer.class.getName(),
478                                    
479                            "java.lang.Integer", "java.lang.Integer",
480                                    "com.liferay.portal.kernel.util.OrderByComparator"
481                            });
482            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
483                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
484                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
485                            new String[] {
486                                    Long.class.getName(), Long.class.getName(),
487                                    Integer.class.getName()
488                            },
489                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
490                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
491                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
492            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
493                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
494                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
495                            new String[] {
496                                    Long.class.getName(), Long.class.getName(),
497                                    Integer.class.getName()
498                            });
499            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
500                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
501                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
502                            new String[] {
503                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
504                                    
505                            "java.lang.Integer", "java.lang.Integer",
506                                    "com.liferay.portal.kernel.util.OrderByComparator"
507                            });
508            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
509                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
510                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
511                            new String[] {
512                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
513                            },
514                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
515                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
516                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
517            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
518                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
519                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
520                            new String[] {
521                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
522                            });
523            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
524                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
525                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
526                            new String[] {
527                                    Long.class.getName(), Long.class.getName(),
528                                    Integer.class.getName(),
529                                    
530                            "java.lang.Integer", "java.lang.Integer",
531                                    "com.liferay.portal.kernel.util.OrderByComparator"
532                            });
533            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
534                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
535                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
536                            new String[] {
537                                    Long.class.getName(), Long.class.getName(),
538                                    Integer.class.getName()
539                            },
540                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
541                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
542                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
543            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
544                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
545                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
546                            new String[] {
547                                    Long.class.getName(), Long.class.getName(),
548                                    Integer.class.getName()
549                            });
550            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
551                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
552                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
553                            new String[] {
554                                    Long.class.getName(), Long.class.getName(),
555                                    Integer.class.getName()
556                            });
557            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
558                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
559                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
560                            new String[] {
561                                    Long.class.getName(), Long.class.getName(),
562                                    Integer.class.getName(),
563                                    
564                            "java.lang.Integer", "java.lang.Integer",
565                                    "com.liferay.portal.kernel.util.OrderByComparator"
566                            });
567            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
568                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
569                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
570                            new String[] {
571                                    Long.class.getName(), Long.class.getName(),
572                                    Integer.class.getName()
573                            },
574                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
575                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
576                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
577            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
578                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
579                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
580                            new String[] {
581                                    Long.class.getName(), Long.class.getName(),
582                                    Integer.class.getName()
583                            });
584            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
585                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
586                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
587                            new String[] {
588                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
589                                    Boolean.class.getName(),
590                                    
591                            "java.lang.Integer", "java.lang.Integer",
592                                    "com.liferay.portal.kernel.util.OrderByComparator"
593                            });
594            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
595                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
596                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
597                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
598                            new String[] {
599                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
600                                    Boolean.class.getName()
601                            },
602                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
603                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
604                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
605                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
606            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
607                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
608                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
609                            new String[] {
610                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
611                                    Boolean.class.getName()
612                            });
613            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
614                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
615                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
616                            new String[] {
617                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
618                                    Integer.class.getName(),
619                                    
620                            "java.lang.Integer", "java.lang.Integer",
621                                    "com.liferay.portal.kernel.util.OrderByComparator"
622                            });
623            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
624                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
625                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
627                            new String[] {
628                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
629                                    Integer.class.getName()
630                            },
631                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
632                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
633                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
634                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
635            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
636                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
637                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
638                            new String[] {
639                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
640                                    Integer.class.getName()
641                            });
642            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
643                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
644                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
645                            new String[] {
646                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
647                                    Integer.class.getName(),
648                                    
649                            "java.lang.Integer", "java.lang.Integer",
650                                    "com.liferay.portal.kernel.util.OrderByComparator"
651                            });
652            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
653                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
656                            new String[] {
657                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
658                                    Integer.class.getName()
659                            },
660                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
661                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
662                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
663                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
664            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
665                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
666                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
667                            new String[] {
668                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
669                                    Integer.class.getName()
670                            });
671            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
672                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
673                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
674            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
675                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
676                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
677            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
678                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
679                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
680    
681            /**
682             * Caches the message-boards message in the entity cache if it is enabled.
683             *
684             * @param mbMessage the message-boards message
685             */
686            public void cacheResult(MBMessage mbMessage) {
687                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
688                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
689    
690                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
691                            new Object[] {
692                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
693                            }, mbMessage);
694    
695                    mbMessage.resetOriginalValues();
696            }
697    
698            /**
699             * Caches the message-boards messages in the entity cache if it is enabled.
700             *
701             * @param mbMessages the message-boards messages
702             */
703            public void cacheResult(List<MBMessage> mbMessages) {
704                    for (MBMessage mbMessage : mbMessages) {
705                            if (EntityCacheUtil.getResult(
706                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
707                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
708                                    cacheResult(mbMessage);
709                            }
710                            else {
711                                    mbMessage.resetOriginalValues();
712                            }
713                    }
714            }
715    
716            /**
717             * Clears the cache for all message-boards messages.
718             *
719             * <p>
720             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
721             * </p>
722             */
723            @Override
724            public void clearCache() {
725                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
726                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
727                    }
728    
729                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
730    
731                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
732                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
733                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
734            }
735    
736            /**
737             * Clears the cache for the message-boards message.
738             *
739             * <p>
740             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
741             * </p>
742             */
743            @Override
744            public void clearCache(MBMessage mbMessage) {
745                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
746                            MBMessageImpl.class, mbMessage.getPrimaryKey());
747    
748                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
749                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
750    
751                    clearUniqueFindersCache(mbMessage);
752            }
753    
754            @Override
755            public void clearCache(List<MBMessage> mbMessages) {
756                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
757                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
758    
759                    for (MBMessage mbMessage : mbMessages) {
760                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
761                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
762    
763                            clearUniqueFindersCache(mbMessage);
764                    }
765            }
766    
767            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
768                    if (mbMessage.isNew()) {
769                            Object[] args = new Object[] {
770                                            mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
771                                    };
772    
773                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
774                                    Long.valueOf(1));
775                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
776                                    mbMessage);
777                    }
778                    else {
779                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
780    
781                            if ((mbMessageModelImpl.getColumnBitmask() &
782                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
783                                    Object[] args = new Object[] {
784                                                    mbMessage.getUuid(),
785                                                    Long.valueOf(mbMessage.getGroupId())
786                                            };
787    
788                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
789                                            Long.valueOf(1));
790                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
791                                            mbMessage);
792                            }
793                    }
794            }
795    
796            protected void clearUniqueFindersCache(MBMessage mbMessage) {
797                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
798    
799                    Object[] args = new Object[] {
800                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
801                            };
802    
803                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
804                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
805    
806                    if ((mbMessageModelImpl.getColumnBitmask() &
807                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
808                            args = new Object[] {
809                                            mbMessageModelImpl.getOriginalUuid(),
810                                            Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
811                                    };
812    
813                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
814                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
815                    }
816            }
817    
818            /**
819             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
820             *
821             * @param messageId the primary key for the new message-boards message
822             * @return the new message-boards message
823             */
824            public MBMessage create(long messageId) {
825                    MBMessage mbMessage = new MBMessageImpl();
826    
827                    mbMessage.setNew(true);
828                    mbMessage.setPrimaryKey(messageId);
829    
830                    String uuid = PortalUUIDUtil.generate();
831    
832                    mbMessage.setUuid(uuid);
833    
834                    return mbMessage;
835            }
836    
837            /**
838             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
839             *
840             * @param messageId the primary key of the message-boards message
841             * @return the message-boards message that was removed
842             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
843             * @throws SystemException if a system exception occurred
844             */
845            public MBMessage remove(long messageId)
846                    throws NoSuchMessageException, SystemException {
847                    return remove(Long.valueOf(messageId));
848            }
849    
850            /**
851             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
852             *
853             * @param primaryKey the primary key of the message-boards message
854             * @return the message-boards message that was removed
855             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
856             * @throws SystemException if a system exception occurred
857             */
858            @Override
859            public MBMessage remove(Serializable primaryKey)
860                    throws NoSuchMessageException, SystemException {
861                    Session session = null;
862    
863                    try {
864                            session = openSession();
865    
866                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
867                                            primaryKey);
868    
869                            if (mbMessage == null) {
870                                    if (_log.isWarnEnabled()) {
871                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
872                                    }
873    
874                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
875                                            primaryKey);
876                            }
877    
878                            return remove(mbMessage);
879                    }
880                    catch (NoSuchMessageException nsee) {
881                            throw nsee;
882                    }
883                    catch (Exception e) {
884                            throw processException(e);
885                    }
886                    finally {
887                            closeSession(session);
888                    }
889            }
890    
891            @Override
892            protected MBMessage removeImpl(MBMessage mbMessage)
893                    throws SystemException {
894                    mbMessage = toUnwrappedModel(mbMessage);
895    
896                    Session session = null;
897    
898                    try {
899                            session = openSession();
900    
901                            BatchSessionUtil.delete(session, mbMessage);
902                    }
903                    catch (Exception e) {
904                            throw processException(e);
905                    }
906                    finally {
907                            closeSession(session);
908                    }
909    
910                    clearCache(mbMessage);
911    
912                    return mbMessage;
913            }
914    
915            @Override
916            public MBMessage updateImpl(
917                    com.liferay.portlet.messageboards.model.MBMessage mbMessage,
918                    boolean merge) throws SystemException {
919                    mbMessage = toUnwrappedModel(mbMessage);
920    
921                    boolean isNew = mbMessage.isNew();
922    
923                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
924    
925                    if (Validator.isNull(mbMessage.getUuid())) {
926                            String uuid = PortalUUIDUtil.generate();
927    
928                            mbMessage.setUuid(uuid);
929                    }
930    
931                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
932    
933                    if (userId > 0) {
934                            long companyId = mbMessage.getCompanyId();
935    
936                            long groupId = mbMessage.getGroupId();
937    
938                            long messageId = 0;
939    
940                            if (!isNew) {
941                                    messageId = mbMessage.getPrimaryKey();
942                            }
943    
944                            try {
945                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
946                                                    userId,
947                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
948                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
949                                                    mbMessage.getSubject(), null));
950                            }
951                            catch (SanitizerException se) {
952                                    throw new SystemException(se);
953                            }
954                    }
955    
956                    Session session = null;
957    
958                    try {
959                            session = openSession();
960    
961                            BatchSessionUtil.update(session, mbMessage, merge);
962    
963                            mbMessage.setNew(false);
964                    }
965                    catch (Exception e) {
966                            throw processException(e);
967                    }
968                    finally {
969                            closeSession(session);
970                    }
971    
972                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
973    
974                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
975                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
976                    }
977    
978                    else {
979                            if ((mbMessageModelImpl.getColumnBitmask() &
980                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
981                                    Object[] args = new Object[] {
982                                                    mbMessageModelImpl.getOriginalUuid()
983                                            };
984    
985                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
986                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
987                                            args);
988    
989                                    args = new Object[] { mbMessageModelImpl.getUuid() };
990    
991                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
992                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
993                                            args);
994                            }
995    
996                            if ((mbMessageModelImpl.getColumnBitmask() &
997                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
998                                    Object[] args = new Object[] {
999                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
1000                                            };
1001    
1002                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1003                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1004                                            args);
1005    
1006                                    args = new Object[] {
1007                                                    Long.valueOf(mbMessageModelImpl.getGroupId())
1008                                            };
1009    
1010                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1011                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1012                                            args);
1013                            }
1014    
1015                            if ((mbMessageModelImpl.getColumnBitmask() &
1016                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1017                                    Object[] args = new Object[] {
1018                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
1019                                            };
1020    
1021                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1022                                            args);
1023                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1024                                            args);
1025    
1026                                    args = new Object[] {
1027                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
1028                                            };
1029    
1030                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1031                                            args);
1032                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1033                                            args);
1034                            }
1035    
1036                            if ((mbMessageModelImpl.getColumnBitmask() &
1037                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
1038                                    Object[] args = new Object[] {
1039                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1040                                            };
1041    
1042                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1043                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1044                                            args);
1045    
1046                                    args = new Object[] {
1047                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1048                                            };
1049    
1050                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1051                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1052                                            args);
1053                            }
1054    
1055                            if ((mbMessageModelImpl.getColumnBitmask() &
1056                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
1057                                    Object[] args = new Object[] {
1058                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1059                                            };
1060    
1061                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1062                                            args);
1063                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1064                                            args);
1065    
1066                                    args = new Object[] {
1067                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1068                                            };
1069    
1070                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1071                                            args);
1072                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1073                                            args);
1074                            }
1075    
1076                            if ((mbMessageModelImpl.getColumnBitmask() &
1077                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1078                                    Object[] args = new Object[] {
1079                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1080                                            };
1081    
1082                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1083                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1084                                            args);
1085    
1086                                    args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
1087    
1088                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1089                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1090                                            args);
1091                            }
1092    
1093                            if ((mbMessageModelImpl.getColumnBitmask() &
1094                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
1095                                    Object[] args = new Object[] {
1096                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1097                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1098                                            };
1099    
1100                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1101                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1102                                            args);
1103    
1104                                    args = new Object[] {
1105                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1106                                                    Long.valueOf(mbMessageModelImpl.getUserId())
1107                                            };
1108    
1109                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1110                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1111                                            args);
1112                            }
1113    
1114                            if ((mbMessageModelImpl.getColumnBitmask() &
1115                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1116                                    Object[] args = new Object[] {
1117                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1118                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
1119                                            };
1120    
1121                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1122                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1123                                            args);
1124    
1125                                    args = new Object[] {
1126                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1127                                                    Long.valueOf(mbMessageModelImpl.getCategoryId())
1128                                            };
1129    
1130                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1131                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1132                                            args);
1133                            }
1134    
1135                            if ((mbMessageModelImpl.getColumnBitmask() &
1136                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
1137                                    Object[] args = new Object[] {
1138                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1139                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1140                                            };
1141    
1142                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1143                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1144                                            args);
1145    
1146                                    args = new Object[] {
1147                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1148                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1149                                            };
1150    
1151                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1152                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1153                                            args);
1154                            }
1155    
1156                            if ((mbMessageModelImpl.getColumnBitmask() &
1157                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
1158                                    Object[] args = new Object[] {
1159                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
1160                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1161                                            };
1162    
1163                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1164                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1165                                            args);
1166    
1167                                    args = new Object[] {
1168                                                    Long.valueOf(mbMessageModelImpl.getCompanyId()),
1169                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1170                                            };
1171    
1172                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1173                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1174                                            args);
1175                            }
1176    
1177                            if ((mbMessageModelImpl.getColumnBitmask() &
1178                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
1179                                    Object[] args = new Object[] {
1180                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1181                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
1182                                            };
1183    
1184                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1185                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1186                                            args);
1187    
1188                                    args = new Object[] {
1189                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1190                                                    Long.valueOf(mbMessageModelImpl.getClassNameId())
1191                                            };
1192    
1193                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1194                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1195                                            args);
1196                            }
1197    
1198                            if ((mbMessageModelImpl.getColumnBitmask() &
1199                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1200                                    Object[] args = new Object[] {
1201                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1202                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1203                                            };
1204    
1205                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1206                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1207                                            args);
1208    
1209                                    args = new Object[] {
1210                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1211                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1212                                            };
1213    
1214                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1215                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1216                                            args);
1217                            }
1218    
1219                            if ((mbMessageModelImpl.getColumnBitmask() &
1220                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
1221                                    Object[] args = new Object[] {
1222                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1223                                                    Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
1224                                            };
1225    
1226                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1227                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1228                                            args);
1229    
1230                                    args = new Object[] {
1231                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1232                                                    Long.valueOf(mbMessageModelImpl.getParentMessageId())
1233                                            };
1234    
1235                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1236                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1237                                            args);
1238                            }
1239    
1240                            if ((mbMessageModelImpl.getColumnBitmask() &
1241                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
1242                                    Object[] args = new Object[] {
1243                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1244                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1245                                            };
1246    
1247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1248                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1249                                            args);
1250    
1251                                    args = new Object[] {
1252                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1253                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1254                                            };
1255    
1256                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1257                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1258                                            args);
1259                            }
1260    
1261                            if ((mbMessageModelImpl.getColumnBitmask() &
1262                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
1263                                    Object[] args = new Object[] {
1264                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1265                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1266                                            };
1267    
1268                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1269                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1270                                            args);
1271    
1272                                    args = new Object[] {
1273                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1274                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1275                                            };
1276    
1277                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1279                                            args);
1280                            }
1281    
1282                            if ((mbMessageModelImpl.getColumnBitmask() &
1283                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
1284                                    Object[] args = new Object[] {
1285                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1286                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1287                                            };
1288    
1289                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1290                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1291                                            args);
1292    
1293                                    args = new Object[] {
1294                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1295                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1296                                            };
1297    
1298                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1299                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1300                                            args);
1301                            }
1302    
1303                            if ((mbMessageModelImpl.getColumnBitmask() &
1304                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
1305                                    Object[] args = new Object[] {
1306                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1307                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1308                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1309                                            };
1310    
1311                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1312                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1313                                            args);
1314    
1315                                    args = new Object[] {
1316                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1317                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1318                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1319                                            };
1320    
1321                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1322                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1323                                            args);
1324                            }
1325    
1326                            if ((mbMessageModelImpl.getColumnBitmask() &
1327                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
1328                                    Object[] args = new Object[] {
1329                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1330                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1331                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1332                                            };
1333    
1334                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1335                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1336                                            args);
1337    
1338                                    args = new Object[] {
1339                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1340                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1341                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1342                                            };
1343    
1344                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1345                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1346                                            args);
1347                            }
1348    
1349                            if ((mbMessageModelImpl.getColumnBitmask() &
1350                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
1351                                    Object[] args = new Object[] {
1352                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1353                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1354                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1355                                            };
1356    
1357                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1358                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1359                                            args);
1360    
1361                                    args = new Object[] {
1362                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1363                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1364                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1365                                            };
1366    
1367                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1368                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1369                                            args);
1370                            }
1371    
1372                            if ((mbMessageModelImpl.getColumnBitmask() &
1373                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
1374                                    Object[] args = new Object[] {
1375                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1376                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1377                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1378                                            };
1379    
1380                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1381                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1382                                            args);
1383    
1384                                    args = new Object[] {
1385                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1386                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1387                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1388                                            };
1389    
1390                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1391                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1392                                            args);
1393                            }
1394    
1395                            if ((mbMessageModelImpl.getColumnBitmask() &
1396                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
1397                                    Object[] args = new Object[] {
1398                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1399                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1400                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1401                                            };
1402    
1403                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1404                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1405                                            args);
1406    
1407                                    args = new Object[] {
1408                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1409                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1410                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1411                                            };
1412    
1413                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1414                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1415                                            args);
1416                            }
1417    
1418                            if ((mbMessageModelImpl.getColumnBitmask() &
1419                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1420                                    Object[] args = new Object[] {
1421                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1422                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1423                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1424                                            };
1425    
1426                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1427                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1428                                            args);
1429    
1430                                    args = new Object[] {
1431                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1432                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1433                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1434                                            };
1435    
1436                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1437                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1438                                            args);
1439                            }
1440    
1441                            if ((mbMessageModelImpl.getColumnBitmask() &
1442                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
1443                                    Object[] args = new Object[] {
1444                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1445                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1446                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1447                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1448                                            };
1449    
1450                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1451                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1452                                            args);
1453    
1454                                    args = new Object[] {
1455                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1456                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1457                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1458                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1459                                            };
1460    
1461                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1462                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1463                                            args);
1464                            }
1465    
1466                            if ((mbMessageModelImpl.getColumnBitmask() &
1467                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
1468                                    Object[] args = new Object[] {
1469                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1470                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1471                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1472                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1473                                            };
1474    
1475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1477                                            args);
1478    
1479                                    args = new Object[] {
1480                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1481                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1482                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1483                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1484                                            };
1485    
1486                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1487                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1488                                            args);
1489                            }
1490    
1491                            if ((mbMessageModelImpl.getColumnBitmask() &
1492                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
1493                                    Object[] args = new Object[] {
1494                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1495                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1496                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1497                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1498                                            };
1499    
1500                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1501                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1502                                            args);
1503    
1504                                    args = new Object[] {
1505                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1506                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1507                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1508                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1509                                            };
1510    
1511                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1512                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1513                                            args);
1514                            }
1515                    }
1516    
1517                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1518                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
1519    
1520                    clearUniqueFindersCache(mbMessage);
1521                    cacheUniqueFindersCache(mbMessage);
1522    
1523                    return mbMessage;
1524            }
1525    
1526            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
1527                    if (mbMessage instanceof MBMessageImpl) {
1528                            return mbMessage;
1529                    }
1530    
1531                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
1532    
1533                    mbMessageImpl.setNew(mbMessage.isNew());
1534                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
1535    
1536                    mbMessageImpl.setUuid(mbMessage.getUuid());
1537                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
1538                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
1539                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
1540                    mbMessageImpl.setUserId(mbMessage.getUserId());
1541                    mbMessageImpl.setUserName(mbMessage.getUserName());
1542                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
1543                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
1544                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
1545                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
1546                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
1547                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
1548                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
1549                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
1550                    mbMessageImpl.setSubject(mbMessage.getSubject());
1551                    mbMessageImpl.setBody(mbMessage.getBody());
1552                    mbMessageImpl.setFormat(mbMessage.getFormat());
1553                    mbMessageImpl.setAttachments(mbMessage.isAttachments());
1554                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
1555                    mbMessageImpl.setPriority(mbMessage.getPriority());
1556                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
1557                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
1558                    mbMessageImpl.setStatus(mbMessage.getStatus());
1559                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
1560                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
1561                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
1562    
1563                    return mbMessageImpl;
1564            }
1565    
1566            /**
1567             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1568             *
1569             * @param primaryKey the primary key of the message-boards message
1570             * @return the message-boards message
1571             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
1572             * @throws SystemException if a system exception occurred
1573             */
1574            @Override
1575            public MBMessage findByPrimaryKey(Serializable primaryKey)
1576                    throws NoSuchModelException, SystemException {
1577                    return findByPrimaryKey(((Long)primaryKey).longValue());
1578            }
1579    
1580            /**
1581             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
1582             *
1583             * @param messageId the primary key of the message-boards message
1584             * @return the message-boards message
1585             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1586             * @throws SystemException if a system exception occurred
1587             */
1588            public MBMessage findByPrimaryKey(long messageId)
1589                    throws NoSuchMessageException, SystemException {
1590                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
1591    
1592                    if (mbMessage == null) {
1593                            if (_log.isWarnEnabled()) {
1594                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
1595                            }
1596    
1597                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1598                                    messageId);
1599                    }
1600    
1601                    return mbMessage;
1602            }
1603    
1604            /**
1605             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1606             *
1607             * @param primaryKey the primary key of the message-boards message
1608             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1609             * @throws SystemException if a system exception occurred
1610             */
1611            @Override
1612            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
1613                    throws SystemException {
1614                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1615            }
1616    
1617            /**
1618             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1619             *
1620             * @param messageId the primary key of the message-boards message
1621             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1622             * @throws SystemException if a system exception occurred
1623             */
1624            public MBMessage fetchByPrimaryKey(long messageId)
1625                    throws SystemException {
1626                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1627                                    MBMessageImpl.class, messageId);
1628    
1629                    if (mbMessage == _nullMBMessage) {
1630                            return null;
1631                    }
1632    
1633                    if (mbMessage == null) {
1634                            Session session = null;
1635    
1636                            boolean hasException = false;
1637    
1638                            try {
1639                                    session = openSession();
1640    
1641                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
1642                                                    Long.valueOf(messageId));
1643                            }
1644                            catch (Exception e) {
1645                                    hasException = true;
1646    
1647                                    throw processException(e);
1648                            }
1649                            finally {
1650                                    if (mbMessage != null) {
1651                                            cacheResult(mbMessage);
1652                                    }
1653                                    else if (!hasException) {
1654                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1655                                                    MBMessageImpl.class, messageId, _nullMBMessage);
1656                                    }
1657    
1658                                    closeSession(session);
1659                            }
1660                    }
1661    
1662                    return mbMessage;
1663            }
1664    
1665            /**
1666             * Returns all the message-boards messages where uuid = &#63;.
1667             *
1668             * @param uuid the uuid
1669             * @return the matching message-boards messages
1670             * @throws SystemException if a system exception occurred
1671             */
1672            public List<MBMessage> findByUuid(String uuid) throws SystemException {
1673                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1674            }
1675    
1676            /**
1677             * Returns a range of all the message-boards messages where uuid = &#63;.
1678             *
1679             * <p>
1680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1681             * </p>
1682             *
1683             * @param uuid the uuid
1684             * @param start the lower bound of the range of message-boards messages
1685             * @param end the upper bound of the range of message-boards messages (not inclusive)
1686             * @return the range of matching message-boards messages
1687             * @throws SystemException if a system exception occurred
1688             */
1689            public List<MBMessage> findByUuid(String uuid, int start, int end)
1690                    throws SystemException {
1691                    return findByUuid(uuid, start, end, null);
1692            }
1693    
1694            /**
1695             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
1696             *
1697             * <p>
1698             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1699             * </p>
1700             *
1701             * @param uuid the uuid
1702             * @param start the lower bound of the range of message-boards messages
1703             * @param end the upper bound of the range of message-boards messages (not inclusive)
1704             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1705             * @return the ordered range of matching message-boards messages
1706             * @throws SystemException if a system exception occurred
1707             */
1708            public List<MBMessage> findByUuid(String uuid, int start, int end,
1709                    OrderByComparator orderByComparator) throws SystemException {
1710                    FinderPath finderPath = null;
1711                    Object[] finderArgs = null;
1712    
1713                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1714                                    (orderByComparator == null)) {
1715                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1716                            finderArgs = new Object[] { uuid };
1717                    }
1718                    else {
1719                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1720                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1721                    }
1722    
1723                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1724                                    finderArgs, this);
1725    
1726                    if ((list != null) && !list.isEmpty()) {
1727                            for (MBMessage mbMessage : list) {
1728                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
1729                                            list = null;
1730    
1731                                            break;
1732                                    }
1733                            }
1734                    }
1735    
1736                    if (list == null) {
1737                            StringBundler query = null;
1738    
1739                            if (orderByComparator != null) {
1740                                    query = new StringBundler(3 +
1741                                                    (orderByComparator.getOrderByFields().length * 3));
1742                            }
1743                            else {
1744                                    query = new StringBundler(3);
1745                            }
1746    
1747                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1748    
1749                            if (uuid == null) {
1750                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1751                            }
1752                            else {
1753                                    if (uuid.equals(StringPool.BLANK)) {
1754                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1755                                    }
1756                                    else {
1757                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1758                                    }
1759                            }
1760    
1761                            if (orderByComparator != null) {
1762                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1763                                            orderByComparator);
1764                            }
1765    
1766                            else {
1767                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1768                            }
1769    
1770                            String sql = query.toString();
1771    
1772                            Session session = null;
1773    
1774                            try {
1775                                    session = openSession();
1776    
1777                                    Query q = session.createQuery(sql);
1778    
1779                                    QueryPos qPos = QueryPos.getInstance(q);
1780    
1781                                    if (uuid != null) {
1782                                            qPos.add(uuid);
1783                                    }
1784    
1785                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1786                                                    end);
1787                            }
1788                            catch (Exception e) {
1789                                    throw processException(e);
1790                            }
1791                            finally {
1792                                    if (list == null) {
1793                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1794                                    }
1795                                    else {
1796                                            cacheResult(list);
1797    
1798                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1799                                    }
1800    
1801                                    closeSession(session);
1802                            }
1803                    }
1804    
1805                    return list;
1806            }
1807    
1808            /**
1809             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1810             *
1811             * @param uuid the uuid
1812             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1813             * @return the first matching message-boards message
1814             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1815             * @throws SystemException if a system exception occurred
1816             */
1817            public MBMessage findByUuid_First(String uuid,
1818                    OrderByComparator orderByComparator)
1819                    throws NoSuchMessageException, SystemException {
1820                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
1821    
1822                    if (mbMessage != null) {
1823                            return mbMessage;
1824                    }
1825    
1826                    StringBundler msg = new StringBundler(4);
1827    
1828                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1829    
1830                    msg.append("uuid=");
1831                    msg.append(uuid);
1832    
1833                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1834    
1835                    throw new NoSuchMessageException(msg.toString());
1836            }
1837    
1838            /**
1839             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1840             *
1841             * @param uuid the uuid
1842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1843             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1844             * @throws SystemException if a system exception occurred
1845             */
1846            public MBMessage fetchByUuid_First(String uuid,
1847                    OrderByComparator orderByComparator) throws SystemException {
1848                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
1849    
1850                    if (!list.isEmpty()) {
1851                            return list.get(0);
1852                    }
1853    
1854                    return null;
1855            }
1856    
1857            /**
1858             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1859             *
1860             * @param uuid the uuid
1861             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1862             * @return the last matching message-boards message
1863             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1864             * @throws SystemException if a system exception occurred
1865             */
1866            public MBMessage findByUuid_Last(String uuid,
1867                    OrderByComparator orderByComparator)
1868                    throws NoSuchMessageException, SystemException {
1869                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
1870    
1871                    if (mbMessage != null) {
1872                            return mbMessage;
1873                    }
1874    
1875                    StringBundler msg = new StringBundler(4);
1876    
1877                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1878    
1879                    msg.append("uuid=");
1880                    msg.append(uuid);
1881    
1882                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1883    
1884                    throw new NoSuchMessageException(msg.toString());
1885            }
1886    
1887            /**
1888             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1889             *
1890             * @param uuid the uuid
1891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1892             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1893             * @throws SystemException if a system exception occurred
1894             */
1895            public MBMessage fetchByUuid_Last(String uuid,
1896                    OrderByComparator orderByComparator) throws SystemException {
1897                    int count = countByUuid(uuid);
1898    
1899                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
1900                                    orderByComparator);
1901    
1902                    if (!list.isEmpty()) {
1903                            return list.get(0);
1904                    }
1905    
1906                    return null;
1907            }
1908    
1909            /**
1910             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
1911             *
1912             * @param messageId the primary key of the current message-boards message
1913             * @param uuid the uuid
1914             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1915             * @return the previous, current, and next message-boards message
1916             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1917             * @throws SystemException if a system exception occurred
1918             */
1919            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
1920                    OrderByComparator orderByComparator)
1921                    throws NoSuchMessageException, SystemException {
1922                    MBMessage mbMessage = findByPrimaryKey(messageId);
1923    
1924                    Session session = null;
1925    
1926                    try {
1927                            session = openSession();
1928    
1929                            MBMessage[] array = new MBMessageImpl[3];
1930    
1931                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1932                                            orderByComparator, true);
1933    
1934                            array[1] = mbMessage;
1935    
1936                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1937                                            orderByComparator, false);
1938    
1939                            return array;
1940                    }
1941                    catch (Exception e) {
1942                            throw processException(e);
1943                    }
1944                    finally {
1945                            closeSession(session);
1946                    }
1947            }
1948    
1949            protected MBMessage getByUuid_PrevAndNext(Session session,
1950                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
1951                    boolean previous) {
1952                    StringBundler query = null;
1953    
1954                    if (orderByComparator != null) {
1955                            query = new StringBundler(6 +
1956                                            (orderByComparator.getOrderByFields().length * 6));
1957                    }
1958                    else {
1959                            query = new StringBundler(3);
1960                    }
1961    
1962                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1963    
1964                    if (uuid == null) {
1965                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1966                    }
1967                    else {
1968                            if (uuid.equals(StringPool.BLANK)) {
1969                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1970                            }
1971                            else {
1972                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1973                            }
1974                    }
1975    
1976                    if (orderByComparator != null) {
1977                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1978    
1979                            if (orderByConditionFields.length > 0) {
1980                                    query.append(WHERE_AND);
1981                            }
1982    
1983                            for (int i = 0; i < orderByConditionFields.length; i++) {
1984                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1985                                    query.append(orderByConditionFields[i]);
1986    
1987                                    if ((i + 1) < orderByConditionFields.length) {
1988                                            if (orderByComparator.isAscending() ^ previous) {
1989                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1990                                            }
1991                                            else {
1992                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1993                                            }
1994                                    }
1995                                    else {
1996                                            if (orderByComparator.isAscending() ^ previous) {
1997                                                    query.append(WHERE_GREATER_THAN);
1998                                            }
1999                                            else {
2000                                                    query.append(WHERE_LESSER_THAN);
2001                                            }
2002                                    }
2003                            }
2004    
2005                            query.append(ORDER_BY_CLAUSE);
2006    
2007                            String[] orderByFields = orderByComparator.getOrderByFields();
2008    
2009                            for (int i = 0; i < orderByFields.length; i++) {
2010                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2011                                    query.append(orderByFields[i]);
2012    
2013                                    if ((i + 1) < orderByFields.length) {
2014                                            if (orderByComparator.isAscending() ^ previous) {
2015                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2016                                            }
2017                                            else {
2018                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2019                                            }
2020                                    }
2021                                    else {
2022                                            if (orderByComparator.isAscending() ^ previous) {
2023                                                    query.append(ORDER_BY_ASC);
2024                                            }
2025                                            else {
2026                                                    query.append(ORDER_BY_DESC);
2027                                            }
2028                                    }
2029                            }
2030                    }
2031    
2032                    else {
2033                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2034                    }
2035    
2036                    String sql = query.toString();
2037    
2038                    Query q = session.createQuery(sql);
2039    
2040                    q.setFirstResult(0);
2041                    q.setMaxResults(2);
2042    
2043                    QueryPos qPos = QueryPos.getInstance(q);
2044    
2045                    if (uuid != null) {
2046                            qPos.add(uuid);
2047                    }
2048    
2049                    if (orderByComparator != null) {
2050                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2051    
2052                            for (Object value : values) {
2053                                    qPos.add(value);
2054                            }
2055                    }
2056    
2057                    List<MBMessage> list = q.list();
2058    
2059                    if (list.size() == 2) {
2060                            return list.get(1);
2061                    }
2062                    else {
2063                            return null;
2064                    }
2065            }
2066    
2067            /**
2068             * Returns 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.
2069             *
2070             * @param uuid the uuid
2071             * @param groupId the group ID
2072             * @return the matching message-boards message
2073             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2074             * @throws SystemException if a system exception occurred
2075             */
2076            public MBMessage findByUUID_G(String uuid, long groupId)
2077                    throws NoSuchMessageException, SystemException {
2078                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
2079    
2080                    if (mbMessage == null) {
2081                            StringBundler msg = new StringBundler(6);
2082    
2083                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2084    
2085                            msg.append("uuid=");
2086                            msg.append(uuid);
2087    
2088                            msg.append(", groupId=");
2089                            msg.append(groupId);
2090    
2091                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2092    
2093                            if (_log.isWarnEnabled()) {
2094                                    _log.warn(msg.toString());
2095                            }
2096    
2097                            throw new NoSuchMessageException(msg.toString());
2098                    }
2099    
2100                    return mbMessage;
2101            }
2102    
2103            /**
2104             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2105             *
2106             * @param uuid the uuid
2107             * @param groupId the group ID
2108             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2109             * @throws SystemException if a system exception occurred
2110             */
2111            public MBMessage fetchByUUID_G(String uuid, long groupId)
2112                    throws SystemException {
2113                    return fetchByUUID_G(uuid, groupId, true);
2114            }
2115    
2116            /**
2117             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2118             *
2119             * @param uuid the uuid
2120             * @param groupId the group ID
2121             * @param retrieveFromCache whether to use the finder cache
2122             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2123             * @throws SystemException if a system exception occurred
2124             */
2125            public MBMessage fetchByUUID_G(String uuid, long groupId,
2126                    boolean retrieveFromCache) throws SystemException {
2127                    Object[] finderArgs = new Object[] { uuid, groupId };
2128    
2129                    Object result = null;
2130    
2131                    if (retrieveFromCache) {
2132                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
2133                                            finderArgs, this);
2134                    }
2135    
2136                    if (result instanceof MBMessage) {
2137                            MBMessage mbMessage = (MBMessage)result;
2138    
2139                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
2140                                            (groupId != mbMessage.getGroupId())) {
2141                                    result = null;
2142                            }
2143                    }
2144    
2145                    if (result == null) {
2146                            StringBundler query = new StringBundler(4);
2147    
2148                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2149    
2150                            if (uuid == null) {
2151                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2152                            }
2153                            else {
2154                                    if (uuid.equals(StringPool.BLANK)) {
2155                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2156                                    }
2157                                    else {
2158                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2159                                    }
2160                            }
2161    
2162                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2163    
2164                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2165    
2166                            String sql = query.toString();
2167    
2168                            Session session = null;
2169    
2170                            try {
2171                                    session = openSession();
2172    
2173                                    Query q = session.createQuery(sql);
2174    
2175                                    QueryPos qPos = QueryPos.getInstance(q);
2176    
2177                                    if (uuid != null) {
2178                                            qPos.add(uuid);
2179                                    }
2180    
2181                                    qPos.add(groupId);
2182    
2183                                    List<MBMessage> list = q.list();
2184    
2185                                    result = list;
2186    
2187                                    MBMessage mbMessage = null;
2188    
2189                                    if (list.isEmpty()) {
2190                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2191                                                    finderArgs, list);
2192                                    }
2193                                    else {
2194                                            mbMessage = list.get(0);
2195    
2196                                            cacheResult(mbMessage);
2197    
2198                                            if ((mbMessage.getUuid() == null) ||
2199                                                            !mbMessage.getUuid().equals(uuid) ||
2200                                                            (mbMessage.getGroupId() != groupId)) {
2201                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2202                                                            finderArgs, mbMessage);
2203                                            }
2204                                    }
2205    
2206                                    return mbMessage;
2207                            }
2208                            catch (Exception e) {
2209                                    throw processException(e);
2210                            }
2211                            finally {
2212                                    if (result == null) {
2213                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
2214                                                    finderArgs);
2215                                    }
2216    
2217                                    closeSession(session);
2218                            }
2219                    }
2220                    else {
2221                            if (result instanceof List<?>) {
2222                                    return null;
2223                            }
2224                            else {
2225                                    return (MBMessage)result;
2226                            }
2227                    }
2228            }
2229    
2230            /**
2231             * Returns all the message-boards messages where groupId = &#63;.
2232             *
2233             * @param groupId the group ID
2234             * @return the matching message-boards messages
2235             * @throws SystemException if a system exception occurred
2236             */
2237            public List<MBMessage> findByGroupId(long groupId)
2238                    throws SystemException {
2239                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2240            }
2241    
2242            /**
2243             * Returns a range of all the message-boards messages where groupId = &#63;.
2244             *
2245             * <p>
2246             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2247             * </p>
2248             *
2249             * @param groupId the group ID
2250             * @param start the lower bound of the range of message-boards messages
2251             * @param end the upper bound of the range of message-boards messages (not inclusive)
2252             * @return the range of matching message-boards messages
2253             * @throws SystemException if a system exception occurred
2254             */
2255            public List<MBMessage> findByGroupId(long groupId, int start, int end)
2256                    throws SystemException {
2257                    return findByGroupId(groupId, start, end, null);
2258            }
2259    
2260            /**
2261             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
2262             *
2263             * <p>
2264             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2265             * </p>
2266             *
2267             * @param groupId the group ID
2268             * @param start the lower bound of the range of message-boards messages
2269             * @param end the upper bound of the range of message-boards messages (not inclusive)
2270             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2271             * @return the ordered range of matching message-boards messages
2272             * @throws SystemException if a system exception occurred
2273             */
2274            public List<MBMessage> findByGroupId(long groupId, int start, int end,
2275                    OrderByComparator orderByComparator) throws SystemException {
2276                    FinderPath finderPath = null;
2277                    Object[] finderArgs = null;
2278    
2279                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2280                                    (orderByComparator == null)) {
2281                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2282                            finderArgs = new Object[] { groupId };
2283                    }
2284                    else {
2285                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2286                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2287                    }
2288    
2289                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2290                                    finderArgs, this);
2291    
2292                    if ((list != null) && !list.isEmpty()) {
2293                            for (MBMessage mbMessage : list) {
2294                                    if ((groupId != mbMessage.getGroupId())) {
2295                                            list = null;
2296    
2297                                            break;
2298                                    }
2299                            }
2300                    }
2301    
2302                    if (list == null) {
2303                            StringBundler query = null;
2304    
2305                            if (orderByComparator != null) {
2306                                    query = new StringBundler(3 +
2307                                                    (orderByComparator.getOrderByFields().length * 3));
2308                            }
2309                            else {
2310                                    query = new StringBundler(3);
2311                            }
2312    
2313                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2314    
2315                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2316    
2317                            if (orderByComparator != null) {
2318                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2319                                            orderByComparator);
2320                            }
2321    
2322                            else {
2323                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2324                            }
2325    
2326                            String sql = query.toString();
2327    
2328                            Session session = null;
2329    
2330                            try {
2331                                    session = openSession();
2332    
2333                                    Query q = session.createQuery(sql);
2334    
2335                                    QueryPos qPos = QueryPos.getInstance(q);
2336    
2337                                    qPos.add(groupId);
2338    
2339                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2340                                                    end);
2341                            }
2342                            catch (Exception e) {
2343                                    throw processException(e);
2344                            }
2345                            finally {
2346                                    if (list == null) {
2347                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2348                                    }
2349                                    else {
2350                                            cacheResult(list);
2351    
2352                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2353                                    }
2354    
2355                                    closeSession(session);
2356                            }
2357                    }
2358    
2359                    return list;
2360            }
2361    
2362            /**
2363             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2364             *
2365             * @param groupId the group ID
2366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2367             * @return the first matching message-boards message
2368             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2369             * @throws SystemException if a system exception occurred
2370             */
2371            public MBMessage findByGroupId_First(long groupId,
2372                    OrderByComparator orderByComparator)
2373                    throws NoSuchMessageException, SystemException {
2374                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
2375    
2376                    if (mbMessage != null) {
2377                            return mbMessage;
2378                    }
2379    
2380                    StringBundler msg = new StringBundler(4);
2381    
2382                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2383    
2384                    msg.append("groupId=");
2385                    msg.append(groupId);
2386    
2387                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2388    
2389                    throw new NoSuchMessageException(msg.toString());
2390            }
2391    
2392            /**
2393             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2394             *
2395             * @param groupId the group ID
2396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2397             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2398             * @throws SystemException if a system exception occurred
2399             */
2400            public MBMessage fetchByGroupId_First(long groupId,
2401                    OrderByComparator orderByComparator) throws SystemException {
2402                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
2403    
2404                    if (!list.isEmpty()) {
2405                            return list.get(0);
2406                    }
2407    
2408                    return null;
2409            }
2410    
2411            /**
2412             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2413             *
2414             * @param groupId the group ID
2415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2416             * @return the last matching message-boards message
2417             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2418             * @throws SystemException if a system exception occurred
2419             */
2420            public MBMessage findByGroupId_Last(long groupId,
2421                    OrderByComparator orderByComparator)
2422                    throws NoSuchMessageException, SystemException {
2423                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
2424    
2425                    if (mbMessage != null) {
2426                            return mbMessage;
2427                    }
2428    
2429                    StringBundler msg = new StringBundler(4);
2430    
2431                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2432    
2433                    msg.append("groupId=");
2434                    msg.append(groupId);
2435    
2436                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2437    
2438                    throw new NoSuchMessageException(msg.toString());
2439            }
2440    
2441            /**
2442             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2443             *
2444             * @param groupId the group ID
2445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2446             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2447             * @throws SystemException if a system exception occurred
2448             */
2449            public MBMessage fetchByGroupId_Last(long groupId,
2450                    OrderByComparator orderByComparator) throws SystemException {
2451                    int count = countByGroupId(groupId);
2452    
2453                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
2454                                    orderByComparator);
2455    
2456                    if (!list.isEmpty()) {
2457                            return list.get(0);
2458                    }
2459    
2460                    return null;
2461            }
2462    
2463            /**
2464             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
2465             *
2466             * @param messageId the primary key of the current message-boards message
2467             * @param groupId the group ID
2468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2469             * @return the previous, current, and next message-boards message
2470             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2471             * @throws SystemException if a system exception occurred
2472             */
2473            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
2474                    OrderByComparator orderByComparator)
2475                    throws NoSuchMessageException, SystemException {
2476                    MBMessage mbMessage = findByPrimaryKey(messageId);
2477    
2478                    Session session = null;
2479    
2480                    try {
2481                            session = openSession();
2482    
2483                            MBMessage[] array = new MBMessageImpl[3];
2484    
2485                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2486                                            orderByComparator, true);
2487    
2488                            array[1] = mbMessage;
2489    
2490                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2491                                            orderByComparator, false);
2492    
2493                            return array;
2494                    }
2495                    catch (Exception e) {
2496                            throw processException(e);
2497                    }
2498                    finally {
2499                            closeSession(session);
2500                    }
2501            }
2502    
2503            protected MBMessage getByGroupId_PrevAndNext(Session session,
2504                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2505                    boolean previous) {
2506                    StringBundler query = null;
2507    
2508                    if (orderByComparator != null) {
2509                            query = new StringBundler(6 +
2510                                            (orderByComparator.getOrderByFields().length * 6));
2511                    }
2512                    else {
2513                            query = new StringBundler(3);
2514                    }
2515    
2516                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2517    
2518                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2519    
2520                    if (orderByComparator != null) {
2521                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2522    
2523                            if (orderByConditionFields.length > 0) {
2524                                    query.append(WHERE_AND);
2525                            }
2526    
2527                            for (int i = 0; i < orderByConditionFields.length; i++) {
2528                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2529                                    query.append(orderByConditionFields[i]);
2530    
2531                                    if ((i + 1) < orderByConditionFields.length) {
2532                                            if (orderByComparator.isAscending() ^ previous) {
2533                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2534                                            }
2535                                            else {
2536                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2537                                            }
2538                                    }
2539                                    else {
2540                                            if (orderByComparator.isAscending() ^ previous) {
2541                                                    query.append(WHERE_GREATER_THAN);
2542                                            }
2543                                            else {
2544                                                    query.append(WHERE_LESSER_THAN);
2545                                            }
2546                                    }
2547                            }
2548    
2549                            query.append(ORDER_BY_CLAUSE);
2550    
2551                            String[] orderByFields = orderByComparator.getOrderByFields();
2552    
2553                            for (int i = 0; i < orderByFields.length; i++) {
2554                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2555                                    query.append(orderByFields[i]);
2556    
2557                                    if ((i + 1) < orderByFields.length) {
2558                                            if (orderByComparator.isAscending() ^ previous) {
2559                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2560                                            }
2561                                            else {
2562                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2563                                            }
2564                                    }
2565                                    else {
2566                                            if (orderByComparator.isAscending() ^ previous) {
2567                                                    query.append(ORDER_BY_ASC);
2568                                            }
2569                                            else {
2570                                                    query.append(ORDER_BY_DESC);
2571                                            }
2572                                    }
2573                            }
2574                    }
2575    
2576                    else {
2577                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2578                    }
2579    
2580                    String sql = query.toString();
2581    
2582                    Query q = session.createQuery(sql);
2583    
2584                    q.setFirstResult(0);
2585                    q.setMaxResults(2);
2586    
2587                    QueryPos qPos = QueryPos.getInstance(q);
2588    
2589                    qPos.add(groupId);
2590    
2591                    if (orderByComparator != null) {
2592                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2593    
2594                            for (Object value : values) {
2595                                    qPos.add(value);
2596                            }
2597                    }
2598    
2599                    List<MBMessage> list = q.list();
2600    
2601                    if (list.size() == 2) {
2602                            return list.get(1);
2603                    }
2604                    else {
2605                            return null;
2606                    }
2607            }
2608    
2609            /**
2610             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
2611             *
2612             * @param groupId the group ID
2613             * @return the matching message-boards messages that the user has permission to view
2614             * @throws SystemException if a system exception occurred
2615             */
2616            public List<MBMessage> filterFindByGroupId(long groupId)
2617                    throws SystemException {
2618                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2619                            QueryUtil.ALL_POS, null);
2620            }
2621    
2622            /**
2623             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
2624             *
2625             * <p>
2626             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2627             * </p>
2628             *
2629             * @param groupId the group ID
2630             * @param start the lower bound of the range of message-boards messages
2631             * @param end the upper bound of the range of message-boards messages (not inclusive)
2632             * @return the range of matching message-boards messages that the user has permission to view
2633             * @throws SystemException if a system exception occurred
2634             */
2635            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
2636                    throws SystemException {
2637                    return filterFindByGroupId(groupId, start, end, null);
2638            }
2639    
2640            /**
2641             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
2642             *
2643             * <p>
2644             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2645             * </p>
2646             *
2647             * @param groupId the group ID
2648             * @param start the lower bound of the range of message-boards messages
2649             * @param end the upper bound of the range of message-boards messages (not inclusive)
2650             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2651             * @return the ordered range of matching message-boards messages that the user has permission to view
2652             * @throws SystemException if a system exception occurred
2653             */
2654            public List<MBMessage> filterFindByGroupId(long groupId, int start,
2655                    int end, OrderByComparator orderByComparator) throws SystemException {
2656                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2657                            return findByGroupId(groupId, start, end, orderByComparator);
2658                    }
2659    
2660                    StringBundler query = null;
2661    
2662                    if (orderByComparator != null) {
2663                            query = new StringBundler(3 +
2664                                            (orderByComparator.getOrderByFields().length * 3));
2665                    }
2666                    else {
2667                            query = new StringBundler(3);
2668                    }
2669    
2670                    if (getDB().isSupportsInlineDistinct()) {
2671                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2672                    }
2673                    else {
2674                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2675                    }
2676    
2677                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2678    
2679                    if (!getDB().isSupportsInlineDistinct()) {
2680                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2681                    }
2682    
2683                    if (orderByComparator != null) {
2684                            if (getDB().isSupportsInlineDistinct()) {
2685                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2686                                            orderByComparator);
2687                            }
2688                            else {
2689                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2690                                            orderByComparator);
2691                            }
2692                    }
2693    
2694                    else {
2695                            if (getDB().isSupportsInlineDistinct()) {
2696                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2697                            }
2698                            else {
2699                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2700                            }
2701                    }
2702    
2703                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2704                                    MBMessage.class.getName(),
2705                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2706    
2707                    Session session = null;
2708    
2709                    try {
2710                            session = openSession();
2711    
2712                            SQLQuery q = session.createSQLQuery(sql);
2713    
2714                            if (getDB().isSupportsInlineDistinct()) {
2715                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2716                            }
2717                            else {
2718                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2719                            }
2720    
2721                            QueryPos qPos = QueryPos.getInstance(q);
2722    
2723                            qPos.add(groupId);
2724    
2725                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2726                    }
2727                    catch (Exception e) {
2728                            throw processException(e);
2729                    }
2730                    finally {
2731                            closeSession(session);
2732                    }
2733            }
2734    
2735            /**
2736             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63;.
2737             *
2738             * @param messageId the primary key of the current message-boards message
2739             * @param groupId the group ID
2740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2741             * @return the previous, current, and next message-boards message
2742             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2743             * @throws SystemException if a system exception occurred
2744             */
2745            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2746                    long groupId, OrderByComparator orderByComparator)
2747                    throws NoSuchMessageException, SystemException {
2748                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2749                            return findByGroupId_PrevAndNext(messageId, groupId,
2750                                    orderByComparator);
2751                    }
2752    
2753                    MBMessage mbMessage = findByPrimaryKey(messageId);
2754    
2755                    Session session = null;
2756    
2757                    try {
2758                            session = openSession();
2759    
2760                            MBMessage[] array = new MBMessageImpl[3];
2761    
2762                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2763                                            groupId, orderByComparator, true);
2764    
2765                            array[1] = mbMessage;
2766    
2767                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2768                                            groupId, orderByComparator, false);
2769    
2770                            return array;
2771                    }
2772                    catch (Exception e) {
2773                            throw processException(e);
2774                    }
2775                    finally {
2776                            closeSession(session);
2777                    }
2778            }
2779    
2780            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2781                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2782                    boolean previous) {
2783                    StringBundler query = null;
2784    
2785                    if (orderByComparator != null) {
2786                            query = new StringBundler(6 +
2787                                            (orderByComparator.getOrderByFields().length * 6));
2788                    }
2789                    else {
2790                            query = new StringBundler(3);
2791                    }
2792    
2793                    if (getDB().isSupportsInlineDistinct()) {
2794                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2795                    }
2796                    else {
2797                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2798                    }
2799    
2800                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2801    
2802                    if (!getDB().isSupportsInlineDistinct()) {
2803                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2804                    }
2805    
2806                    if (orderByComparator != null) {
2807                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2808    
2809                            if (orderByConditionFields.length > 0) {
2810                                    query.append(WHERE_AND);
2811                            }
2812    
2813                            for (int i = 0; i < orderByConditionFields.length; i++) {
2814                                    if (getDB().isSupportsInlineDistinct()) {
2815                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2816                                    }
2817                                    else {
2818                                            query.append(_ORDER_BY_ENTITY_TABLE);
2819                                    }
2820    
2821                                    query.append(orderByConditionFields[i]);
2822    
2823                                    if ((i + 1) < orderByConditionFields.length) {
2824                                            if (orderByComparator.isAscending() ^ previous) {
2825                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2826                                            }
2827                                            else {
2828                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2829                                            }
2830                                    }
2831                                    else {
2832                                            if (orderByComparator.isAscending() ^ previous) {
2833                                                    query.append(WHERE_GREATER_THAN);
2834                                            }
2835                                            else {
2836                                                    query.append(WHERE_LESSER_THAN);
2837                                            }
2838                                    }
2839                            }
2840    
2841                            query.append(ORDER_BY_CLAUSE);
2842    
2843                            String[] orderByFields = orderByComparator.getOrderByFields();
2844    
2845                            for (int i = 0; i < orderByFields.length; i++) {
2846                                    if (getDB().isSupportsInlineDistinct()) {
2847                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2848                                    }
2849                                    else {
2850                                            query.append(_ORDER_BY_ENTITY_TABLE);
2851                                    }
2852    
2853                                    query.append(orderByFields[i]);
2854    
2855                                    if ((i + 1) < orderByFields.length) {
2856                                            if (orderByComparator.isAscending() ^ previous) {
2857                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2858                                            }
2859                                            else {
2860                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2861                                            }
2862                                    }
2863                                    else {
2864                                            if (orderByComparator.isAscending() ^ previous) {
2865                                                    query.append(ORDER_BY_ASC);
2866                                            }
2867                                            else {
2868                                                    query.append(ORDER_BY_DESC);
2869                                            }
2870                                    }
2871                            }
2872                    }
2873    
2874                    else {
2875                            if (getDB().isSupportsInlineDistinct()) {
2876                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2877                            }
2878                            else {
2879                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2880                            }
2881                    }
2882    
2883                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2884                                    MBMessage.class.getName(),
2885                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2886    
2887                    SQLQuery q = session.createSQLQuery(sql);
2888    
2889                    q.setFirstResult(0);
2890                    q.setMaxResults(2);
2891    
2892                    if (getDB().isSupportsInlineDistinct()) {
2893                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2894                    }
2895                    else {
2896                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2897                    }
2898    
2899                    QueryPos qPos = QueryPos.getInstance(q);
2900    
2901                    qPos.add(groupId);
2902    
2903                    if (orderByComparator != null) {
2904                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2905    
2906                            for (Object value : values) {
2907                                    qPos.add(value);
2908                            }
2909                    }
2910    
2911                    List<MBMessage> list = q.list();
2912    
2913                    if (list.size() == 2) {
2914                            return list.get(1);
2915                    }
2916                    else {
2917                            return null;
2918                    }
2919            }
2920    
2921            /**
2922             * Returns all the message-boards messages where companyId = &#63;.
2923             *
2924             * @param companyId the company ID
2925             * @return the matching message-boards messages
2926             * @throws SystemException if a system exception occurred
2927             */
2928            public List<MBMessage> findByCompanyId(long companyId)
2929                    throws SystemException {
2930                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2931                            null);
2932            }
2933    
2934            /**
2935             * Returns a range of all the message-boards messages where companyId = &#63;.
2936             *
2937             * <p>
2938             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2939             * </p>
2940             *
2941             * @param companyId the company ID
2942             * @param start the lower bound of the range of message-boards messages
2943             * @param end the upper bound of the range of message-boards messages (not inclusive)
2944             * @return the range of matching message-boards messages
2945             * @throws SystemException if a system exception occurred
2946             */
2947            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2948                    throws SystemException {
2949                    return findByCompanyId(companyId, start, end, null);
2950            }
2951    
2952            /**
2953             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2954             *
2955             * <p>
2956             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2957             * </p>
2958             *
2959             * @param companyId the company ID
2960             * @param start the lower bound of the range of message-boards messages
2961             * @param end the upper bound of the range of message-boards messages (not inclusive)
2962             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2963             * @return the ordered range of matching message-boards messages
2964             * @throws SystemException if a system exception occurred
2965             */
2966            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2967                    OrderByComparator orderByComparator) throws SystemException {
2968                    FinderPath finderPath = null;
2969                    Object[] finderArgs = null;
2970    
2971                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2972                                    (orderByComparator == null)) {
2973                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2974                            finderArgs = new Object[] { companyId };
2975                    }
2976                    else {
2977                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2978                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2979                    }
2980    
2981                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2982                                    finderArgs, this);
2983    
2984                    if ((list != null) && !list.isEmpty()) {
2985                            for (MBMessage mbMessage : list) {
2986                                    if ((companyId != mbMessage.getCompanyId())) {
2987                                            list = null;
2988    
2989                                            break;
2990                                    }
2991                            }
2992                    }
2993    
2994                    if (list == null) {
2995                            StringBundler query = null;
2996    
2997                            if (orderByComparator != null) {
2998                                    query = new StringBundler(3 +
2999                                                    (orderByComparator.getOrderByFields().length * 3));
3000                            }
3001                            else {
3002                                    query = new StringBundler(3);
3003                            }
3004    
3005                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3006    
3007                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3008    
3009                            if (orderByComparator != null) {
3010                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3011                                            orderByComparator);
3012                            }
3013    
3014                            else {
3015                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3016                            }
3017    
3018                            String sql = query.toString();
3019    
3020                            Session session = null;
3021    
3022                            try {
3023                                    session = openSession();
3024    
3025                                    Query q = session.createQuery(sql);
3026    
3027                                    QueryPos qPos = QueryPos.getInstance(q);
3028    
3029                                    qPos.add(companyId);
3030    
3031                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3032                                                    end);
3033                            }
3034                            catch (Exception e) {
3035                                    throw processException(e);
3036                            }
3037                            finally {
3038                                    if (list == null) {
3039                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3040                                    }
3041                                    else {
3042                                            cacheResult(list);
3043    
3044                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3045                                    }
3046    
3047                                    closeSession(session);
3048                            }
3049                    }
3050    
3051                    return list;
3052            }
3053    
3054            /**
3055             * Returns the first message-boards message in the ordered set where companyId = &#63;.
3056             *
3057             * @param companyId the company ID
3058             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3059             * @return the first matching message-boards message
3060             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3061             * @throws SystemException if a system exception occurred
3062             */
3063            public MBMessage findByCompanyId_First(long companyId,
3064                    OrderByComparator orderByComparator)
3065                    throws NoSuchMessageException, SystemException {
3066                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
3067                                    orderByComparator);
3068    
3069                    if (mbMessage != null) {
3070                            return mbMessage;
3071                    }
3072    
3073                    StringBundler msg = new StringBundler(4);
3074    
3075                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3076    
3077                    msg.append("companyId=");
3078                    msg.append(companyId);
3079    
3080                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3081    
3082                    throw new NoSuchMessageException(msg.toString());
3083            }
3084    
3085            /**
3086             * Returns the first message-boards message in the ordered set where companyId = &#63;.
3087             *
3088             * @param companyId the company ID
3089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3090             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3091             * @throws SystemException if a system exception occurred
3092             */
3093            public MBMessage fetchByCompanyId_First(long companyId,
3094                    OrderByComparator orderByComparator) throws SystemException {
3095                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
3096                                    orderByComparator);
3097    
3098                    if (!list.isEmpty()) {
3099                            return list.get(0);
3100                    }
3101    
3102                    return null;
3103            }
3104    
3105            /**
3106             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3107             *
3108             * @param companyId the company ID
3109             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3110             * @return the last matching message-boards message
3111             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3112             * @throws SystemException if a system exception occurred
3113             */
3114            public MBMessage findByCompanyId_Last(long companyId,
3115                    OrderByComparator orderByComparator)
3116                    throws NoSuchMessageException, SystemException {
3117                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
3118    
3119                    if (mbMessage != null) {
3120                            return mbMessage;
3121                    }
3122    
3123                    StringBundler msg = new StringBundler(4);
3124    
3125                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3126    
3127                    msg.append("companyId=");
3128                    msg.append(companyId);
3129    
3130                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3131    
3132                    throw new NoSuchMessageException(msg.toString());
3133            }
3134    
3135            /**
3136             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3137             *
3138             * @param companyId the company ID
3139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3140             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3141             * @throws SystemException if a system exception occurred
3142             */
3143            public MBMessage fetchByCompanyId_Last(long companyId,
3144                    OrderByComparator orderByComparator) throws SystemException {
3145                    int count = countByCompanyId(companyId);
3146    
3147                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
3148                                    orderByComparator);
3149    
3150                    if (!list.isEmpty()) {
3151                            return list.get(0);
3152                    }
3153    
3154                    return null;
3155            }
3156    
3157            /**
3158             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
3159             *
3160             * @param messageId the primary key of the current message-boards message
3161             * @param companyId the company ID
3162             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3163             * @return the previous, current, and next message-boards message
3164             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3165             * @throws SystemException if a system exception occurred
3166             */
3167            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
3168                    long companyId, OrderByComparator orderByComparator)
3169                    throws NoSuchMessageException, SystemException {
3170                    MBMessage mbMessage = findByPrimaryKey(messageId);
3171    
3172                    Session session = null;
3173    
3174                    try {
3175                            session = openSession();
3176    
3177                            MBMessage[] array = new MBMessageImpl[3];
3178    
3179                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
3180                                            companyId, orderByComparator, true);
3181    
3182                            array[1] = mbMessage;
3183    
3184                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
3185                                            companyId, orderByComparator, false);
3186    
3187                            return array;
3188                    }
3189                    catch (Exception e) {
3190                            throw processException(e);
3191                    }
3192                    finally {
3193                            closeSession(session);
3194                    }
3195            }
3196    
3197            protected MBMessage getByCompanyId_PrevAndNext(Session session,
3198                    MBMessage mbMessage, long companyId,
3199                    OrderByComparator orderByComparator, boolean previous) {
3200                    StringBundler query = null;
3201    
3202                    if (orderByComparator != null) {
3203                            query = new StringBundler(6 +
3204                                            (orderByComparator.getOrderByFields().length * 6));
3205                    }
3206                    else {
3207                            query = new StringBundler(3);
3208                    }
3209    
3210                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3211    
3212                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3213    
3214                    if (orderByComparator != null) {
3215                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3216    
3217                            if (orderByConditionFields.length > 0) {
3218                                    query.append(WHERE_AND);
3219                            }
3220    
3221                            for (int i = 0; i < orderByConditionFields.length; i++) {
3222                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3223                                    query.append(orderByConditionFields[i]);
3224    
3225                                    if ((i + 1) < orderByConditionFields.length) {
3226                                            if (orderByComparator.isAscending() ^ previous) {
3227                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3228                                            }
3229                                            else {
3230                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3231                                            }
3232                                    }
3233                                    else {
3234                                            if (orderByComparator.isAscending() ^ previous) {
3235                                                    query.append(WHERE_GREATER_THAN);
3236                                            }
3237                                            else {
3238                                                    query.append(WHERE_LESSER_THAN);
3239                                            }
3240                                    }
3241                            }
3242    
3243                            query.append(ORDER_BY_CLAUSE);
3244    
3245                            String[] orderByFields = orderByComparator.getOrderByFields();
3246    
3247                            for (int i = 0; i < orderByFields.length; i++) {
3248                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3249                                    query.append(orderByFields[i]);
3250    
3251                                    if ((i + 1) < orderByFields.length) {
3252                                            if (orderByComparator.isAscending() ^ previous) {
3253                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3254                                            }
3255                                            else {
3256                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3257                                            }
3258                                    }
3259                                    else {
3260                                            if (orderByComparator.isAscending() ^ previous) {
3261                                                    query.append(ORDER_BY_ASC);
3262                                            }
3263                                            else {
3264                                                    query.append(ORDER_BY_DESC);
3265                                            }
3266                                    }
3267                            }
3268                    }
3269    
3270                    else {
3271                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3272                    }
3273    
3274                    String sql = query.toString();
3275    
3276                    Query q = session.createQuery(sql);
3277    
3278                    q.setFirstResult(0);
3279                    q.setMaxResults(2);
3280    
3281                    QueryPos qPos = QueryPos.getInstance(q);
3282    
3283                    qPos.add(companyId);
3284    
3285                    if (orderByComparator != null) {
3286                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3287    
3288                            for (Object value : values) {
3289                                    qPos.add(value);
3290                            }
3291                    }
3292    
3293                    List<MBMessage> list = q.list();
3294    
3295                    if (list.size() == 2) {
3296                            return list.get(1);
3297                    }
3298                    else {
3299                            return null;
3300                    }
3301            }
3302    
3303            /**
3304             * Returns all the message-boards messages where threadId = &#63;.
3305             *
3306             * @param threadId the thread ID
3307             * @return the matching message-boards messages
3308             * @throws SystemException if a system exception occurred
3309             */
3310            public List<MBMessage> findByThreadId(long threadId)
3311                    throws SystemException {
3312                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3313                            null);
3314            }
3315    
3316            /**
3317             * Returns a range of all the message-boards messages where threadId = &#63;.
3318             *
3319             * <p>
3320             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3321             * </p>
3322             *
3323             * @param threadId the thread ID
3324             * @param start the lower bound of the range of message-boards messages
3325             * @param end the upper bound of the range of message-boards messages (not inclusive)
3326             * @return the range of matching message-boards messages
3327             * @throws SystemException if a system exception occurred
3328             */
3329            public List<MBMessage> findByThreadId(long threadId, int start, int end)
3330                    throws SystemException {
3331                    return findByThreadId(threadId, start, end, null);
3332            }
3333    
3334            /**
3335             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3336             *
3337             * <p>
3338             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3339             * </p>
3340             *
3341             * @param threadId the thread ID
3342             * @param start the lower bound of the range of message-boards messages
3343             * @param end the upper bound of the range of message-boards messages (not inclusive)
3344             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3345             * @return the ordered range of matching message-boards messages
3346             * @throws SystemException if a system exception occurred
3347             */
3348            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3349                    OrderByComparator orderByComparator) throws SystemException {
3350                    FinderPath finderPath = null;
3351                    Object[] finderArgs = null;
3352    
3353                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3354                                    (orderByComparator == null)) {
3355                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3356                            finderArgs = new Object[] { threadId };
3357                    }
3358                    else {
3359                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3360                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3361                    }
3362    
3363                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3364                                    finderArgs, this);
3365    
3366                    if ((list != null) && !list.isEmpty()) {
3367                            for (MBMessage mbMessage : list) {
3368                                    if ((threadId != mbMessage.getThreadId())) {
3369                                            list = null;
3370    
3371                                            break;
3372                                    }
3373                            }
3374                    }
3375    
3376                    if (list == null) {
3377                            StringBundler query = null;
3378    
3379                            if (orderByComparator != null) {
3380                                    query = new StringBundler(3 +
3381                                                    (orderByComparator.getOrderByFields().length * 3));
3382                            }
3383                            else {
3384                                    query = new StringBundler(3);
3385                            }
3386    
3387                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3388    
3389                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3390    
3391                            if (orderByComparator != null) {
3392                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3393                                            orderByComparator);
3394                            }
3395    
3396                            else {
3397                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3398                            }
3399    
3400                            String sql = query.toString();
3401    
3402                            Session session = null;
3403    
3404                            try {
3405                                    session = openSession();
3406    
3407                                    Query q = session.createQuery(sql);
3408    
3409                                    QueryPos qPos = QueryPos.getInstance(q);
3410    
3411                                    qPos.add(threadId);
3412    
3413                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3414                                                    end);
3415                            }
3416                            catch (Exception e) {
3417                                    throw processException(e);
3418                            }
3419                            finally {
3420                                    if (list == null) {
3421                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3422                                    }
3423                                    else {
3424                                            cacheResult(list);
3425    
3426                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3427                                    }
3428    
3429                                    closeSession(session);
3430                            }
3431                    }
3432    
3433                    return list;
3434            }
3435    
3436            /**
3437             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3438             *
3439             * @param threadId the thread ID
3440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3441             * @return the first matching message-boards message
3442             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3443             * @throws SystemException if a system exception occurred
3444             */
3445            public MBMessage findByThreadId_First(long threadId,
3446                    OrderByComparator orderByComparator)
3447                    throws NoSuchMessageException, SystemException {
3448                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3449    
3450                    if (mbMessage != null) {
3451                            return mbMessage;
3452                    }
3453    
3454                    StringBundler msg = new StringBundler(4);
3455    
3456                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3457    
3458                    msg.append("threadId=");
3459                    msg.append(threadId);
3460    
3461                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3462    
3463                    throw new NoSuchMessageException(msg.toString());
3464            }
3465    
3466            /**
3467             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3468             *
3469             * @param threadId the thread ID
3470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3471             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3472             * @throws SystemException if a system exception occurred
3473             */
3474            public MBMessage fetchByThreadId_First(long threadId,
3475                    OrderByComparator orderByComparator) throws SystemException {
3476                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3477    
3478                    if (!list.isEmpty()) {
3479                            return list.get(0);
3480                    }
3481    
3482                    return null;
3483            }
3484    
3485            /**
3486             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3487             *
3488             * @param threadId the thread ID
3489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3490             * @return the last matching message-boards message
3491             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3492             * @throws SystemException if a system exception occurred
3493             */
3494            public MBMessage findByThreadId_Last(long threadId,
3495                    OrderByComparator orderByComparator)
3496                    throws NoSuchMessageException, SystemException {
3497                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3498    
3499                    if (mbMessage != null) {
3500                            return mbMessage;
3501                    }
3502    
3503                    StringBundler msg = new StringBundler(4);
3504    
3505                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3506    
3507                    msg.append("threadId=");
3508                    msg.append(threadId);
3509    
3510                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3511    
3512                    throw new NoSuchMessageException(msg.toString());
3513            }
3514    
3515            /**
3516             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3517             *
3518             * @param threadId the thread ID
3519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3520             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3521             * @throws SystemException if a system exception occurred
3522             */
3523            public MBMessage fetchByThreadId_Last(long threadId,
3524                    OrderByComparator orderByComparator) throws SystemException {
3525                    int count = countByThreadId(threadId);
3526    
3527                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3528                                    orderByComparator);
3529    
3530                    if (!list.isEmpty()) {
3531                            return list.get(0);
3532                    }
3533    
3534                    return null;
3535            }
3536    
3537            /**
3538             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3539             *
3540             * @param messageId the primary key of the current message-boards message
3541             * @param threadId the thread ID
3542             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3543             * @return the previous, current, and next message-boards message
3544             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3545             * @throws SystemException if a system exception occurred
3546             */
3547            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3548                    long threadId, OrderByComparator orderByComparator)
3549                    throws NoSuchMessageException, SystemException {
3550                    MBMessage mbMessage = findByPrimaryKey(messageId);
3551    
3552                    Session session = null;
3553    
3554                    try {
3555                            session = openSession();
3556    
3557                            MBMessage[] array = new MBMessageImpl[3];
3558    
3559                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3560                                            orderByComparator, true);
3561    
3562                            array[1] = mbMessage;
3563    
3564                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3565                                            orderByComparator, false);
3566    
3567                            return array;
3568                    }
3569                    catch (Exception e) {
3570                            throw processException(e);
3571                    }
3572                    finally {
3573                            closeSession(session);
3574                    }
3575            }
3576    
3577            protected MBMessage getByThreadId_PrevAndNext(Session session,
3578                    MBMessage mbMessage, long threadId,
3579                    OrderByComparator orderByComparator, boolean previous) {
3580                    StringBundler query = null;
3581    
3582                    if (orderByComparator != null) {
3583                            query = new StringBundler(6 +
3584                                            (orderByComparator.getOrderByFields().length * 6));
3585                    }
3586                    else {
3587                            query = new StringBundler(3);
3588                    }
3589    
3590                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3591    
3592                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3593    
3594                    if (orderByComparator != null) {
3595                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3596    
3597                            if (orderByConditionFields.length > 0) {
3598                                    query.append(WHERE_AND);
3599                            }
3600    
3601                            for (int i = 0; i < orderByConditionFields.length; i++) {
3602                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3603                                    query.append(orderByConditionFields[i]);
3604    
3605                                    if ((i + 1) < orderByConditionFields.length) {
3606                                            if (orderByComparator.isAscending() ^ previous) {
3607                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3608                                            }
3609                                            else {
3610                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3611                                            }
3612                                    }
3613                                    else {
3614                                            if (orderByComparator.isAscending() ^ previous) {
3615                                                    query.append(WHERE_GREATER_THAN);
3616                                            }
3617                                            else {
3618                                                    query.append(WHERE_LESSER_THAN);
3619                                            }
3620                                    }
3621                            }
3622    
3623                            query.append(ORDER_BY_CLAUSE);
3624    
3625                            String[] orderByFields = orderByComparator.getOrderByFields();
3626    
3627                            for (int i = 0; i < orderByFields.length; i++) {
3628                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3629                                    query.append(orderByFields[i]);
3630    
3631                                    if ((i + 1) < orderByFields.length) {
3632                                            if (orderByComparator.isAscending() ^ previous) {
3633                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3634                                            }
3635                                            else {
3636                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3637                                            }
3638                                    }
3639                                    else {
3640                                            if (orderByComparator.isAscending() ^ previous) {
3641                                                    query.append(ORDER_BY_ASC);
3642                                            }
3643                                            else {
3644                                                    query.append(ORDER_BY_DESC);
3645                                            }
3646                                    }
3647                            }
3648                    }
3649    
3650                    else {
3651                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3652                    }
3653    
3654                    String sql = query.toString();
3655    
3656                    Query q = session.createQuery(sql);
3657    
3658                    q.setFirstResult(0);
3659                    q.setMaxResults(2);
3660    
3661                    QueryPos qPos = QueryPos.getInstance(q);
3662    
3663                    qPos.add(threadId);
3664    
3665                    if (orderByComparator != null) {
3666                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3667    
3668                            for (Object value : values) {
3669                                    qPos.add(value);
3670                            }
3671                    }
3672    
3673                    List<MBMessage> list = q.list();
3674    
3675                    if (list.size() == 2) {
3676                            return list.get(1);
3677                    }
3678                    else {
3679                            return null;
3680                    }
3681            }
3682    
3683            /**
3684             * Returns all the message-boards messages where threadId = &#63;.
3685             *
3686             * @param threadId the thread ID
3687             * @return the matching message-boards messages
3688             * @throws SystemException if a system exception occurred
3689             */
3690            public List<MBMessage> findByThreadReplies(long threadId)
3691                    throws SystemException {
3692                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3693                            QueryUtil.ALL_POS, null);
3694            }
3695    
3696            /**
3697             * Returns a range of all the message-boards messages where threadId = &#63;.
3698             *
3699             * <p>
3700             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3701             * </p>
3702             *
3703             * @param threadId the thread ID
3704             * @param start the lower bound of the range of message-boards messages
3705             * @param end the upper bound of the range of message-boards messages (not inclusive)
3706             * @return the range of matching message-boards messages
3707             * @throws SystemException if a system exception occurred
3708             */
3709            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3710                    throws SystemException {
3711                    return findByThreadReplies(threadId, start, end, null);
3712            }
3713    
3714            /**
3715             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3716             *
3717             * <p>
3718             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3719             * </p>
3720             *
3721             * @param threadId the thread ID
3722             * @param start the lower bound of the range of message-boards messages
3723             * @param end the upper bound of the range of message-boards messages (not inclusive)
3724             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3725             * @return the ordered range of matching message-boards messages
3726             * @throws SystemException if a system exception occurred
3727             */
3728            public List<MBMessage> findByThreadReplies(long threadId, int start,
3729                    int end, OrderByComparator orderByComparator) throws SystemException {
3730                    FinderPath finderPath = null;
3731                    Object[] finderArgs = null;
3732    
3733                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3734                                    (orderByComparator == null)) {
3735                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3736                            finderArgs = new Object[] { threadId };
3737                    }
3738                    else {
3739                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3740                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3741                    }
3742    
3743                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3744                                    finderArgs, this);
3745    
3746                    if ((list != null) && !list.isEmpty()) {
3747                            for (MBMessage mbMessage : list) {
3748                                    if ((threadId != mbMessage.getThreadId())) {
3749                                            list = null;
3750    
3751                                            break;
3752                                    }
3753                            }
3754                    }
3755    
3756                    if (list == null) {
3757                            StringBundler query = null;
3758    
3759                            if (orderByComparator != null) {
3760                                    query = new StringBundler(3 +
3761                                                    (orderByComparator.getOrderByFields().length * 3));
3762                            }
3763                            else {
3764                                    query = new StringBundler(3);
3765                            }
3766    
3767                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3768    
3769                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3770    
3771                            if (orderByComparator != null) {
3772                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3773                                            orderByComparator);
3774                            }
3775    
3776                            else {
3777                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3778                            }
3779    
3780                            String sql = query.toString();
3781    
3782                            Session session = null;
3783    
3784                            try {
3785                                    session = openSession();
3786    
3787                                    Query q = session.createQuery(sql);
3788    
3789                                    QueryPos qPos = QueryPos.getInstance(q);
3790    
3791                                    qPos.add(threadId);
3792    
3793                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3794                                                    end);
3795                            }
3796                            catch (Exception e) {
3797                                    throw processException(e);
3798                            }
3799                            finally {
3800                                    if (list == null) {
3801                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3802                                    }
3803                                    else {
3804                                            cacheResult(list);
3805    
3806                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3807                                    }
3808    
3809                                    closeSession(session);
3810                            }
3811                    }
3812    
3813                    return list;
3814            }
3815    
3816            /**
3817             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3818             *
3819             * @param threadId the thread ID
3820             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3821             * @return the first matching message-boards message
3822             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3823             * @throws SystemException if a system exception occurred
3824             */
3825            public MBMessage findByThreadReplies_First(long threadId,
3826                    OrderByComparator orderByComparator)
3827                    throws NoSuchMessageException, SystemException {
3828                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3829                                    orderByComparator);
3830    
3831                    if (mbMessage != null) {
3832                            return mbMessage;
3833                    }
3834    
3835                    StringBundler msg = new StringBundler(4);
3836    
3837                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3838    
3839                    msg.append("threadId=");
3840                    msg.append(threadId);
3841    
3842                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3843    
3844                    throw new NoSuchMessageException(msg.toString());
3845            }
3846    
3847            /**
3848             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3849             *
3850             * @param threadId the thread ID
3851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3852             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3853             * @throws SystemException if a system exception occurred
3854             */
3855            public MBMessage fetchByThreadReplies_First(long threadId,
3856                    OrderByComparator orderByComparator) throws SystemException {
3857                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3858                                    orderByComparator);
3859    
3860                    if (!list.isEmpty()) {
3861                            return list.get(0);
3862                    }
3863    
3864                    return null;
3865            }
3866    
3867            /**
3868             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3869             *
3870             * @param threadId the thread ID
3871             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3872             * @return the last matching message-boards message
3873             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3874             * @throws SystemException if a system exception occurred
3875             */
3876            public MBMessage findByThreadReplies_Last(long threadId,
3877                    OrderByComparator orderByComparator)
3878                    throws NoSuchMessageException, SystemException {
3879                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3880                                    orderByComparator);
3881    
3882                    if (mbMessage != null) {
3883                            return mbMessage;
3884                    }
3885    
3886                    StringBundler msg = new StringBundler(4);
3887    
3888                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3889    
3890                    msg.append("threadId=");
3891                    msg.append(threadId);
3892    
3893                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3894    
3895                    throw new NoSuchMessageException(msg.toString());
3896            }
3897    
3898            /**
3899             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3900             *
3901             * @param threadId the thread ID
3902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3903             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3904             * @throws SystemException if a system exception occurred
3905             */
3906            public MBMessage fetchByThreadReplies_Last(long threadId,
3907                    OrderByComparator orderByComparator) throws SystemException {
3908                    int count = countByThreadReplies(threadId);
3909    
3910                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3911                                    orderByComparator);
3912    
3913                    if (!list.isEmpty()) {
3914                            return list.get(0);
3915                    }
3916    
3917                    return null;
3918            }
3919    
3920            /**
3921             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3922             *
3923             * @param messageId the primary key of the current message-boards message
3924             * @param threadId the thread ID
3925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3926             * @return the previous, current, and next message-boards message
3927             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3928             * @throws SystemException if a system exception occurred
3929             */
3930            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3931                    long threadId, OrderByComparator orderByComparator)
3932                    throws NoSuchMessageException, SystemException {
3933                    MBMessage mbMessage = findByPrimaryKey(messageId);
3934    
3935                    Session session = null;
3936    
3937                    try {
3938                            session = openSession();
3939    
3940                            MBMessage[] array = new MBMessageImpl[3];
3941    
3942                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3943                                            threadId, orderByComparator, true);
3944    
3945                            array[1] = mbMessage;
3946    
3947                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3948                                            threadId, orderByComparator, false);
3949    
3950                            return array;
3951                    }
3952                    catch (Exception e) {
3953                            throw processException(e);
3954                    }
3955                    finally {
3956                            closeSession(session);
3957                    }
3958            }
3959    
3960            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3961                    MBMessage mbMessage, long threadId,
3962                    OrderByComparator orderByComparator, boolean previous) {
3963                    StringBundler query = null;
3964    
3965                    if (orderByComparator != null) {
3966                            query = new StringBundler(6 +
3967                                            (orderByComparator.getOrderByFields().length * 6));
3968                    }
3969                    else {
3970                            query = new StringBundler(3);
3971                    }
3972    
3973                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3974    
3975                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3976    
3977                    if (orderByComparator != null) {
3978                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3979    
3980                            if (orderByConditionFields.length > 0) {
3981                                    query.append(WHERE_AND);
3982                            }
3983    
3984                            for (int i = 0; i < orderByConditionFields.length; i++) {
3985                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3986                                    query.append(orderByConditionFields[i]);
3987    
3988                                    if ((i + 1) < orderByConditionFields.length) {
3989                                            if (orderByComparator.isAscending() ^ previous) {
3990                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3991                                            }
3992                                            else {
3993                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3994                                            }
3995                                    }
3996                                    else {
3997                                            if (orderByComparator.isAscending() ^ previous) {
3998                                                    query.append(WHERE_GREATER_THAN);
3999                                            }
4000                                            else {
4001                                                    query.append(WHERE_LESSER_THAN);
4002                                            }
4003                                    }
4004                            }
4005    
4006                            query.append(ORDER_BY_CLAUSE);
4007    
4008                            String[] orderByFields = orderByComparator.getOrderByFields();
4009    
4010                            for (int i = 0; i < orderByFields.length; i++) {
4011                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4012                                    query.append(orderByFields[i]);
4013    
4014                                    if ((i + 1) < orderByFields.length) {
4015                                            if (orderByComparator.isAscending() ^ previous) {
4016                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4017                                            }
4018                                            else {
4019                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4020                                            }
4021                                    }
4022                                    else {
4023                                            if (orderByComparator.isAscending() ^ previous) {
4024                                                    query.append(ORDER_BY_ASC);
4025                                            }
4026                                            else {
4027                                                    query.append(ORDER_BY_DESC);
4028                                            }
4029                                    }
4030                            }
4031                    }
4032    
4033                    else {
4034                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4035                    }
4036    
4037                    String sql = query.toString();
4038    
4039                    Query q = session.createQuery(sql);
4040    
4041                    q.setFirstResult(0);
4042                    q.setMaxResults(2);
4043    
4044                    QueryPos qPos = QueryPos.getInstance(q);
4045    
4046                    qPos.add(threadId);
4047    
4048                    if (orderByComparator != null) {
4049                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4050    
4051                            for (Object value : values) {
4052                                    qPos.add(value);
4053                            }
4054                    }
4055    
4056                    List<MBMessage> list = q.list();
4057    
4058                    if (list.size() == 2) {
4059                            return list.get(1);
4060                    }
4061                    else {
4062                            return null;
4063                    }
4064            }
4065    
4066            /**
4067             * Returns all the message-boards messages where userId = &#63;.
4068             *
4069             * @param userId the user ID
4070             * @return the matching message-boards messages
4071             * @throws SystemException if a system exception occurred
4072             */
4073            public List<MBMessage> findByUserId(long userId) throws SystemException {
4074                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4075            }
4076    
4077            /**
4078             * Returns a range of all the message-boards messages where userId = &#63;.
4079             *
4080             * <p>
4081             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4082             * </p>
4083             *
4084             * @param userId the user ID
4085             * @param start the lower bound of the range of message-boards messages
4086             * @param end the upper bound of the range of message-boards messages (not inclusive)
4087             * @return the range of matching message-boards messages
4088             * @throws SystemException if a system exception occurred
4089             */
4090            public List<MBMessage> findByUserId(long userId, int start, int end)
4091                    throws SystemException {
4092                    return findByUserId(userId, start, end, null);
4093            }
4094    
4095            /**
4096             * Returns an ordered range of all the message-boards messages where userId = &#63;.
4097             *
4098             * <p>
4099             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4100             * </p>
4101             *
4102             * @param userId the user ID
4103             * @param start the lower bound of the range of message-boards messages
4104             * @param end the upper bound of the range of message-boards messages (not inclusive)
4105             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4106             * @return the ordered range of matching message-boards messages
4107             * @throws SystemException if a system exception occurred
4108             */
4109            public List<MBMessage> findByUserId(long userId, int start, int end,
4110                    OrderByComparator orderByComparator) throws SystemException {
4111                    FinderPath finderPath = null;
4112                    Object[] finderArgs = null;
4113    
4114                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4115                                    (orderByComparator == null)) {
4116                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
4117                            finderArgs = new Object[] { userId };
4118                    }
4119                    else {
4120                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
4121                            finderArgs = new Object[] { userId, start, end, orderByComparator };
4122                    }
4123    
4124                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4125                                    finderArgs, this);
4126    
4127                    if ((list != null) && !list.isEmpty()) {
4128                            for (MBMessage mbMessage : list) {
4129                                    if ((userId != mbMessage.getUserId())) {
4130                                            list = null;
4131    
4132                                            break;
4133                                    }
4134                            }
4135                    }
4136    
4137                    if (list == null) {
4138                            StringBundler query = null;
4139    
4140                            if (orderByComparator != null) {
4141                                    query = new StringBundler(3 +
4142                                                    (orderByComparator.getOrderByFields().length * 3));
4143                            }
4144                            else {
4145                                    query = new StringBundler(3);
4146                            }
4147    
4148                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4149    
4150                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4151    
4152                            if (orderByComparator != null) {
4153                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4154                                            orderByComparator);
4155                            }
4156    
4157                            else {
4158                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4159                            }
4160    
4161                            String sql = query.toString();
4162    
4163                            Session session = null;
4164    
4165                            try {
4166                                    session = openSession();
4167    
4168                                    Query q = session.createQuery(sql);
4169    
4170                                    QueryPos qPos = QueryPos.getInstance(q);
4171    
4172                                    qPos.add(userId);
4173    
4174                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4175                                                    end);
4176                            }
4177                            catch (Exception e) {
4178                                    throw processException(e);
4179                            }
4180                            finally {
4181                                    if (list == null) {
4182                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4183                                    }
4184                                    else {
4185                                            cacheResult(list);
4186    
4187                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4188                                    }
4189    
4190                                    closeSession(session);
4191                            }
4192                    }
4193    
4194                    return list;
4195            }
4196    
4197            /**
4198             * Returns the first message-boards message in the ordered set where userId = &#63;.
4199             *
4200             * @param userId the user ID
4201             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4202             * @return the first matching message-boards message
4203             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4204             * @throws SystemException if a system exception occurred
4205             */
4206            public MBMessage findByUserId_First(long userId,
4207                    OrderByComparator orderByComparator)
4208                    throws NoSuchMessageException, SystemException {
4209                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
4210    
4211                    if (mbMessage != null) {
4212                            return mbMessage;
4213                    }
4214    
4215                    StringBundler msg = new StringBundler(4);
4216    
4217                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4218    
4219                    msg.append("userId=");
4220                    msg.append(userId);
4221    
4222                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4223    
4224                    throw new NoSuchMessageException(msg.toString());
4225            }
4226    
4227            /**
4228             * Returns the first message-boards message in the ordered set where userId = &#63;.
4229             *
4230             * @param userId the user ID
4231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4232             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4233             * @throws SystemException if a system exception occurred
4234             */
4235            public MBMessage fetchByUserId_First(long userId,
4236                    OrderByComparator orderByComparator) throws SystemException {
4237                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
4238    
4239                    if (!list.isEmpty()) {
4240                            return list.get(0);
4241                    }
4242    
4243                    return null;
4244            }
4245    
4246            /**
4247             * Returns the last message-boards message in the ordered set where userId = &#63;.
4248             *
4249             * @param userId the user ID
4250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4251             * @return the last matching message-boards message
4252             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4253             * @throws SystemException if a system exception occurred
4254             */
4255            public MBMessage findByUserId_Last(long userId,
4256                    OrderByComparator orderByComparator)
4257                    throws NoSuchMessageException, SystemException {
4258                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
4259    
4260                    if (mbMessage != null) {
4261                            return mbMessage;
4262                    }
4263    
4264                    StringBundler msg = new StringBundler(4);
4265    
4266                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4267    
4268                    msg.append("userId=");
4269                    msg.append(userId);
4270    
4271                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4272    
4273                    throw new NoSuchMessageException(msg.toString());
4274            }
4275    
4276            /**
4277             * Returns the last message-boards message in the ordered set where userId = &#63;.
4278             *
4279             * @param userId the user ID
4280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4281             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4282             * @throws SystemException if a system exception occurred
4283             */
4284            public MBMessage fetchByUserId_Last(long userId,
4285                    OrderByComparator orderByComparator) throws SystemException {
4286                    int count = countByUserId(userId);
4287    
4288                    List<MBMessage> list = findByUserId(userId, count - 1, count,
4289                                    orderByComparator);
4290    
4291                    if (!list.isEmpty()) {
4292                            return list.get(0);
4293                    }
4294    
4295                    return null;
4296            }
4297    
4298            /**
4299             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
4300             *
4301             * @param messageId the primary key of the current message-boards message
4302             * @param userId the user ID
4303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4304             * @return the previous, current, and next message-boards message
4305             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4306             * @throws SystemException if a system exception occurred
4307             */
4308            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
4309                    OrderByComparator orderByComparator)
4310                    throws NoSuchMessageException, SystemException {
4311                    MBMessage mbMessage = findByPrimaryKey(messageId);
4312    
4313                    Session session = null;
4314    
4315                    try {
4316                            session = openSession();
4317    
4318                            MBMessage[] array = new MBMessageImpl[3];
4319    
4320                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
4321                                            orderByComparator, true);
4322    
4323                            array[1] = mbMessage;
4324    
4325                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
4326                                            orderByComparator, false);
4327    
4328                            return array;
4329                    }
4330                    catch (Exception e) {
4331                            throw processException(e);
4332                    }
4333                    finally {
4334                            closeSession(session);
4335                    }
4336            }
4337    
4338            protected MBMessage getByUserId_PrevAndNext(Session session,
4339                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
4340                    boolean previous) {
4341                    StringBundler query = null;
4342    
4343                    if (orderByComparator != null) {
4344                            query = new StringBundler(6 +
4345                                            (orderByComparator.getOrderByFields().length * 6));
4346                    }
4347                    else {
4348                            query = new StringBundler(3);
4349                    }
4350    
4351                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4352    
4353                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4354    
4355                    if (orderByComparator != null) {
4356                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4357    
4358                            if (orderByConditionFields.length > 0) {
4359                                    query.append(WHERE_AND);
4360                            }
4361    
4362                            for (int i = 0; i < orderByConditionFields.length; i++) {
4363                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4364                                    query.append(orderByConditionFields[i]);
4365    
4366                                    if ((i + 1) < orderByConditionFields.length) {
4367                                            if (orderByComparator.isAscending() ^ previous) {
4368                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4369                                            }
4370                                            else {
4371                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4372                                            }
4373                                    }
4374                                    else {
4375                                            if (orderByComparator.isAscending() ^ previous) {
4376                                                    query.append(WHERE_GREATER_THAN);
4377                                            }
4378                                            else {
4379                                                    query.append(WHERE_LESSER_THAN);
4380                                            }
4381                                    }
4382                            }
4383    
4384                            query.append(ORDER_BY_CLAUSE);
4385    
4386                            String[] orderByFields = orderByComparator.getOrderByFields();
4387    
4388                            for (int i = 0; i < orderByFields.length; i++) {
4389                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4390                                    query.append(orderByFields[i]);
4391    
4392                                    if ((i + 1) < orderByFields.length) {
4393                                            if (orderByComparator.isAscending() ^ previous) {
4394                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4395                                            }
4396                                            else {
4397                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4398                                            }
4399                                    }
4400                                    else {
4401                                            if (orderByComparator.isAscending() ^ previous) {
4402                                                    query.append(ORDER_BY_ASC);
4403                                            }
4404                                            else {
4405                                                    query.append(ORDER_BY_DESC);
4406                                            }
4407                                    }
4408                            }
4409                    }
4410    
4411                    else {
4412                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4413                    }
4414    
4415                    String sql = query.toString();
4416    
4417                    Query q = session.createQuery(sql);
4418    
4419                    q.setFirstResult(0);
4420                    q.setMaxResults(2);
4421    
4422                    QueryPos qPos = QueryPos.getInstance(q);
4423    
4424                    qPos.add(userId);
4425    
4426                    if (orderByComparator != null) {
4427                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4428    
4429                            for (Object value : values) {
4430                                    qPos.add(value);
4431                            }
4432                    }
4433    
4434                    List<MBMessage> list = q.list();
4435    
4436                    if (list.size() == 2) {
4437                            return list.get(1);
4438                    }
4439                    else {
4440                            return null;
4441                    }
4442            }
4443    
4444            /**
4445             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4446             *
4447             * @param groupId the group ID
4448             * @param userId the user ID
4449             * @return the matching message-boards messages
4450             * @throws SystemException if a system exception occurred
4451             */
4452            public List<MBMessage> findByG_U(long groupId, long userId)
4453                    throws SystemException {
4454                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4455                            null);
4456            }
4457    
4458            /**
4459             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4460             *
4461             * <p>
4462             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4463             * </p>
4464             *
4465             * @param groupId the group ID
4466             * @param userId the user ID
4467             * @param start the lower bound of the range of message-boards messages
4468             * @param end the upper bound of the range of message-boards messages (not inclusive)
4469             * @return the range of matching message-boards messages
4470             * @throws SystemException if a system exception occurred
4471             */
4472            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4473                    int end) throws SystemException {
4474                    return findByG_U(groupId, userId, start, end, null);
4475            }
4476    
4477            /**
4478             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4479             *
4480             * <p>
4481             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4482             * </p>
4483             *
4484             * @param groupId the group ID
4485             * @param userId the user ID
4486             * @param start the lower bound of the range of message-boards messages
4487             * @param end the upper bound of the range of message-boards messages (not inclusive)
4488             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4489             * @return the ordered range of matching message-boards messages
4490             * @throws SystemException if a system exception occurred
4491             */
4492            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4493                    int end, OrderByComparator orderByComparator) throws SystemException {
4494                    FinderPath finderPath = null;
4495                    Object[] finderArgs = null;
4496    
4497                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4498                                    (orderByComparator == null)) {
4499                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4500                            finderArgs = new Object[] { groupId, userId };
4501                    }
4502                    else {
4503                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4504                            finderArgs = new Object[] {
4505                                            groupId, userId,
4506                                            
4507                                            start, end, orderByComparator
4508                                    };
4509                    }
4510    
4511                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4512                                    finderArgs, this);
4513    
4514                    if ((list != null) && !list.isEmpty()) {
4515                            for (MBMessage mbMessage : list) {
4516                                    if ((groupId != mbMessage.getGroupId()) ||
4517                                                    (userId != mbMessage.getUserId())) {
4518                                            list = null;
4519    
4520                                            break;
4521                                    }
4522                            }
4523                    }
4524    
4525                    if (list == null) {
4526                            StringBundler query = null;
4527    
4528                            if (orderByComparator != null) {
4529                                    query = new StringBundler(4 +
4530                                                    (orderByComparator.getOrderByFields().length * 3));
4531                            }
4532                            else {
4533                                    query = new StringBundler(4);
4534                            }
4535    
4536                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4537    
4538                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4539    
4540                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4541    
4542                            if (orderByComparator != null) {
4543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4544                                            orderByComparator);
4545                            }
4546    
4547                            else {
4548                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4549                            }
4550    
4551                            String sql = query.toString();
4552    
4553                            Session session = null;
4554    
4555                            try {
4556                                    session = openSession();
4557    
4558                                    Query q = session.createQuery(sql);
4559    
4560                                    QueryPos qPos = QueryPos.getInstance(q);
4561    
4562                                    qPos.add(groupId);
4563    
4564                                    qPos.add(userId);
4565    
4566                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4567                                                    end);
4568                            }
4569                            catch (Exception e) {
4570                                    throw processException(e);
4571                            }
4572                            finally {
4573                                    if (list == null) {
4574                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4575                                    }
4576                                    else {
4577                                            cacheResult(list);
4578    
4579                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4580                                    }
4581    
4582                                    closeSession(session);
4583                            }
4584                    }
4585    
4586                    return list;
4587            }
4588    
4589            /**
4590             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4591             *
4592             * @param groupId the group ID
4593             * @param userId the user ID
4594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4595             * @return the first matching message-boards message
4596             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4597             * @throws SystemException if a system exception occurred
4598             */
4599            public MBMessage findByG_U_First(long groupId, long userId,
4600                    OrderByComparator orderByComparator)
4601                    throws NoSuchMessageException, SystemException {
4602                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4603                                    orderByComparator);
4604    
4605                    if (mbMessage != null) {
4606                            return mbMessage;
4607                    }
4608    
4609                    StringBundler msg = new StringBundler(6);
4610    
4611                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4612    
4613                    msg.append("groupId=");
4614                    msg.append(groupId);
4615    
4616                    msg.append(", userId=");
4617                    msg.append(userId);
4618    
4619                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4620    
4621                    throw new NoSuchMessageException(msg.toString());
4622            }
4623    
4624            /**
4625             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4626             *
4627             * @param groupId the group ID
4628             * @param userId the user ID
4629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4630             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4631             * @throws SystemException if a system exception occurred
4632             */
4633            public MBMessage fetchByG_U_First(long groupId, long userId,
4634                    OrderByComparator orderByComparator) throws SystemException {
4635                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4636                                    orderByComparator);
4637    
4638                    if (!list.isEmpty()) {
4639                            return list.get(0);
4640                    }
4641    
4642                    return null;
4643            }
4644    
4645            /**
4646             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4647             *
4648             * @param groupId the group ID
4649             * @param userId the user ID
4650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4651             * @return the last matching message-boards message
4652             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4653             * @throws SystemException if a system exception occurred
4654             */
4655            public MBMessage findByG_U_Last(long groupId, long userId,
4656                    OrderByComparator orderByComparator)
4657                    throws NoSuchMessageException, SystemException {
4658                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4659    
4660                    if (mbMessage != null) {
4661                            return mbMessage;
4662                    }
4663    
4664                    StringBundler msg = new StringBundler(6);
4665    
4666                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4667    
4668                    msg.append("groupId=");
4669                    msg.append(groupId);
4670    
4671                    msg.append(", userId=");
4672                    msg.append(userId);
4673    
4674                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4675    
4676                    throw new NoSuchMessageException(msg.toString());
4677            }
4678    
4679            /**
4680             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4681             *
4682             * @param groupId the group ID
4683             * @param userId the user ID
4684             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4685             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4686             * @throws SystemException if a system exception occurred
4687             */
4688            public MBMessage fetchByG_U_Last(long groupId, long userId,
4689                    OrderByComparator orderByComparator) throws SystemException {
4690                    int count = countByG_U(groupId, userId);
4691    
4692                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4693                                    orderByComparator);
4694    
4695                    if (!list.isEmpty()) {
4696                            return list.get(0);
4697                    }
4698    
4699                    return null;
4700            }
4701    
4702            /**
4703             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4704             *
4705             * @param messageId the primary key of the current message-boards message
4706             * @param groupId the group ID
4707             * @param userId the user ID
4708             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4709             * @return the previous, current, and next message-boards message
4710             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4711             * @throws SystemException if a system exception occurred
4712             */
4713            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4714                    long userId, OrderByComparator orderByComparator)
4715                    throws NoSuchMessageException, SystemException {
4716                    MBMessage mbMessage = findByPrimaryKey(messageId);
4717    
4718                    Session session = null;
4719    
4720                    try {
4721                            session = openSession();
4722    
4723                            MBMessage[] array = new MBMessageImpl[3];
4724    
4725                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4726                                            userId, orderByComparator, true);
4727    
4728                            array[1] = mbMessage;
4729    
4730                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4731                                            userId, orderByComparator, false);
4732    
4733                            return array;
4734                    }
4735                    catch (Exception e) {
4736                            throw processException(e);
4737                    }
4738                    finally {
4739                            closeSession(session);
4740                    }
4741            }
4742    
4743            protected MBMessage getByG_U_PrevAndNext(Session session,
4744                    MBMessage mbMessage, long groupId, long userId,
4745                    OrderByComparator orderByComparator, boolean previous) {
4746                    StringBundler query = null;
4747    
4748                    if (orderByComparator != null) {
4749                            query = new StringBundler(6 +
4750                                            (orderByComparator.getOrderByFields().length * 6));
4751                    }
4752                    else {
4753                            query = new StringBundler(3);
4754                    }
4755    
4756                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4757    
4758                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4759    
4760                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4761    
4762                    if (orderByComparator != null) {
4763                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4764    
4765                            if (orderByConditionFields.length > 0) {
4766                                    query.append(WHERE_AND);
4767                            }
4768    
4769                            for (int i = 0; i < orderByConditionFields.length; i++) {
4770                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4771                                    query.append(orderByConditionFields[i]);
4772    
4773                                    if ((i + 1) < orderByConditionFields.length) {
4774                                            if (orderByComparator.isAscending() ^ previous) {
4775                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4776                                            }
4777                                            else {
4778                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4779                                            }
4780                                    }
4781                                    else {
4782                                            if (orderByComparator.isAscending() ^ previous) {
4783                                                    query.append(WHERE_GREATER_THAN);
4784                                            }
4785                                            else {
4786                                                    query.append(WHERE_LESSER_THAN);
4787                                            }
4788                                    }
4789                            }
4790    
4791                            query.append(ORDER_BY_CLAUSE);
4792    
4793                            String[] orderByFields = orderByComparator.getOrderByFields();
4794    
4795                            for (int i = 0; i < orderByFields.length; i++) {
4796                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4797                                    query.append(orderByFields[i]);
4798    
4799                                    if ((i + 1) < orderByFields.length) {
4800                                            if (orderByComparator.isAscending() ^ previous) {
4801                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4802                                            }
4803                                            else {
4804                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4805                                            }
4806                                    }
4807                                    else {
4808                                            if (orderByComparator.isAscending() ^ previous) {
4809                                                    query.append(ORDER_BY_ASC);
4810                                            }
4811                                            else {
4812                                                    query.append(ORDER_BY_DESC);
4813                                            }
4814                                    }
4815                            }
4816                    }
4817    
4818                    else {
4819                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4820                    }
4821    
4822                    String sql = query.toString();
4823    
4824                    Query q = session.createQuery(sql);
4825    
4826                    q.setFirstResult(0);
4827                    q.setMaxResults(2);
4828    
4829                    QueryPos qPos = QueryPos.getInstance(q);
4830    
4831                    qPos.add(groupId);
4832    
4833                    qPos.add(userId);
4834    
4835                    if (orderByComparator != null) {
4836                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4837    
4838                            for (Object value : values) {
4839                                    qPos.add(value);
4840                            }
4841                    }
4842    
4843                    List<MBMessage> list = q.list();
4844    
4845                    if (list.size() == 2) {
4846                            return list.get(1);
4847                    }
4848                    else {
4849                            return null;
4850                    }
4851            }
4852    
4853            /**
4854             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4855             *
4856             * @param groupId the group ID
4857             * @param userId the user ID
4858             * @return the matching message-boards messages that the user has permission to view
4859             * @throws SystemException if a system exception occurred
4860             */
4861            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4862                    throws SystemException {
4863                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4864                            QueryUtil.ALL_POS, null);
4865            }
4866    
4867            /**
4868             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4869             *
4870             * <p>
4871             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4872             * </p>
4873             *
4874             * @param groupId the group ID
4875             * @param userId the user ID
4876             * @param start the lower bound of the range of message-boards messages
4877             * @param end the upper bound of the range of message-boards messages (not inclusive)
4878             * @return the range of matching message-boards messages that the user has permission to view
4879             * @throws SystemException if a system exception occurred
4880             */
4881            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4882                    int start, int end) throws SystemException {
4883                    return filterFindByG_U(groupId, userId, start, end, null);
4884            }
4885    
4886            /**
4887             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4888             *
4889             * <p>
4890             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4891             * </p>
4892             *
4893             * @param groupId the group ID
4894             * @param userId the user ID
4895             * @param start the lower bound of the range of message-boards messages
4896             * @param end the upper bound of the range of message-boards messages (not inclusive)
4897             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4898             * @return the ordered range of matching message-boards messages that the user has permission to view
4899             * @throws SystemException if a system exception occurred
4900             */
4901            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4902                    int start, int end, OrderByComparator orderByComparator)
4903                    throws SystemException {
4904                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4905                            return findByG_U(groupId, userId, start, end, orderByComparator);
4906                    }
4907    
4908                    StringBundler query = null;
4909    
4910                    if (orderByComparator != null) {
4911                            query = new StringBundler(4 +
4912                                            (orderByComparator.getOrderByFields().length * 3));
4913                    }
4914                    else {
4915                            query = new StringBundler(4);
4916                    }
4917    
4918                    if (getDB().isSupportsInlineDistinct()) {
4919                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4920                    }
4921                    else {
4922                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4923                    }
4924    
4925                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4926    
4927                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4928    
4929                    if (!getDB().isSupportsInlineDistinct()) {
4930                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4931                    }
4932    
4933                    if (orderByComparator != null) {
4934                            if (getDB().isSupportsInlineDistinct()) {
4935                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4936                                            orderByComparator);
4937                            }
4938                            else {
4939                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4940                                            orderByComparator);
4941                            }
4942                    }
4943    
4944                    else {
4945                            if (getDB().isSupportsInlineDistinct()) {
4946                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4947                            }
4948                            else {
4949                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4950                            }
4951                    }
4952    
4953                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4954                                    MBMessage.class.getName(),
4955                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4956    
4957                    Session session = null;
4958    
4959                    try {
4960                            session = openSession();
4961    
4962                            SQLQuery q = session.createSQLQuery(sql);
4963    
4964                            if (getDB().isSupportsInlineDistinct()) {
4965                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4966                            }
4967                            else {
4968                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4969                            }
4970    
4971                            QueryPos qPos = QueryPos.getInstance(q);
4972    
4973                            qPos.add(groupId);
4974    
4975                            qPos.add(userId);
4976    
4977                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4978                    }
4979                    catch (Exception e) {
4980                            throw processException(e);
4981                    }
4982                    finally {
4983                            closeSession(session);
4984                    }
4985            }
4986    
4987            /**
4988             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4989             *
4990             * @param messageId the primary key of the current message-boards message
4991             * @param groupId the group ID
4992             * @param userId the user ID
4993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4994             * @return the previous, current, and next message-boards message
4995             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4996             * @throws SystemException if a system exception occurred
4997             */
4998            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4999                    long groupId, long userId, OrderByComparator orderByComparator)
5000                    throws NoSuchMessageException, SystemException {
5001                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5002                            return findByG_U_PrevAndNext(messageId, groupId, userId,
5003                                    orderByComparator);
5004                    }
5005    
5006                    MBMessage mbMessage = findByPrimaryKey(messageId);
5007    
5008                    Session session = null;
5009    
5010                    try {
5011                            session = openSession();
5012    
5013                            MBMessage[] array = new MBMessageImpl[3];
5014    
5015                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
5016                                            userId, orderByComparator, true);
5017    
5018                            array[1] = mbMessage;
5019    
5020                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
5021                                            userId, orderByComparator, false);
5022    
5023                            return array;
5024                    }
5025                    catch (Exception e) {
5026                            throw processException(e);
5027                    }
5028                    finally {
5029                            closeSession(session);
5030                    }
5031            }
5032    
5033            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5034                    MBMessage mbMessage, long groupId, long userId,
5035                    OrderByComparator orderByComparator, boolean previous) {
5036                    StringBundler query = null;
5037    
5038                    if (orderByComparator != null) {
5039                            query = new StringBundler(6 +
5040                                            (orderByComparator.getOrderByFields().length * 6));
5041                    }
5042                    else {
5043                            query = new StringBundler(3);
5044                    }
5045    
5046                    if (getDB().isSupportsInlineDistinct()) {
5047                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5048                    }
5049                    else {
5050                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5051                    }
5052    
5053                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5054    
5055                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5056    
5057                    if (!getDB().isSupportsInlineDistinct()) {
5058                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5059                    }
5060    
5061                    if (orderByComparator != null) {
5062                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5063    
5064                            if (orderByConditionFields.length > 0) {
5065                                    query.append(WHERE_AND);
5066                            }
5067    
5068                            for (int i = 0; i < orderByConditionFields.length; i++) {
5069                                    if (getDB().isSupportsInlineDistinct()) {
5070                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5071                                    }
5072                                    else {
5073                                            query.append(_ORDER_BY_ENTITY_TABLE);
5074                                    }
5075    
5076                                    query.append(orderByConditionFields[i]);
5077    
5078                                    if ((i + 1) < orderByConditionFields.length) {
5079                                            if (orderByComparator.isAscending() ^ previous) {
5080                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5081                                            }
5082                                            else {
5083                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5084                                            }
5085                                    }
5086                                    else {
5087                                            if (orderByComparator.isAscending() ^ previous) {
5088                                                    query.append(WHERE_GREATER_THAN);
5089                                            }
5090                                            else {
5091                                                    query.append(WHERE_LESSER_THAN);
5092                                            }
5093                                    }
5094                            }
5095    
5096                            query.append(ORDER_BY_CLAUSE);
5097    
5098                            String[] orderByFields = orderByComparator.getOrderByFields();
5099    
5100                            for (int i = 0; i < orderByFields.length; i++) {
5101                                    if (getDB().isSupportsInlineDistinct()) {
5102                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5103                                    }
5104                                    else {
5105                                            query.append(_ORDER_BY_ENTITY_TABLE);
5106                                    }
5107    
5108                                    query.append(orderByFields[i]);
5109    
5110                                    if ((i + 1) < orderByFields.length) {
5111                                            if (orderByComparator.isAscending() ^ previous) {
5112                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5113                                            }
5114                                            else {
5115                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5116                                            }
5117                                    }
5118                                    else {
5119                                            if (orderByComparator.isAscending() ^ previous) {
5120                                                    query.append(ORDER_BY_ASC);
5121                                            }
5122                                            else {
5123                                                    query.append(ORDER_BY_DESC);
5124                                            }
5125                                    }
5126                            }
5127                    }
5128    
5129                    else {
5130                            if (getDB().isSupportsInlineDistinct()) {
5131                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5132                            }
5133                            else {
5134                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5135                            }
5136                    }
5137    
5138                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5139                                    MBMessage.class.getName(),
5140                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5141    
5142                    SQLQuery q = session.createSQLQuery(sql);
5143    
5144                    q.setFirstResult(0);
5145                    q.setMaxResults(2);
5146    
5147                    if (getDB().isSupportsInlineDistinct()) {
5148                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5149                    }
5150                    else {
5151                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5152                    }
5153    
5154                    QueryPos qPos = QueryPos.getInstance(q);
5155    
5156                    qPos.add(groupId);
5157    
5158                    qPos.add(userId);
5159    
5160                    if (orderByComparator != null) {
5161                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5162    
5163                            for (Object value : values) {
5164                                    qPos.add(value);
5165                            }
5166                    }
5167    
5168                    List<MBMessage> list = q.list();
5169    
5170                    if (list.size() == 2) {
5171                            return list.get(1);
5172                    }
5173                    else {
5174                            return null;
5175                    }
5176            }
5177    
5178            /**
5179             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5180             *
5181             * @param groupId the group ID
5182             * @param categoryId the category ID
5183             * @return the matching message-boards messages
5184             * @throws SystemException if a system exception occurred
5185             */
5186            public List<MBMessage> findByG_C(long groupId, long categoryId)
5187                    throws SystemException {
5188                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5189                            QueryUtil.ALL_POS, null);
5190            }
5191    
5192            /**
5193             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5194             *
5195             * <p>
5196             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5197             * </p>
5198             *
5199             * @param groupId the group ID
5200             * @param categoryId the category ID
5201             * @param start the lower bound of the range of message-boards messages
5202             * @param end the upper bound of the range of message-boards messages (not inclusive)
5203             * @return the range of matching message-boards messages
5204             * @throws SystemException if a system exception occurred
5205             */
5206            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5207                    int end) throws SystemException {
5208                    return findByG_C(groupId, categoryId, start, end, null);
5209            }
5210    
5211            /**
5212             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5213             *
5214             * <p>
5215             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5216             * </p>
5217             *
5218             * @param groupId the group ID
5219             * @param categoryId the category ID
5220             * @param start the lower bound of the range of message-boards messages
5221             * @param end the upper bound of the range of message-boards messages (not inclusive)
5222             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5223             * @return the ordered range of matching message-boards messages
5224             * @throws SystemException if a system exception occurred
5225             */
5226            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5227                    int end, OrderByComparator orderByComparator) throws SystemException {
5228                    FinderPath finderPath = null;
5229                    Object[] finderArgs = null;
5230    
5231                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5232                                    (orderByComparator == null)) {
5233                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5234                            finderArgs = new Object[] { groupId, categoryId };
5235                    }
5236                    else {
5237                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5238                            finderArgs = new Object[] {
5239                                            groupId, categoryId,
5240                                            
5241                                            start, end, orderByComparator
5242                                    };
5243                    }
5244    
5245                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5246                                    finderArgs, this);
5247    
5248                    if ((list != null) && !list.isEmpty()) {
5249                            for (MBMessage mbMessage : list) {
5250                                    if ((groupId != mbMessage.getGroupId()) ||
5251                                                    (categoryId != mbMessage.getCategoryId())) {
5252                                            list = null;
5253    
5254                                            break;
5255                                    }
5256                            }
5257                    }
5258    
5259                    if (list == null) {
5260                            StringBundler query = null;
5261    
5262                            if (orderByComparator != null) {
5263                                    query = new StringBundler(4 +
5264                                                    (orderByComparator.getOrderByFields().length * 3));
5265                            }
5266                            else {
5267                                    query = new StringBundler(4);
5268                            }
5269    
5270                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5271    
5272                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5273    
5274                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5275    
5276                            if (orderByComparator != null) {
5277                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5278                                            orderByComparator);
5279                            }
5280    
5281                            else {
5282                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5283                            }
5284    
5285                            String sql = query.toString();
5286    
5287                            Session session = null;
5288    
5289                            try {
5290                                    session = openSession();
5291    
5292                                    Query q = session.createQuery(sql);
5293    
5294                                    QueryPos qPos = QueryPos.getInstance(q);
5295    
5296                                    qPos.add(groupId);
5297    
5298                                    qPos.add(categoryId);
5299    
5300                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5301                                                    end);
5302                            }
5303                            catch (Exception e) {
5304                                    throw processException(e);
5305                            }
5306                            finally {
5307                                    if (list == null) {
5308                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5309                                    }
5310                                    else {
5311                                            cacheResult(list);
5312    
5313                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5314                                    }
5315    
5316                                    closeSession(session);
5317                            }
5318                    }
5319    
5320                    return list;
5321            }
5322    
5323            /**
5324             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5325             *
5326             * @param groupId the group ID
5327             * @param categoryId the category ID
5328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5329             * @return the first matching message-boards message
5330             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5331             * @throws SystemException if a system exception occurred
5332             */
5333            public MBMessage findByG_C_First(long groupId, long categoryId,
5334                    OrderByComparator orderByComparator)
5335                    throws NoSuchMessageException, SystemException {
5336                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5337                                    orderByComparator);
5338    
5339                    if (mbMessage != null) {
5340                            return mbMessage;
5341                    }
5342    
5343                    StringBundler msg = new StringBundler(6);
5344    
5345                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5346    
5347                    msg.append("groupId=");
5348                    msg.append(groupId);
5349    
5350                    msg.append(", categoryId=");
5351                    msg.append(categoryId);
5352    
5353                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5354    
5355                    throw new NoSuchMessageException(msg.toString());
5356            }
5357    
5358            /**
5359             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5360             *
5361             * @param groupId the group ID
5362             * @param categoryId the category ID
5363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5364             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5365             * @throws SystemException if a system exception occurred
5366             */
5367            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5368                    OrderByComparator orderByComparator) throws SystemException {
5369                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5370                                    orderByComparator);
5371    
5372                    if (!list.isEmpty()) {
5373                            return list.get(0);
5374                    }
5375    
5376                    return null;
5377            }
5378    
5379            /**
5380             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5381             *
5382             * @param groupId the group ID
5383             * @param categoryId the category ID
5384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5385             * @return the last matching message-boards message
5386             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5387             * @throws SystemException if a system exception occurred
5388             */
5389            public MBMessage findByG_C_Last(long groupId, long categoryId,
5390                    OrderByComparator orderByComparator)
5391                    throws NoSuchMessageException, SystemException {
5392                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5393                                    orderByComparator);
5394    
5395                    if (mbMessage != null) {
5396                            return mbMessage;
5397                    }
5398    
5399                    StringBundler msg = new StringBundler(6);
5400    
5401                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5402    
5403                    msg.append("groupId=");
5404                    msg.append(groupId);
5405    
5406                    msg.append(", categoryId=");
5407                    msg.append(categoryId);
5408    
5409                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5410    
5411                    throw new NoSuchMessageException(msg.toString());
5412            }
5413    
5414            /**
5415             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5416             *
5417             * @param groupId the group ID
5418             * @param categoryId the category ID
5419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5420             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5421             * @throws SystemException if a system exception occurred
5422             */
5423            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5424                    OrderByComparator orderByComparator) throws SystemException {
5425                    int count = countByG_C(groupId, categoryId);
5426    
5427                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5428                                    orderByComparator);
5429    
5430                    if (!list.isEmpty()) {
5431                            return list.get(0);
5432                    }
5433    
5434                    return null;
5435            }
5436    
5437            /**
5438             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5439             *
5440             * @param messageId the primary key of the current message-boards message
5441             * @param groupId the group ID
5442             * @param categoryId the category ID
5443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5444             * @return the previous, current, and next message-boards message
5445             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5446             * @throws SystemException if a system exception occurred
5447             */
5448            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5449                    long categoryId, OrderByComparator orderByComparator)
5450                    throws NoSuchMessageException, SystemException {
5451                    MBMessage mbMessage = findByPrimaryKey(messageId);
5452    
5453                    Session session = null;
5454    
5455                    try {
5456                            session = openSession();
5457    
5458                            MBMessage[] array = new MBMessageImpl[3];
5459    
5460                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5461                                            categoryId, orderByComparator, true);
5462    
5463                            array[1] = mbMessage;
5464    
5465                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5466                                            categoryId, orderByComparator, false);
5467    
5468                            return array;
5469                    }
5470                    catch (Exception e) {
5471                            throw processException(e);
5472                    }
5473                    finally {
5474                            closeSession(session);
5475                    }
5476            }
5477    
5478            protected MBMessage getByG_C_PrevAndNext(Session session,
5479                    MBMessage mbMessage, long groupId, long categoryId,
5480                    OrderByComparator orderByComparator, boolean previous) {
5481                    StringBundler query = null;
5482    
5483                    if (orderByComparator != null) {
5484                            query = new StringBundler(6 +
5485                                            (orderByComparator.getOrderByFields().length * 6));
5486                    }
5487                    else {
5488                            query = new StringBundler(3);
5489                    }
5490    
5491                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5492    
5493                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5494    
5495                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5496    
5497                    if (orderByComparator != null) {
5498                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5499    
5500                            if (orderByConditionFields.length > 0) {
5501                                    query.append(WHERE_AND);
5502                            }
5503    
5504                            for (int i = 0; i < orderByConditionFields.length; i++) {
5505                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5506                                    query.append(orderByConditionFields[i]);
5507    
5508                                    if ((i + 1) < orderByConditionFields.length) {
5509                                            if (orderByComparator.isAscending() ^ previous) {
5510                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5511                                            }
5512                                            else {
5513                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5514                                            }
5515                                    }
5516                                    else {
5517                                            if (orderByComparator.isAscending() ^ previous) {
5518                                                    query.append(WHERE_GREATER_THAN);
5519                                            }
5520                                            else {
5521                                                    query.append(WHERE_LESSER_THAN);
5522                                            }
5523                                    }
5524                            }
5525    
5526                            query.append(ORDER_BY_CLAUSE);
5527    
5528                            String[] orderByFields = orderByComparator.getOrderByFields();
5529    
5530                            for (int i = 0; i < orderByFields.length; i++) {
5531                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5532                                    query.append(orderByFields[i]);
5533    
5534                                    if ((i + 1) < orderByFields.length) {
5535                                            if (orderByComparator.isAscending() ^ previous) {
5536                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5537                                            }
5538                                            else {
5539                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5540                                            }
5541                                    }
5542                                    else {
5543                                            if (orderByComparator.isAscending() ^ previous) {
5544                                                    query.append(ORDER_BY_ASC);
5545                                            }
5546                                            else {
5547                                                    query.append(ORDER_BY_DESC);
5548                                            }
5549                                    }
5550                            }
5551                    }
5552    
5553                    else {
5554                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5555                    }
5556    
5557                    String sql = query.toString();
5558    
5559                    Query q = session.createQuery(sql);
5560    
5561                    q.setFirstResult(0);
5562                    q.setMaxResults(2);
5563    
5564                    QueryPos qPos = QueryPos.getInstance(q);
5565    
5566                    qPos.add(groupId);
5567    
5568                    qPos.add(categoryId);
5569    
5570                    if (orderByComparator != null) {
5571                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5572    
5573                            for (Object value : values) {
5574                                    qPos.add(value);
5575                            }
5576                    }
5577    
5578                    List<MBMessage> list = q.list();
5579    
5580                    if (list.size() == 2) {
5581                            return list.get(1);
5582                    }
5583                    else {
5584                            return null;
5585                    }
5586            }
5587    
5588            /**
5589             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5590             *
5591             * @param groupId the group ID
5592             * @param categoryId the category ID
5593             * @return the matching message-boards messages that the user has permission to view
5594             * @throws SystemException if a system exception occurred
5595             */
5596            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5597                    throws SystemException {
5598                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5599                            QueryUtil.ALL_POS, null);
5600            }
5601    
5602            /**
5603             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5604             *
5605             * <p>
5606             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5607             * </p>
5608             *
5609             * @param groupId the group ID
5610             * @param categoryId the category ID
5611             * @param start the lower bound of the range of message-boards messages
5612             * @param end the upper bound of the range of message-boards messages (not inclusive)
5613             * @return the range of matching message-boards messages that the user has permission to view
5614             * @throws SystemException if a system exception occurred
5615             */
5616            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5617                    int start, int end) throws SystemException {
5618                    return filterFindByG_C(groupId, categoryId, start, end, null);
5619            }
5620    
5621            /**
5622             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5623             *
5624             * <p>
5625             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5626             * </p>
5627             *
5628             * @param groupId the group ID
5629             * @param categoryId the category ID
5630             * @param start the lower bound of the range of message-boards messages
5631             * @param end the upper bound of the range of message-boards messages (not inclusive)
5632             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5633             * @return the ordered range of matching message-boards messages that the user has permission to view
5634             * @throws SystemException if a system exception occurred
5635             */
5636            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5637                    int start, int end, OrderByComparator orderByComparator)
5638                    throws SystemException {
5639                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5640                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5641                    }
5642    
5643                    StringBundler query = null;
5644    
5645                    if (orderByComparator != null) {
5646                            query = new StringBundler(4 +
5647                                            (orderByComparator.getOrderByFields().length * 3));
5648                    }
5649                    else {
5650                            query = new StringBundler(4);
5651                    }
5652    
5653                    if (getDB().isSupportsInlineDistinct()) {
5654                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5655                    }
5656                    else {
5657                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5658                    }
5659    
5660                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5661    
5662                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5663    
5664                    if (!getDB().isSupportsInlineDistinct()) {
5665                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5666                    }
5667    
5668                    if (orderByComparator != null) {
5669                            if (getDB().isSupportsInlineDistinct()) {
5670                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5671                                            orderByComparator);
5672                            }
5673                            else {
5674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5675                                            orderByComparator);
5676                            }
5677                    }
5678    
5679                    else {
5680                            if (getDB().isSupportsInlineDistinct()) {
5681                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5682                            }
5683                            else {
5684                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5685                            }
5686                    }
5687    
5688                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5689                                    MBMessage.class.getName(),
5690                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5691    
5692                    Session session = null;
5693    
5694                    try {
5695                            session = openSession();
5696    
5697                            SQLQuery q = session.createSQLQuery(sql);
5698    
5699                            if (getDB().isSupportsInlineDistinct()) {
5700                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5701                            }
5702                            else {
5703                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5704                            }
5705    
5706                            QueryPos qPos = QueryPos.getInstance(q);
5707    
5708                            qPos.add(groupId);
5709    
5710                            qPos.add(categoryId);
5711    
5712                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5713                    }
5714                    catch (Exception e) {
5715                            throw processException(e);
5716                    }
5717                    finally {
5718                            closeSession(session);
5719                    }
5720            }
5721    
5722            /**
5723             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5724             *
5725             * @param messageId the primary key of the current message-boards message
5726             * @param groupId the group ID
5727             * @param categoryId the category ID
5728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5729             * @return the previous, current, and next message-boards message
5730             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5731             * @throws SystemException if a system exception occurred
5732             */
5733            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5734                    long groupId, long categoryId, OrderByComparator orderByComparator)
5735                    throws NoSuchMessageException, SystemException {
5736                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5737                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5738                                    orderByComparator);
5739                    }
5740    
5741                    MBMessage mbMessage = findByPrimaryKey(messageId);
5742    
5743                    Session session = null;
5744    
5745                    try {
5746                            session = openSession();
5747    
5748                            MBMessage[] array = new MBMessageImpl[3];
5749    
5750                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5751                                            categoryId, orderByComparator, true);
5752    
5753                            array[1] = mbMessage;
5754    
5755                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5756                                            categoryId, orderByComparator, false);
5757    
5758                            return array;
5759                    }
5760                    catch (Exception e) {
5761                            throw processException(e);
5762                    }
5763                    finally {
5764                            closeSession(session);
5765                    }
5766            }
5767    
5768            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5769                    MBMessage mbMessage, long groupId, long categoryId,
5770                    OrderByComparator orderByComparator, boolean previous) {
5771                    StringBundler query = null;
5772    
5773                    if (orderByComparator != null) {
5774                            query = new StringBundler(6 +
5775                                            (orderByComparator.getOrderByFields().length * 6));
5776                    }
5777                    else {
5778                            query = new StringBundler(3);
5779                    }
5780    
5781                    if (getDB().isSupportsInlineDistinct()) {
5782                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5783                    }
5784                    else {
5785                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5786                    }
5787    
5788                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5789    
5790                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5791    
5792                    if (!getDB().isSupportsInlineDistinct()) {
5793                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5794                    }
5795    
5796                    if (orderByComparator != null) {
5797                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5798    
5799                            if (orderByConditionFields.length > 0) {
5800                                    query.append(WHERE_AND);
5801                            }
5802    
5803                            for (int i = 0; i < orderByConditionFields.length; i++) {
5804                                    if (getDB().isSupportsInlineDistinct()) {
5805                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5806                                    }
5807                                    else {
5808                                            query.append(_ORDER_BY_ENTITY_TABLE);
5809                                    }
5810    
5811                                    query.append(orderByConditionFields[i]);
5812    
5813                                    if ((i + 1) < orderByConditionFields.length) {
5814                                            if (orderByComparator.isAscending() ^ previous) {
5815                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5816                                            }
5817                                            else {
5818                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5819                                            }
5820                                    }
5821                                    else {
5822                                            if (orderByComparator.isAscending() ^ previous) {
5823                                                    query.append(WHERE_GREATER_THAN);
5824                                            }
5825                                            else {
5826                                                    query.append(WHERE_LESSER_THAN);
5827                                            }
5828                                    }
5829                            }
5830    
5831                            query.append(ORDER_BY_CLAUSE);
5832    
5833                            String[] orderByFields = orderByComparator.getOrderByFields();
5834    
5835                            for (int i = 0; i < orderByFields.length; i++) {
5836                                    if (getDB().isSupportsInlineDistinct()) {
5837                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5838                                    }
5839                                    else {
5840                                            query.append(_ORDER_BY_ENTITY_TABLE);
5841                                    }
5842    
5843                                    query.append(orderByFields[i]);
5844    
5845                                    if ((i + 1) < orderByFields.length) {
5846                                            if (orderByComparator.isAscending() ^ previous) {
5847                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5848                                            }
5849                                            else {
5850                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5851                                            }
5852                                    }
5853                                    else {
5854                                            if (orderByComparator.isAscending() ^ previous) {
5855                                                    query.append(ORDER_BY_ASC);
5856                                            }
5857                                            else {
5858                                                    query.append(ORDER_BY_DESC);
5859                                            }
5860                                    }
5861                            }
5862                    }
5863    
5864                    else {
5865                            if (getDB().isSupportsInlineDistinct()) {
5866                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5867                            }
5868                            else {
5869                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5870                            }
5871                    }
5872    
5873                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5874                                    MBMessage.class.getName(),
5875                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5876    
5877                    SQLQuery q = session.createSQLQuery(sql);
5878    
5879                    q.setFirstResult(0);
5880                    q.setMaxResults(2);
5881    
5882                    if (getDB().isSupportsInlineDistinct()) {
5883                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5884                    }
5885                    else {
5886                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5887                    }
5888    
5889                    QueryPos qPos = QueryPos.getInstance(q);
5890    
5891                    qPos.add(groupId);
5892    
5893                    qPos.add(categoryId);
5894    
5895                    if (orderByComparator != null) {
5896                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5897    
5898                            for (Object value : values) {
5899                                    qPos.add(value);
5900                            }
5901                    }
5902    
5903                    List<MBMessage> list = q.list();
5904    
5905                    if (list.size() == 2) {
5906                            return list.get(1);
5907                    }
5908                    else {
5909                            return null;
5910                    }
5911            }
5912    
5913            /**
5914             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5915             *
5916             * @param groupId the group ID
5917             * @param status the status
5918             * @return the matching message-boards messages
5919             * @throws SystemException if a system exception occurred
5920             */
5921            public List<MBMessage> findByG_S(long groupId, int status)
5922                    throws SystemException {
5923                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5924                            null);
5925            }
5926    
5927            /**
5928             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5929             *
5930             * <p>
5931             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5932             * </p>
5933             *
5934             * @param groupId the group ID
5935             * @param status the status
5936             * @param start the lower bound of the range of message-boards messages
5937             * @param end the upper bound of the range of message-boards messages (not inclusive)
5938             * @return the range of matching message-boards messages
5939             * @throws SystemException if a system exception occurred
5940             */
5941            public List<MBMessage> findByG_S(long groupId, int status, int start,
5942                    int end) throws SystemException {
5943                    return findByG_S(groupId, status, start, end, null);
5944            }
5945    
5946            /**
5947             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
5948             *
5949             * <p>
5950             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5951             * </p>
5952             *
5953             * @param groupId the group ID
5954             * @param status the status
5955             * @param start the lower bound of the range of message-boards messages
5956             * @param end the upper bound of the range of message-boards messages (not inclusive)
5957             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5958             * @return the ordered range of matching message-boards messages
5959             * @throws SystemException if a system exception occurred
5960             */
5961            public List<MBMessage> findByG_S(long groupId, int status, int start,
5962                    int end, OrderByComparator orderByComparator) throws SystemException {
5963                    FinderPath finderPath = null;
5964                    Object[] finderArgs = null;
5965    
5966                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5967                                    (orderByComparator == null)) {
5968                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
5969                            finderArgs = new Object[] { groupId, status };
5970                    }
5971                    else {
5972                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
5973                            finderArgs = new Object[] {
5974                                            groupId, status,
5975                                            
5976                                            start, end, orderByComparator
5977                                    };
5978                    }
5979    
5980                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5981                                    finderArgs, this);
5982    
5983                    if ((list != null) && !list.isEmpty()) {
5984                            for (MBMessage mbMessage : list) {
5985                                    if ((groupId != mbMessage.getGroupId()) ||
5986                                                    (status != mbMessage.getStatus())) {
5987                                            list = null;
5988    
5989                                            break;
5990                                    }
5991                            }
5992                    }
5993    
5994                    if (list == null) {
5995                            StringBundler query = null;
5996    
5997                            if (orderByComparator != null) {
5998                                    query = new StringBundler(4 +
5999                                                    (orderByComparator.getOrderByFields().length * 3));
6000                            }
6001                            else {
6002                                    query = new StringBundler(4);
6003                            }
6004    
6005                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6006    
6007                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6008    
6009                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6010    
6011                            if (orderByComparator != null) {
6012                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6013                                            orderByComparator);
6014                            }
6015    
6016                            else {
6017                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6018                            }
6019    
6020                            String sql = query.toString();
6021    
6022                            Session session = null;
6023    
6024                            try {
6025                                    session = openSession();
6026    
6027                                    Query q = session.createQuery(sql);
6028    
6029                                    QueryPos qPos = QueryPos.getInstance(q);
6030    
6031                                    qPos.add(groupId);
6032    
6033                                    qPos.add(status);
6034    
6035                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6036                                                    end);
6037                            }
6038                            catch (Exception e) {
6039                                    throw processException(e);
6040                            }
6041                            finally {
6042                                    if (list == null) {
6043                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6044                                    }
6045                                    else {
6046                                            cacheResult(list);
6047    
6048                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6049                                    }
6050    
6051                                    closeSession(session);
6052                            }
6053                    }
6054    
6055                    return list;
6056            }
6057    
6058            /**
6059             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6060             *
6061             * @param groupId the group ID
6062             * @param status the status
6063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6064             * @return the first matching message-boards message
6065             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6066             * @throws SystemException if a system exception occurred
6067             */
6068            public MBMessage findByG_S_First(long groupId, int status,
6069                    OrderByComparator orderByComparator)
6070                    throws NoSuchMessageException, SystemException {
6071                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6072                                    orderByComparator);
6073    
6074                    if (mbMessage != null) {
6075                            return mbMessage;
6076                    }
6077    
6078                    StringBundler msg = new StringBundler(6);
6079    
6080                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6081    
6082                    msg.append("groupId=");
6083                    msg.append(groupId);
6084    
6085                    msg.append(", status=");
6086                    msg.append(status);
6087    
6088                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6089    
6090                    throw new NoSuchMessageException(msg.toString());
6091            }
6092    
6093            /**
6094             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6095             *
6096             * @param groupId the group ID
6097             * @param status the status
6098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6099             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6100             * @throws SystemException if a system exception occurred
6101             */
6102            public MBMessage fetchByG_S_First(long groupId, int status,
6103                    OrderByComparator orderByComparator) throws SystemException {
6104                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6105                                    orderByComparator);
6106    
6107                    if (!list.isEmpty()) {
6108                            return list.get(0);
6109                    }
6110    
6111                    return null;
6112            }
6113    
6114            /**
6115             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6116             *
6117             * @param groupId the group ID
6118             * @param status the status
6119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6120             * @return the last matching message-boards message
6121             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6122             * @throws SystemException if a system exception occurred
6123             */
6124            public MBMessage findByG_S_Last(long groupId, int status,
6125                    OrderByComparator orderByComparator)
6126                    throws NoSuchMessageException, SystemException {
6127                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6128    
6129                    if (mbMessage != null) {
6130                            return mbMessage;
6131                    }
6132    
6133                    StringBundler msg = new StringBundler(6);
6134    
6135                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6136    
6137                    msg.append("groupId=");
6138                    msg.append(groupId);
6139    
6140                    msg.append(", status=");
6141                    msg.append(status);
6142    
6143                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6144    
6145                    throw new NoSuchMessageException(msg.toString());
6146            }
6147    
6148            /**
6149             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6150             *
6151             * @param groupId the group ID
6152             * @param status the status
6153             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6154             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6155             * @throws SystemException if a system exception occurred
6156             */
6157            public MBMessage fetchByG_S_Last(long groupId, int status,
6158                    OrderByComparator orderByComparator) throws SystemException {
6159                    int count = countByG_S(groupId, status);
6160    
6161                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6162                                    orderByComparator);
6163    
6164                    if (!list.isEmpty()) {
6165                            return list.get(0);
6166                    }
6167    
6168                    return null;
6169            }
6170    
6171            /**
6172             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6173             *
6174             * @param messageId the primary key of the current message-boards message
6175             * @param groupId the group ID
6176             * @param status the status
6177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6178             * @return the previous, current, and next message-boards message
6179             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6180             * @throws SystemException if a system exception occurred
6181             */
6182            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6183                    int status, OrderByComparator orderByComparator)
6184                    throws NoSuchMessageException, SystemException {
6185                    MBMessage mbMessage = findByPrimaryKey(messageId);
6186    
6187                    Session session = null;
6188    
6189                    try {
6190                            session = openSession();
6191    
6192                            MBMessage[] array = new MBMessageImpl[3];
6193    
6194                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6195                                            status, orderByComparator, true);
6196    
6197                            array[1] = mbMessage;
6198    
6199                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6200                                            status, orderByComparator, false);
6201    
6202                            return array;
6203                    }
6204                    catch (Exception e) {
6205                            throw processException(e);
6206                    }
6207                    finally {
6208                            closeSession(session);
6209                    }
6210            }
6211    
6212            protected MBMessage getByG_S_PrevAndNext(Session session,
6213                    MBMessage mbMessage, long groupId, int status,
6214                    OrderByComparator orderByComparator, boolean previous) {
6215                    StringBundler query = null;
6216    
6217                    if (orderByComparator != null) {
6218                            query = new StringBundler(6 +
6219                                            (orderByComparator.getOrderByFields().length * 6));
6220                    }
6221                    else {
6222                            query = new StringBundler(3);
6223                    }
6224    
6225                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6226    
6227                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6228    
6229                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6230    
6231                    if (orderByComparator != null) {
6232                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6233    
6234                            if (orderByConditionFields.length > 0) {
6235                                    query.append(WHERE_AND);
6236                            }
6237    
6238                            for (int i = 0; i < orderByConditionFields.length; i++) {
6239                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6240                                    query.append(orderByConditionFields[i]);
6241    
6242                                    if ((i + 1) < orderByConditionFields.length) {
6243                                            if (orderByComparator.isAscending() ^ previous) {
6244                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6245                                            }
6246                                            else {
6247                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6248                                            }
6249                                    }
6250                                    else {
6251                                            if (orderByComparator.isAscending() ^ previous) {
6252                                                    query.append(WHERE_GREATER_THAN);
6253                                            }
6254                                            else {
6255                                                    query.append(WHERE_LESSER_THAN);
6256                                            }
6257                                    }
6258                            }
6259    
6260                            query.append(ORDER_BY_CLAUSE);
6261    
6262                            String[] orderByFields = orderByComparator.getOrderByFields();
6263    
6264                            for (int i = 0; i < orderByFields.length; i++) {
6265                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6266                                    query.append(orderByFields[i]);
6267    
6268                                    if ((i + 1) < orderByFields.length) {
6269                                            if (orderByComparator.isAscending() ^ previous) {
6270                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6271                                            }
6272                                            else {
6273                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6274                                            }
6275                                    }
6276                                    else {
6277                                            if (orderByComparator.isAscending() ^ previous) {
6278                                                    query.append(ORDER_BY_ASC);
6279                                            }
6280                                            else {
6281                                                    query.append(ORDER_BY_DESC);
6282                                            }
6283                                    }
6284                            }
6285                    }
6286    
6287                    else {
6288                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6289                    }
6290    
6291                    String sql = query.toString();
6292    
6293                    Query q = session.createQuery(sql);
6294    
6295                    q.setFirstResult(0);
6296                    q.setMaxResults(2);
6297    
6298                    QueryPos qPos = QueryPos.getInstance(q);
6299    
6300                    qPos.add(groupId);
6301    
6302                    qPos.add(status);
6303    
6304                    if (orderByComparator != null) {
6305                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6306    
6307                            for (Object value : values) {
6308                                    qPos.add(value);
6309                            }
6310                    }
6311    
6312                    List<MBMessage> list = q.list();
6313    
6314                    if (list.size() == 2) {
6315                            return list.get(1);
6316                    }
6317                    else {
6318                            return null;
6319                    }
6320            }
6321    
6322            /**
6323             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6324             *
6325             * @param groupId the group ID
6326             * @param status the status
6327             * @return the matching message-boards messages that the user has permission to view
6328             * @throws SystemException if a system exception occurred
6329             */
6330            public List<MBMessage> filterFindByG_S(long groupId, int status)
6331                    throws SystemException {
6332                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6333                            QueryUtil.ALL_POS, null);
6334            }
6335    
6336            /**
6337             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6338             *
6339             * <p>
6340             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6341             * </p>
6342             *
6343             * @param groupId the group ID
6344             * @param status the status
6345             * @param start the lower bound of the range of message-boards messages
6346             * @param end the upper bound of the range of message-boards messages (not inclusive)
6347             * @return the range of matching message-boards messages that the user has permission to view
6348             * @throws SystemException if a system exception occurred
6349             */
6350            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6351                    int end) throws SystemException {
6352                    return filterFindByG_S(groupId, status, start, end, null);
6353            }
6354    
6355            /**
6356             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6357             *
6358             * <p>
6359             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6360             * </p>
6361             *
6362             * @param groupId the group ID
6363             * @param status the status
6364             * @param start the lower bound of the range of message-boards messages
6365             * @param end the upper bound of the range of message-boards messages (not inclusive)
6366             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6367             * @return the ordered range of matching message-boards messages that the user has permission to view
6368             * @throws SystemException if a system exception occurred
6369             */
6370            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6371                    int end, OrderByComparator orderByComparator) throws SystemException {
6372                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6373                            return findByG_S(groupId, status, start, end, orderByComparator);
6374                    }
6375    
6376                    StringBundler query = null;
6377    
6378                    if (orderByComparator != null) {
6379                            query = new StringBundler(4 +
6380                                            (orderByComparator.getOrderByFields().length * 3));
6381                    }
6382                    else {
6383                            query = new StringBundler(4);
6384                    }
6385    
6386                    if (getDB().isSupportsInlineDistinct()) {
6387                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6388                    }
6389                    else {
6390                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6391                    }
6392    
6393                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6394    
6395                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6396    
6397                    if (!getDB().isSupportsInlineDistinct()) {
6398                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6399                    }
6400    
6401                    if (orderByComparator != null) {
6402                            if (getDB().isSupportsInlineDistinct()) {
6403                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6404                                            orderByComparator);
6405                            }
6406                            else {
6407                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6408                                            orderByComparator);
6409                            }
6410                    }
6411    
6412                    else {
6413                            if (getDB().isSupportsInlineDistinct()) {
6414                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6415                            }
6416                            else {
6417                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6418                            }
6419                    }
6420    
6421                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6422                                    MBMessage.class.getName(),
6423                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6424    
6425                    Session session = null;
6426    
6427                    try {
6428                            session = openSession();
6429    
6430                            SQLQuery q = session.createSQLQuery(sql);
6431    
6432                            if (getDB().isSupportsInlineDistinct()) {
6433                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6434                            }
6435                            else {
6436                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6437                            }
6438    
6439                            QueryPos qPos = QueryPos.getInstance(q);
6440    
6441                            qPos.add(groupId);
6442    
6443                            qPos.add(status);
6444    
6445                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6446                    }
6447                    catch (Exception e) {
6448                            throw processException(e);
6449                    }
6450                    finally {
6451                            closeSession(session);
6452                    }
6453            }
6454    
6455            /**
6456             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6457             *
6458             * @param messageId the primary key of the current message-boards message
6459             * @param groupId the group ID
6460             * @param status the status
6461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6462             * @return the previous, current, and next message-boards message
6463             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6464             * @throws SystemException if a system exception occurred
6465             */
6466            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6467                    long groupId, int status, OrderByComparator orderByComparator)
6468                    throws NoSuchMessageException, SystemException {
6469                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6470                            return findByG_S_PrevAndNext(messageId, groupId, status,
6471                                    orderByComparator);
6472                    }
6473    
6474                    MBMessage mbMessage = findByPrimaryKey(messageId);
6475    
6476                    Session session = null;
6477    
6478                    try {
6479                            session = openSession();
6480    
6481                            MBMessage[] array = new MBMessageImpl[3];
6482    
6483                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6484                                            status, orderByComparator, true);
6485    
6486                            array[1] = mbMessage;
6487    
6488                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6489                                            status, orderByComparator, false);
6490    
6491                            return array;
6492                    }
6493                    catch (Exception e) {
6494                            throw processException(e);
6495                    }
6496                    finally {
6497                            closeSession(session);
6498                    }
6499            }
6500    
6501            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6502                    MBMessage mbMessage, long groupId, int status,
6503                    OrderByComparator orderByComparator, boolean previous) {
6504                    StringBundler query = null;
6505    
6506                    if (orderByComparator != null) {
6507                            query = new StringBundler(6 +
6508                                            (orderByComparator.getOrderByFields().length * 6));
6509                    }
6510                    else {
6511                            query = new StringBundler(3);
6512                    }
6513    
6514                    if (getDB().isSupportsInlineDistinct()) {
6515                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6516                    }
6517                    else {
6518                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6519                    }
6520    
6521                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6522    
6523                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6524    
6525                    if (!getDB().isSupportsInlineDistinct()) {
6526                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6527                    }
6528    
6529                    if (orderByComparator != null) {
6530                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6531    
6532                            if (orderByConditionFields.length > 0) {
6533                                    query.append(WHERE_AND);
6534                            }
6535    
6536                            for (int i = 0; i < orderByConditionFields.length; i++) {
6537                                    if (getDB().isSupportsInlineDistinct()) {
6538                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6539                                    }
6540                                    else {
6541                                            query.append(_ORDER_BY_ENTITY_TABLE);
6542                                    }
6543    
6544                                    query.append(orderByConditionFields[i]);
6545    
6546                                    if ((i + 1) < orderByConditionFields.length) {
6547                                            if (orderByComparator.isAscending() ^ previous) {
6548                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6549                                            }
6550                                            else {
6551                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6552                                            }
6553                                    }
6554                                    else {
6555                                            if (orderByComparator.isAscending() ^ previous) {
6556                                                    query.append(WHERE_GREATER_THAN);
6557                                            }
6558                                            else {
6559                                                    query.append(WHERE_LESSER_THAN);
6560                                            }
6561                                    }
6562                            }
6563    
6564                            query.append(ORDER_BY_CLAUSE);
6565    
6566                            String[] orderByFields = orderByComparator.getOrderByFields();
6567    
6568                            for (int i = 0; i < orderByFields.length; i++) {
6569                                    if (getDB().isSupportsInlineDistinct()) {
6570                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6571                                    }
6572                                    else {
6573                                            query.append(_ORDER_BY_ENTITY_TABLE);
6574                                    }
6575    
6576                                    query.append(orderByFields[i]);
6577    
6578                                    if ((i + 1) < orderByFields.length) {
6579                                            if (orderByComparator.isAscending() ^ previous) {
6580                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6581                                            }
6582                                            else {
6583                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6584                                            }
6585                                    }
6586                                    else {
6587                                            if (orderByComparator.isAscending() ^ previous) {
6588                                                    query.append(ORDER_BY_ASC);
6589                                            }
6590                                            else {
6591                                                    query.append(ORDER_BY_DESC);
6592                                            }
6593                                    }
6594                            }
6595                    }
6596    
6597                    else {
6598                            if (getDB().isSupportsInlineDistinct()) {
6599                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6600                            }
6601                            else {
6602                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6603                            }
6604                    }
6605    
6606                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6607                                    MBMessage.class.getName(),
6608                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6609    
6610                    SQLQuery q = session.createSQLQuery(sql);
6611    
6612                    q.setFirstResult(0);
6613                    q.setMaxResults(2);
6614    
6615                    if (getDB().isSupportsInlineDistinct()) {
6616                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6617                    }
6618                    else {
6619                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6620                    }
6621    
6622                    QueryPos qPos = QueryPos.getInstance(q);
6623    
6624                    qPos.add(groupId);
6625    
6626                    qPos.add(status);
6627    
6628                    if (orderByComparator != null) {
6629                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6630    
6631                            for (Object value : values) {
6632                                    qPos.add(value);
6633                            }
6634                    }
6635    
6636                    List<MBMessage> list = q.list();
6637    
6638                    if (list.size() == 2) {
6639                            return list.get(1);
6640                    }
6641                    else {
6642                            return null;
6643                    }
6644            }
6645    
6646            /**
6647             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6648             *
6649             * @param companyId the company ID
6650             * @param status the status
6651             * @return the matching message-boards messages
6652             * @throws SystemException if a system exception occurred
6653             */
6654            public List<MBMessage> findByC_S(long companyId, int status)
6655                    throws SystemException {
6656                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6657                            QueryUtil.ALL_POS, null);
6658            }
6659    
6660            /**
6661             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6662             *
6663             * <p>
6664             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6665             * </p>
6666             *
6667             * @param companyId the company ID
6668             * @param status the status
6669             * @param start the lower bound of the range of message-boards messages
6670             * @param end the upper bound of the range of message-boards messages (not inclusive)
6671             * @return the range of matching message-boards messages
6672             * @throws SystemException if a system exception occurred
6673             */
6674            public List<MBMessage> findByC_S(long companyId, int status, int start,
6675                    int end) throws SystemException {
6676                    return findByC_S(companyId, status, start, end, null);
6677            }
6678    
6679            /**
6680             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6681             *
6682             * <p>
6683             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6684             * </p>
6685             *
6686             * @param companyId the company ID
6687             * @param status the status
6688             * @param start the lower bound of the range of message-boards messages
6689             * @param end the upper bound of the range of message-boards messages (not inclusive)
6690             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6691             * @return the ordered range of matching message-boards messages
6692             * @throws SystemException if a system exception occurred
6693             */
6694            public List<MBMessage> findByC_S(long companyId, int status, int start,
6695                    int end, OrderByComparator orderByComparator) throws SystemException {
6696                    FinderPath finderPath = null;
6697                    Object[] finderArgs = null;
6698    
6699                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6700                                    (orderByComparator == null)) {
6701                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6702                            finderArgs = new Object[] { companyId, status };
6703                    }
6704                    else {
6705                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6706                            finderArgs = new Object[] {
6707                                            companyId, status,
6708                                            
6709                                            start, end, orderByComparator
6710                                    };
6711                    }
6712    
6713                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6714                                    finderArgs, this);
6715    
6716                    if ((list != null) && !list.isEmpty()) {
6717                            for (MBMessage mbMessage : list) {
6718                                    if ((companyId != mbMessage.getCompanyId()) ||
6719                                                    (status != mbMessage.getStatus())) {
6720                                            list = null;
6721    
6722                                            break;
6723                                    }
6724                            }
6725                    }
6726    
6727                    if (list == null) {
6728                            StringBundler query = null;
6729    
6730                            if (orderByComparator != null) {
6731                                    query = new StringBundler(4 +
6732                                                    (orderByComparator.getOrderByFields().length * 3));
6733                            }
6734                            else {
6735                                    query = new StringBundler(4);
6736                            }
6737    
6738                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6739    
6740                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6741    
6742                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6743    
6744                            if (orderByComparator != null) {
6745                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6746                                            orderByComparator);
6747                            }
6748    
6749                            else {
6750                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6751                            }
6752    
6753                            String sql = query.toString();
6754    
6755                            Session session = null;
6756    
6757                            try {
6758                                    session = openSession();
6759    
6760                                    Query q = session.createQuery(sql);
6761    
6762                                    QueryPos qPos = QueryPos.getInstance(q);
6763    
6764                                    qPos.add(companyId);
6765    
6766                                    qPos.add(status);
6767    
6768                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6769                                                    end);
6770                            }
6771                            catch (Exception e) {
6772                                    throw processException(e);
6773                            }
6774                            finally {
6775                                    if (list == null) {
6776                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6777                                    }
6778                                    else {
6779                                            cacheResult(list);
6780    
6781                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6782                                    }
6783    
6784                                    closeSession(session);
6785                            }
6786                    }
6787    
6788                    return list;
6789            }
6790    
6791            /**
6792             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6793             *
6794             * @param companyId the company ID
6795             * @param status the status
6796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6797             * @return the first matching message-boards message
6798             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6799             * @throws SystemException if a system exception occurred
6800             */
6801            public MBMessage findByC_S_First(long companyId, int status,
6802                    OrderByComparator orderByComparator)
6803                    throws NoSuchMessageException, SystemException {
6804                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
6805                                    orderByComparator);
6806    
6807                    if (mbMessage != null) {
6808                            return mbMessage;
6809                    }
6810    
6811                    StringBundler msg = new StringBundler(6);
6812    
6813                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6814    
6815                    msg.append("companyId=");
6816                    msg.append(companyId);
6817    
6818                    msg.append(", status=");
6819                    msg.append(status);
6820    
6821                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6822    
6823                    throw new NoSuchMessageException(msg.toString());
6824            }
6825    
6826            /**
6827             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6828             *
6829             * @param companyId the company ID
6830             * @param status the status
6831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6832             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6833             * @throws SystemException if a system exception occurred
6834             */
6835            public MBMessage fetchByC_S_First(long companyId, int status,
6836                    OrderByComparator orderByComparator) throws SystemException {
6837                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
6838                                    orderByComparator);
6839    
6840                    if (!list.isEmpty()) {
6841                            return list.get(0);
6842                    }
6843    
6844                    return null;
6845            }
6846    
6847            /**
6848             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6849             *
6850             * @param companyId the company ID
6851             * @param status the status
6852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6853             * @return the last matching message-boards message
6854             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6855             * @throws SystemException if a system exception occurred
6856             */
6857            public MBMessage findByC_S_Last(long companyId, int status,
6858                    OrderByComparator orderByComparator)
6859                    throws NoSuchMessageException, SystemException {
6860                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
6861                                    orderByComparator);
6862    
6863                    if (mbMessage != null) {
6864                            return mbMessage;
6865                    }
6866    
6867                    StringBundler msg = new StringBundler(6);
6868    
6869                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6870    
6871                    msg.append("companyId=");
6872                    msg.append(companyId);
6873    
6874                    msg.append(", status=");
6875                    msg.append(status);
6876    
6877                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6878    
6879                    throw new NoSuchMessageException(msg.toString());
6880            }
6881    
6882            /**
6883             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6884             *
6885             * @param companyId the company ID
6886             * @param status the status
6887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6888             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6889             * @throws SystemException if a system exception occurred
6890             */
6891            public MBMessage fetchByC_S_Last(long companyId, int status,
6892                    OrderByComparator orderByComparator) throws SystemException {
6893                    int count = countByC_S(companyId, status);
6894    
6895                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
6896                                    orderByComparator);
6897    
6898                    if (!list.isEmpty()) {
6899                            return list.get(0);
6900                    }
6901    
6902                    return null;
6903            }
6904    
6905            /**
6906             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6907             *
6908             * @param messageId the primary key of the current message-boards message
6909             * @param companyId the company ID
6910             * @param status the status
6911             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6912             * @return the previous, current, and next message-boards message
6913             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6914             * @throws SystemException if a system exception occurred
6915             */
6916            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
6917                    int status, OrderByComparator orderByComparator)
6918                    throws NoSuchMessageException, SystemException {
6919                    MBMessage mbMessage = findByPrimaryKey(messageId);
6920    
6921                    Session session = null;
6922    
6923                    try {
6924                            session = openSession();
6925    
6926                            MBMessage[] array = new MBMessageImpl[3];
6927    
6928                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6929                                            status, orderByComparator, true);
6930    
6931                            array[1] = mbMessage;
6932    
6933                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6934                                            status, orderByComparator, false);
6935    
6936                            return array;
6937                    }
6938                    catch (Exception e) {
6939                            throw processException(e);
6940                    }
6941                    finally {
6942                            closeSession(session);
6943                    }
6944            }
6945    
6946            protected MBMessage getByC_S_PrevAndNext(Session session,
6947                    MBMessage mbMessage, long companyId, int status,
6948                    OrderByComparator orderByComparator, boolean previous) {
6949                    StringBundler query = null;
6950    
6951                    if (orderByComparator != null) {
6952                            query = new StringBundler(6 +
6953                                            (orderByComparator.getOrderByFields().length * 6));
6954                    }
6955                    else {
6956                            query = new StringBundler(3);
6957                    }
6958    
6959                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6960    
6961                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6962    
6963                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
6964    
6965                    if (orderByComparator != null) {
6966                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6967    
6968                            if (orderByConditionFields.length > 0) {
6969                                    query.append(WHERE_AND);
6970                            }
6971    
6972                            for (int i = 0; i < orderByConditionFields.length; i++) {
6973                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6974                                    query.append(orderByConditionFields[i]);
6975    
6976                                    if ((i + 1) < orderByConditionFields.length) {
6977                                            if (orderByComparator.isAscending() ^ previous) {
6978                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6979                                            }
6980                                            else {
6981                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6982                                            }
6983                                    }
6984                                    else {
6985                                            if (orderByComparator.isAscending() ^ previous) {
6986                                                    query.append(WHERE_GREATER_THAN);
6987                                            }
6988                                            else {
6989                                                    query.append(WHERE_LESSER_THAN);
6990                                            }
6991                                    }
6992                            }
6993    
6994                            query.append(ORDER_BY_CLAUSE);
6995    
6996                            String[] orderByFields = orderByComparator.getOrderByFields();
6997    
6998                            for (int i = 0; i < orderByFields.length; i++) {
6999                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7000                                    query.append(orderByFields[i]);
7001    
7002                                    if ((i + 1) < orderByFields.length) {
7003                                            if (orderByComparator.isAscending() ^ previous) {
7004                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7005                                            }
7006                                            else {
7007                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7008                                            }
7009                                    }
7010                                    else {
7011                                            if (orderByComparator.isAscending() ^ previous) {
7012                                                    query.append(ORDER_BY_ASC);
7013                                            }
7014                                            else {
7015                                                    query.append(ORDER_BY_DESC);
7016                                            }
7017                                    }
7018                            }
7019                    }
7020    
7021                    else {
7022                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7023                    }
7024    
7025                    String sql = query.toString();
7026    
7027                    Query q = session.createQuery(sql);
7028    
7029                    q.setFirstResult(0);
7030                    q.setMaxResults(2);
7031    
7032                    QueryPos qPos = QueryPos.getInstance(q);
7033    
7034                    qPos.add(companyId);
7035    
7036                    qPos.add(status);
7037    
7038                    if (orderByComparator != null) {
7039                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7040    
7041                            for (Object value : values) {
7042                                    qPos.add(value);
7043                            }
7044                    }
7045    
7046                    List<MBMessage> list = q.list();
7047    
7048                    if (list.size() == 2) {
7049                            return list.get(1);
7050                    }
7051                    else {
7052                            return null;
7053                    }
7054            }
7055    
7056            /**
7057             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7058             *
7059             * @param userId the user ID
7060             * @param classNameId the class name ID
7061             * @return the matching message-boards messages
7062             * @throws SystemException if a system exception occurred
7063             */
7064            public List<MBMessage> findByU_C(long userId, long classNameId)
7065                    throws SystemException {
7066                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7067                            QueryUtil.ALL_POS, null);
7068            }
7069    
7070            /**
7071             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7072             *
7073             * <p>
7074             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7075             * </p>
7076             *
7077             * @param userId the user ID
7078             * @param classNameId the class name ID
7079             * @param start the lower bound of the range of message-boards messages
7080             * @param end the upper bound of the range of message-boards messages (not inclusive)
7081             * @return the range of matching message-boards messages
7082             * @throws SystemException if a system exception occurred
7083             */
7084            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7085                    int end) throws SystemException {
7086                    return findByU_C(userId, classNameId, start, end, null);
7087            }
7088    
7089            /**
7090             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7091             *
7092             * <p>
7093             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7094             * </p>
7095             *
7096             * @param userId the user ID
7097             * @param classNameId the class name ID
7098             * @param start the lower bound of the range of message-boards messages
7099             * @param end the upper bound of the range of message-boards messages (not inclusive)
7100             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7101             * @return the ordered range of matching message-boards messages
7102             * @throws SystemException if a system exception occurred
7103             */
7104            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7105                    int end, OrderByComparator orderByComparator) throws SystemException {
7106                    FinderPath finderPath = null;
7107                    Object[] finderArgs = null;
7108    
7109                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7110                                    (orderByComparator == null)) {
7111                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7112                            finderArgs = new Object[] { userId, classNameId };
7113                    }
7114                    else {
7115                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7116                            finderArgs = new Object[] {
7117                                            userId, classNameId,
7118                                            
7119                                            start, end, orderByComparator
7120                                    };
7121                    }
7122    
7123                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7124                                    finderArgs, this);
7125    
7126                    if ((list != null) && !list.isEmpty()) {
7127                            for (MBMessage mbMessage : list) {
7128                                    if ((userId != mbMessage.getUserId()) ||
7129                                                    (classNameId != mbMessage.getClassNameId())) {
7130                                            list = null;
7131    
7132                                            break;
7133                                    }
7134                            }
7135                    }
7136    
7137                    if (list == null) {
7138                            StringBundler query = null;
7139    
7140                            if (orderByComparator != null) {
7141                                    query = new StringBundler(4 +
7142                                                    (orderByComparator.getOrderByFields().length * 3));
7143                            }
7144                            else {
7145                                    query = new StringBundler(4);
7146                            }
7147    
7148                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7149    
7150                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7151    
7152                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7153    
7154                            if (orderByComparator != null) {
7155                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7156                                            orderByComparator);
7157                            }
7158    
7159                            else {
7160                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7161                            }
7162    
7163                            String sql = query.toString();
7164    
7165                            Session session = null;
7166    
7167                            try {
7168                                    session = openSession();
7169    
7170                                    Query q = session.createQuery(sql);
7171    
7172                                    QueryPos qPos = QueryPos.getInstance(q);
7173    
7174                                    qPos.add(userId);
7175    
7176                                    qPos.add(classNameId);
7177    
7178                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7179                                                    end);
7180                            }
7181                            catch (Exception e) {
7182                                    throw processException(e);
7183                            }
7184                            finally {
7185                                    if (list == null) {
7186                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7187                                    }
7188                                    else {
7189                                            cacheResult(list);
7190    
7191                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7192                                    }
7193    
7194                                    closeSession(session);
7195                            }
7196                    }
7197    
7198                    return list;
7199            }
7200    
7201            /**
7202             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7203             *
7204             * @param userId the user ID
7205             * @param classNameId the class name ID
7206             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7207             * @return the first matching message-boards message
7208             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7209             * @throws SystemException if a system exception occurred
7210             */
7211            public MBMessage findByU_C_First(long userId, long classNameId,
7212                    OrderByComparator orderByComparator)
7213                    throws NoSuchMessageException, SystemException {
7214                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7215                                    orderByComparator);
7216    
7217                    if (mbMessage != null) {
7218                            return mbMessage;
7219                    }
7220    
7221                    StringBundler msg = new StringBundler(6);
7222    
7223                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7224    
7225                    msg.append("userId=");
7226                    msg.append(userId);
7227    
7228                    msg.append(", classNameId=");
7229                    msg.append(classNameId);
7230    
7231                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7232    
7233                    throw new NoSuchMessageException(msg.toString());
7234            }
7235    
7236            /**
7237             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7238             *
7239             * @param userId the user ID
7240             * @param classNameId the class name ID
7241             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7242             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7243             * @throws SystemException if a system exception occurred
7244             */
7245            public MBMessage fetchByU_C_First(long userId, long classNameId,
7246                    OrderByComparator orderByComparator) throws SystemException {
7247                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7248                                    orderByComparator);
7249    
7250                    if (!list.isEmpty()) {
7251                            return list.get(0);
7252                    }
7253    
7254                    return null;
7255            }
7256    
7257            /**
7258             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7259             *
7260             * @param userId the user ID
7261             * @param classNameId the class name ID
7262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7263             * @return the last matching message-boards message
7264             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7265             * @throws SystemException if a system exception occurred
7266             */
7267            public MBMessage findByU_C_Last(long userId, long classNameId,
7268                    OrderByComparator orderByComparator)
7269                    throws NoSuchMessageException, SystemException {
7270                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7271                                    orderByComparator);
7272    
7273                    if (mbMessage != null) {
7274                            return mbMessage;
7275                    }
7276    
7277                    StringBundler msg = new StringBundler(6);
7278    
7279                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7280    
7281                    msg.append("userId=");
7282                    msg.append(userId);
7283    
7284                    msg.append(", classNameId=");
7285                    msg.append(classNameId);
7286    
7287                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7288    
7289                    throw new NoSuchMessageException(msg.toString());
7290            }
7291    
7292            /**
7293             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7294             *
7295             * @param userId the user ID
7296             * @param classNameId the class name ID
7297             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7298             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7299             * @throws SystemException if a system exception occurred
7300             */
7301            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7302                    OrderByComparator orderByComparator) throws SystemException {
7303                    int count = countByU_C(userId, classNameId);
7304    
7305                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7306                                    orderByComparator);
7307    
7308                    if (!list.isEmpty()) {
7309                            return list.get(0);
7310                    }
7311    
7312                    return null;
7313            }
7314    
7315            /**
7316             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7317             *
7318             * @param messageId the primary key of the current message-boards message
7319             * @param userId the user ID
7320             * @param classNameId the class name ID
7321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7322             * @return the previous, current, and next message-boards message
7323             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7324             * @throws SystemException if a system exception occurred
7325             */
7326            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7327                    long classNameId, OrderByComparator orderByComparator)
7328                    throws NoSuchMessageException, SystemException {
7329                    MBMessage mbMessage = findByPrimaryKey(messageId);
7330    
7331                    Session session = null;
7332    
7333                    try {
7334                            session = openSession();
7335    
7336                            MBMessage[] array = new MBMessageImpl[3];
7337    
7338                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7339                                            classNameId, orderByComparator, true);
7340    
7341                            array[1] = mbMessage;
7342    
7343                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7344                                            classNameId, orderByComparator, false);
7345    
7346                            return array;
7347                    }
7348                    catch (Exception e) {
7349                            throw processException(e);
7350                    }
7351                    finally {
7352                            closeSession(session);
7353                    }
7354            }
7355    
7356            protected MBMessage getByU_C_PrevAndNext(Session session,
7357                    MBMessage mbMessage, long userId, long classNameId,
7358                    OrderByComparator orderByComparator, boolean previous) {
7359                    StringBundler query = null;
7360    
7361                    if (orderByComparator != null) {
7362                            query = new StringBundler(6 +
7363                                            (orderByComparator.getOrderByFields().length * 6));
7364                    }
7365                    else {
7366                            query = new StringBundler(3);
7367                    }
7368    
7369                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7370    
7371                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7372    
7373                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7374    
7375                    if (orderByComparator != null) {
7376                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7377    
7378                            if (orderByConditionFields.length > 0) {
7379                                    query.append(WHERE_AND);
7380                            }
7381    
7382                            for (int i = 0; i < orderByConditionFields.length; i++) {
7383                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7384                                    query.append(orderByConditionFields[i]);
7385    
7386                                    if ((i + 1) < orderByConditionFields.length) {
7387                                            if (orderByComparator.isAscending() ^ previous) {
7388                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7389                                            }
7390                                            else {
7391                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7392                                            }
7393                                    }
7394                                    else {
7395                                            if (orderByComparator.isAscending() ^ previous) {
7396                                                    query.append(WHERE_GREATER_THAN);
7397                                            }
7398                                            else {
7399                                                    query.append(WHERE_LESSER_THAN);
7400                                            }
7401                                    }
7402                            }
7403    
7404                            query.append(ORDER_BY_CLAUSE);
7405    
7406                            String[] orderByFields = orderByComparator.getOrderByFields();
7407    
7408                            for (int i = 0; i < orderByFields.length; i++) {
7409                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7410                                    query.append(orderByFields[i]);
7411    
7412                                    if ((i + 1) < orderByFields.length) {
7413                                            if (orderByComparator.isAscending() ^ previous) {
7414                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7415                                            }
7416                                            else {
7417                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7418                                            }
7419                                    }
7420                                    else {
7421                                            if (orderByComparator.isAscending() ^ previous) {
7422                                                    query.append(ORDER_BY_ASC);
7423                                            }
7424                                            else {
7425                                                    query.append(ORDER_BY_DESC);
7426                                            }
7427                                    }
7428                            }
7429                    }
7430    
7431                    else {
7432                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7433                    }
7434    
7435                    String sql = query.toString();
7436    
7437                    Query q = session.createQuery(sql);
7438    
7439                    q.setFirstResult(0);
7440                    q.setMaxResults(2);
7441    
7442                    QueryPos qPos = QueryPos.getInstance(q);
7443    
7444                    qPos.add(userId);
7445    
7446                    qPos.add(classNameId);
7447    
7448                    if (orderByComparator != null) {
7449                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7450    
7451                            for (Object value : values) {
7452                                    qPos.add(value);
7453                            }
7454                    }
7455    
7456                    List<MBMessage> list = q.list();
7457    
7458                    if (list.size() == 2) {
7459                            return list.get(1);
7460                    }
7461                    else {
7462                            return null;
7463                    }
7464            }
7465    
7466            /**
7467             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7468             *
7469             * <p>
7470             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7471             * </p>
7472             *
7473             * @param userId the user ID
7474             * @param classNameIds the class name IDs
7475             * @return the matching message-boards messages
7476             * @throws SystemException if a system exception occurred
7477             */
7478            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7479                    throws SystemException {
7480                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7481                            QueryUtil.ALL_POS, null);
7482            }
7483    
7484            /**
7485             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7486             *
7487             * <p>
7488             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7489             * </p>
7490             *
7491             * @param userId the user ID
7492             * @param classNameIds the class name IDs
7493             * @param start the lower bound of the range of message-boards messages
7494             * @param end the upper bound of the range of message-boards messages (not inclusive)
7495             * @return the range of matching message-boards messages
7496             * @throws SystemException if a system exception occurred
7497             */
7498            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7499                    int start, int end) throws SystemException {
7500                    return findByU_C(userId, classNameIds, start, end, null);
7501            }
7502    
7503            /**
7504             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7505             *
7506             * <p>
7507             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7508             * </p>
7509             *
7510             * @param userId the user ID
7511             * @param classNameIds the class name IDs
7512             * @param start the lower bound of the range of message-boards messages
7513             * @param end the upper bound of the range of message-boards messages (not inclusive)
7514             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7515             * @return the ordered range of matching message-boards messages
7516             * @throws SystemException if a system exception occurred
7517             */
7518            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7519                    int start, int end, OrderByComparator orderByComparator)
7520                    throws SystemException {
7521                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7522                    Object[] finderArgs = null;
7523    
7524                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7525                                    (orderByComparator == null)) {
7526                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7527                    }
7528                    else {
7529                            finderArgs = new Object[] {
7530                                            userId, StringUtil.merge(classNameIds),
7531                                            
7532                                            start, end, orderByComparator
7533                                    };
7534                    }
7535    
7536                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7537                                    finderArgs, this);
7538    
7539                    if ((list != null) && !list.isEmpty()) {
7540                            for (MBMessage mbMessage : list) {
7541                                    if ((userId != mbMessage.getUserId()) ||
7542                                                    !ArrayUtil.contains(classNameIds,
7543                                                            mbMessage.getClassNameId())) {
7544                                            list = null;
7545    
7546                                            break;
7547                                    }
7548                            }
7549                    }
7550    
7551                    if (list == null) {
7552                            StringBundler query = new StringBundler();
7553    
7554                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7555    
7556                            boolean conjunctionable = false;
7557    
7558                            if (conjunctionable) {
7559                                    query.append(WHERE_AND);
7560                            }
7561    
7562                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7563    
7564                            conjunctionable = true;
7565    
7566                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7567                                    if (conjunctionable) {
7568                                            query.append(WHERE_AND);
7569                                    }
7570    
7571                                    query.append(StringPool.OPEN_PARENTHESIS);
7572    
7573                                    for (int i = 0; i < classNameIds.length; i++) {
7574                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7575    
7576                                            if ((i + 1) < classNameIds.length) {
7577                                                    query.append(WHERE_OR);
7578                                            }
7579                                    }
7580    
7581                                    query.append(StringPool.CLOSE_PARENTHESIS);
7582    
7583                                    conjunctionable = true;
7584                            }
7585    
7586                            if (orderByComparator != null) {
7587                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7588                                            orderByComparator);
7589                            }
7590    
7591                            else {
7592                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7593                            }
7594    
7595                            String sql = query.toString();
7596    
7597                            Session session = null;
7598    
7599                            try {
7600                                    session = openSession();
7601    
7602                                    Query q = session.createQuery(sql);
7603    
7604                                    QueryPos qPos = QueryPos.getInstance(q);
7605    
7606                                    qPos.add(userId);
7607    
7608                                    if (classNameIds != null) {
7609                                            qPos.add(classNameIds);
7610                                    }
7611    
7612                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7613                                                    end);
7614                            }
7615                            catch (Exception e) {
7616                                    throw processException(e);
7617                            }
7618                            finally {
7619                                    if (list == null) {
7620                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7621                                    }
7622                                    else {
7623                                            cacheResult(list);
7624    
7625                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7626                                    }
7627    
7628                                    closeSession(session);
7629                            }
7630                    }
7631    
7632                    return list;
7633            }
7634    
7635            /**
7636             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7637             *
7638             * @param classNameId the class name ID
7639             * @param classPK the class p k
7640             * @return the matching message-boards messages
7641             * @throws SystemException if a system exception occurred
7642             */
7643            public List<MBMessage> findByC_C(long classNameId, long classPK)
7644                    throws SystemException {
7645                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
7646                            QueryUtil.ALL_POS, null);
7647            }
7648    
7649            /**
7650             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7651             *
7652             * <p>
7653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7654             * </p>
7655             *
7656             * @param classNameId the class name ID
7657             * @param classPK the class p k
7658             * @param start the lower bound of the range of message-boards messages
7659             * @param end the upper bound of the range of message-boards messages (not inclusive)
7660             * @return the range of matching message-boards messages
7661             * @throws SystemException if a system exception occurred
7662             */
7663            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7664                    int end) throws SystemException {
7665                    return findByC_C(classNameId, classPK, start, end, null);
7666            }
7667    
7668            /**
7669             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7670             *
7671             * <p>
7672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7673             * </p>
7674             *
7675             * @param classNameId the class name ID
7676             * @param classPK the class p k
7677             * @param start the lower bound of the range of message-boards messages
7678             * @param end the upper bound of the range of message-boards messages (not inclusive)
7679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7680             * @return the ordered range of matching message-boards messages
7681             * @throws SystemException if a system exception occurred
7682             */
7683            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7684                    int end, OrderByComparator orderByComparator) throws SystemException {
7685                    FinderPath finderPath = null;
7686                    Object[] finderArgs = null;
7687    
7688                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7689                                    (orderByComparator == null)) {
7690                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
7691                            finderArgs = new Object[] { classNameId, classPK };
7692                    }
7693                    else {
7694                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
7695                            finderArgs = new Object[] {
7696                                            classNameId, classPK,
7697                                            
7698                                            start, end, orderByComparator
7699                                    };
7700                    }
7701    
7702                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7703                                    finderArgs, this);
7704    
7705                    if ((list != null) && !list.isEmpty()) {
7706                            for (MBMessage mbMessage : list) {
7707                                    if ((classNameId != mbMessage.getClassNameId()) ||
7708                                                    (classPK != mbMessage.getClassPK())) {
7709                                            list = null;
7710    
7711                                            break;
7712                                    }
7713                            }
7714                    }
7715    
7716                    if (list == null) {
7717                            StringBundler query = null;
7718    
7719                            if (orderByComparator != null) {
7720                                    query = new StringBundler(4 +
7721                                                    (orderByComparator.getOrderByFields().length * 3));
7722                            }
7723                            else {
7724                                    query = new StringBundler(4);
7725                            }
7726    
7727                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7728    
7729                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7730    
7731                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7732    
7733                            if (orderByComparator != null) {
7734                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7735                                            orderByComparator);
7736                            }
7737    
7738                            else {
7739                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7740                            }
7741    
7742                            String sql = query.toString();
7743    
7744                            Session session = null;
7745    
7746                            try {
7747                                    session = openSession();
7748    
7749                                    Query q = session.createQuery(sql);
7750    
7751                                    QueryPos qPos = QueryPos.getInstance(q);
7752    
7753                                    qPos.add(classNameId);
7754    
7755                                    qPos.add(classPK);
7756    
7757                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7758                                                    end);
7759                            }
7760                            catch (Exception e) {
7761                                    throw processException(e);
7762                            }
7763                            finally {
7764                                    if (list == null) {
7765                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7766                                    }
7767                                    else {
7768                                            cacheResult(list);
7769    
7770                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7771                                    }
7772    
7773                                    closeSession(session);
7774                            }
7775                    }
7776    
7777                    return list;
7778            }
7779    
7780            /**
7781             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7782             *
7783             * @param classNameId the class name ID
7784             * @param classPK the class p k
7785             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7786             * @return the first matching message-boards message
7787             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7788             * @throws SystemException if a system exception occurred
7789             */
7790            public MBMessage findByC_C_First(long classNameId, long classPK,
7791                    OrderByComparator orderByComparator)
7792                    throws NoSuchMessageException, SystemException {
7793                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
7794                                    orderByComparator);
7795    
7796                    if (mbMessage != null) {
7797                            return mbMessage;
7798                    }
7799    
7800                    StringBundler msg = new StringBundler(6);
7801    
7802                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7803    
7804                    msg.append("classNameId=");
7805                    msg.append(classNameId);
7806    
7807                    msg.append(", classPK=");
7808                    msg.append(classPK);
7809    
7810                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7811    
7812                    throw new NoSuchMessageException(msg.toString());
7813            }
7814    
7815            /**
7816             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7817             *
7818             * @param classNameId the class name ID
7819             * @param classPK the class p k
7820             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7821             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7822             * @throws SystemException if a system exception occurred
7823             */
7824            public MBMessage fetchByC_C_First(long classNameId, long classPK,
7825                    OrderByComparator orderByComparator) throws SystemException {
7826                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
7827                                    orderByComparator);
7828    
7829                    if (!list.isEmpty()) {
7830                            return list.get(0);
7831                    }
7832    
7833                    return null;
7834            }
7835    
7836            /**
7837             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7838             *
7839             * @param classNameId the class name ID
7840             * @param classPK the class p k
7841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7842             * @return the last matching message-boards message
7843             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7844             * @throws SystemException if a system exception occurred
7845             */
7846            public MBMessage findByC_C_Last(long classNameId, long classPK,
7847                    OrderByComparator orderByComparator)
7848                    throws NoSuchMessageException, SystemException {
7849                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
7850                                    orderByComparator);
7851    
7852                    if (mbMessage != null) {
7853                            return mbMessage;
7854                    }
7855    
7856                    StringBundler msg = new StringBundler(6);
7857    
7858                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7859    
7860                    msg.append("classNameId=");
7861                    msg.append(classNameId);
7862    
7863                    msg.append(", classPK=");
7864                    msg.append(classPK);
7865    
7866                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7867    
7868                    throw new NoSuchMessageException(msg.toString());
7869            }
7870    
7871            /**
7872             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7873             *
7874             * @param classNameId the class name ID
7875             * @param classPK the class p k
7876             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7877             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7878             * @throws SystemException if a system exception occurred
7879             */
7880            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
7881                    OrderByComparator orderByComparator) throws SystemException {
7882                    int count = countByC_C(classNameId, classPK);
7883    
7884                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
7885                                    count, orderByComparator);
7886    
7887                    if (!list.isEmpty()) {
7888                            return list.get(0);
7889                    }
7890    
7891                    return null;
7892            }
7893    
7894            /**
7895             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7896             *
7897             * @param messageId the primary key of the current message-boards message
7898             * @param classNameId the class name ID
7899             * @param classPK the class p k
7900             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7901             * @return the previous, current, and next message-boards message
7902             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7903             * @throws SystemException if a system exception occurred
7904             */
7905            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
7906                    long classPK, OrderByComparator orderByComparator)
7907                    throws NoSuchMessageException, SystemException {
7908                    MBMessage mbMessage = findByPrimaryKey(messageId);
7909    
7910                    Session session = null;
7911    
7912                    try {
7913                            session = openSession();
7914    
7915                            MBMessage[] array = new MBMessageImpl[3];
7916    
7917                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7918                                            classPK, orderByComparator, true);
7919    
7920                            array[1] = mbMessage;
7921    
7922                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7923                                            classPK, orderByComparator, false);
7924    
7925                            return array;
7926                    }
7927                    catch (Exception e) {
7928                            throw processException(e);
7929                    }
7930                    finally {
7931                            closeSession(session);
7932                    }
7933            }
7934    
7935            protected MBMessage getByC_C_PrevAndNext(Session session,
7936                    MBMessage mbMessage, long classNameId, long classPK,
7937                    OrderByComparator orderByComparator, boolean previous) {
7938                    StringBundler query = null;
7939    
7940                    if (orderByComparator != null) {
7941                            query = new StringBundler(6 +
7942                                            (orderByComparator.getOrderByFields().length * 6));
7943                    }
7944                    else {
7945                            query = new StringBundler(3);
7946                    }
7947    
7948                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7949    
7950                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7951    
7952                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7953    
7954                    if (orderByComparator != null) {
7955                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7956    
7957                            if (orderByConditionFields.length > 0) {
7958                                    query.append(WHERE_AND);
7959                            }
7960    
7961                            for (int i = 0; i < orderByConditionFields.length; i++) {
7962                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7963                                    query.append(orderByConditionFields[i]);
7964    
7965                                    if ((i + 1) < orderByConditionFields.length) {
7966                                            if (orderByComparator.isAscending() ^ previous) {
7967                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7968                                            }
7969                                            else {
7970                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7971                                            }
7972                                    }
7973                                    else {
7974                                            if (orderByComparator.isAscending() ^ previous) {
7975                                                    query.append(WHERE_GREATER_THAN);
7976                                            }
7977                                            else {
7978                                                    query.append(WHERE_LESSER_THAN);
7979                                            }
7980                                    }
7981                            }
7982    
7983                            query.append(ORDER_BY_CLAUSE);
7984    
7985                            String[] orderByFields = orderByComparator.getOrderByFields();
7986    
7987                            for (int i = 0; i < orderByFields.length; i++) {
7988                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7989                                    query.append(orderByFields[i]);
7990    
7991                                    if ((i + 1) < orderByFields.length) {
7992                                            if (orderByComparator.isAscending() ^ previous) {
7993                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7994                                            }
7995                                            else {
7996                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7997                                            }
7998                                    }
7999                                    else {
8000                                            if (orderByComparator.isAscending() ^ previous) {
8001                                                    query.append(ORDER_BY_ASC);
8002                                            }
8003                                            else {
8004                                                    query.append(ORDER_BY_DESC);
8005                                            }
8006                                    }
8007                            }
8008                    }
8009    
8010                    else {
8011                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8012                    }
8013    
8014                    String sql = query.toString();
8015    
8016                    Query q = session.createQuery(sql);
8017    
8018                    q.setFirstResult(0);
8019                    q.setMaxResults(2);
8020    
8021                    QueryPos qPos = QueryPos.getInstance(q);
8022    
8023                    qPos.add(classNameId);
8024    
8025                    qPos.add(classPK);
8026    
8027                    if (orderByComparator != null) {
8028                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8029    
8030                            for (Object value : values) {
8031                                    qPos.add(value);
8032                            }
8033                    }
8034    
8035                    List<MBMessage> list = q.list();
8036    
8037                    if (list.size() == 2) {
8038                            return list.get(1);
8039                    }
8040                    else {
8041                            return null;
8042                    }
8043            }
8044    
8045            /**
8046             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8047             *
8048             * @param threadId the thread ID
8049             * @param parentMessageId the parent message ID
8050             * @return the matching message-boards messages
8051             * @throws SystemException if a system exception occurred
8052             */
8053            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8054                    throws SystemException {
8055                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8056                            QueryUtil.ALL_POS, null);
8057            }
8058    
8059            /**
8060             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8061             *
8062             * <p>
8063             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8064             * </p>
8065             *
8066             * @param threadId the thread ID
8067             * @param parentMessageId the parent message ID
8068             * @param start the lower bound of the range of message-boards messages
8069             * @param end the upper bound of the range of message-boards messages (not inclusive)
8070             * @return the range of matching message-boards messages
8071             * @throws SystemException if a system exception occurred
8072             */
8073            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8074                    int start, int end) throws SystemException {
8075                    return findByT_P(threadId, parentMessageId, start, end, null);
8076            }
8077    
8078            /**
8079             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8080             *
8081             * <p>
8082             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8083             * </p>
8084             *
8085             * @param threadId the thread ID
8086             * @param parentMessageId the parent message ID
8087             * @param start the lower bound of the range of message-boards messages
8088             * @param end the upper bound of the range of message-boards messages (not inclusive)
8089             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8090             * @return the ordered range of matching message-boards messages
8091             * @throws SystemException if a system exception occurred
8092             */
8093            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8094                    int start, int end, OrderByComparator orderByComparator)
8095                    throws SystemException {
8096                    FinderPath finderPath = null;
8097                    Object[] finderArgs = null;
8098    
8099                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8100                                    (orderByComparator == null)) {
8101                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8102                            finderArgs = new Object[] { threadId, parentMessageId };
8103                    }
8104                    else {
8105                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8106                            finderArgs = new Object[] {
8107                                            threadId, parentMessageId,
8108                                            
8109                                            start, end, orderByComparator
8110                                    };
8111                    }
8112    
8113                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8114                                    finderArgs, this);
8115    
8116                    if ((list != null) && !list.isEmpty()) {
8117                            for (MBMessage mbMessage : list) {
8118                                    if ((threadId != mbMessage.getThreadId()) ||
8119                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8120                                            list = null;
8121    
8122                                            break;
8123                                    }
8124                            }
8125                    }
8126    
8127                    if (list == null) {
8128                            StringBundler query = null;
8129    
8130                            if (orderByComparator != null) {
8131                                    query = new StringBundler(4 +
8132                                                    (orderByComparator.getOrderByFields().length * 3));
8133                            }
8134                            else {
8135                                    query = new StringBundler(4);
8136                            }
8137    
8138                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8139    
8140                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8141    
8142                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8143    
8144                            if (orderByComparator != null) {
8145                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8146                                            orderByComparator);
8147                            }
8148    
8149                            else {
8150                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8151                            }
8152    
8153                            String sql = query.toString();
8154    
8155                            Session session = null;
8156    
8157                            try {
8158                                    session = openSession();
8159    
8160                                    Query q = session.createQuery(sql);
8161    
8162                                    QueryPos qPos = QueryPos.getInstance(q);
8163    
8164                                    qPos.add(threadId);
8165    
8166                                    qPos.add(parentMessageId);
8167    
8168                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8169                                                    end);
8170                            }
8171                            catch (Exception e) {
8172                                    throw processException(e);
8173                            }
8174                            finally {
8175                                    if (list == null) {
8176                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8177                                    }
8178                                    else {
8179                                            cacheResult(list);
8180    
8181                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8182                                    }
8183    
8184                                    closeSession(session);
8185                            }
8186                    }
8187    
8188                    return list;
8189            }
8190    
8191            /**
8192             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8193             *
8194             * @param threadId the thread ID
8195             * @param parentMessageId the parent message ID
8196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8197             * @return the first matching message-boards message
8198             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8199             * @throws SystemException if a system exception occurred
8200             */
8201            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8202                    OrderByComparator orderByComparator)
8203                    throws NoSuchMessageException, SystemException {
8204                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8205                                    orderByComparator);
8206    
8207                    if (mbMessage != null) {
8208                            return mbMessage;
8209                    }
8210    
8211                    StringBundler msg = new StringBundler(6);
8212    
8213                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8214    
8215                    msg.append("threadId=");
8216                    msg.append(threadId);
8217    
8218                    msg.append(", parentMessageId=");
8219                    msg.append(parentMessageId);
8220    
8221                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8222    
8223                    throw new NoSuchMessageException(msg.toString());
8224            }
8225    
8226            /**
8227             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8228             *
8229             * @param threadId the thread ID
8230             * @param parentMessageId the parent message ID
8231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8232             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8233             * @throws SystemException if a system exception occurred
8234             */
8235            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8236                    OrderByComparator orderByComparator) throws SystemException {
8237                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8238                                    orderByComparator);
8239    
8240                    if (!list.isEmpty()) {
8241                            return list.get(0);
8242                    }
8243    
8244                    return null;
8245            }
8246    
8247            /**
8248             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8249             *
8250             * @param threadId the thread ID
8251             * @param parentMessageId the parent message ID
8252             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8253             * @return the last matching message-boards message
8254             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8255             * @throws SystemException if a system exception occurred
8256             */
8257            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8258                    OrderByComparator orderByComparator)
8259                    throws NoSuchMessageException, SystemException {
8260                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8261                                    orderByComparator);
8262    
8263                    if (mbMessage != null) {
8264                            return mbMessage;
8265                    }
8266    
8267                    StringBundler msg = new StringBundler(6);
8268    
8269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8270    
8271                    msg.append("threadId=");
8272                    msg.append(threadId);
8273    
8274                    msg.append(", parentMessageId=");
8275                    msg.append(parentMessageId);
8276    
8277                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8278    
8279                    throw new NoSuchMessageException(msg.toString());
8280            }
8281    
8282            /**
8283             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8284             *
8285             * @param threadId the thread ID
8286             * @param parentMessageId the parent message ID
8287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8288             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8289             * @throws SystemException if a system exception occurred
8290             */
8291            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8292                    OrderByComparator orderByComparator) throws SystemException {
8293                    int count = countByT_P(threadId, parentMessageId);
8294    
8295                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8296                                    count, orderByComparator);
8297    
8298                    if (!list.isEmpty()) {
8299                            return list.get(0);
8300                    }
8301    
8302                    return null;
8303            }
8304    
8305            /**
8306             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8307             *
8308             * @param messageId the primary key of the current message-boards message
8309             * @param threadId the thread ID
8310             * @param parentMessageId the parent message ID
8311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8312             * @return the previous, current, and next message-boards message
8313             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8314             * @throws SystemException if a system exception occurred
8315             */
8316            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8317                    long parentMessageId, OrderByComparator orderByComparator)
8318                    throws NoSuchMessageException, SystemException {
8319                    MBMessage mbMessage = findByPrimaryKey(messageId);
8320    
8321                    Session session = null;
8322    
8323                    try {
8324                            session = openSession();
8325    
8326                            MBMessage[] array = new MBMessageImpl[3];
8327    
8328                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8329                                            parentMessageId, orderByComparator, true);
8330    
8331                            array[1] = mbMessage;
8332    
8333                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8334                                            parentMessageId, orderByComparator, false);
8335    
8336                            return array;
8337                    }
8338                    catch (Exception e) {
8339                            throw processException(e);
8340                    }
8341                    finally {
8342                            closeSession(session);
8343                    }
8344            }
8345    
8346            protected MBMessage getByT_P_PrevAndNext(Session session,
8347                    MBMessage mbMessage, long threadId, long parentMessageId,
8348                    OrderByComparator orderByComparator, boolean previous) {
8349                    StringBundler query = null;
8350    
8351                    if (orderByComparator != null) {
8352                            query = new StringBundler(6 +
8353                                            (orderByComparator.getOrderByFields().length * 6));
8354                    }
8355                    else {
8356                            query = new StringBundler(3);
8357                    }
8358    
8359                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8360    
8361                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8362    
8363                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8364    
8365                    if (orderByComparator != null) {
8366                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8367    
8368                            if (orderByConditionFields.length > 0) {
8369                                    query.append(WHERE_AND);
8370                            }
8371    
8372                            for (int i = 0; i < orderByConditionFields.length; i++) {
8373                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8374                                    query.append(orderByConditionFields[i]);
8375    
8376                                    if ((i + 1) < orderByConditionFields.length) {
8377                                            if (orderByComparator.isAscending() ^ previous) {
8378                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8379                                            }
8380                                            else {
8381                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8382                                            }
8383                                    }
8384                                    else {
8385                                            if (orderByComparator.isAscending() ^ previous) {
8386                                                    query.append(WHERE_GREATER_THAN);
8387                                            }
8388                                            else {
8389                                                    query.append(WHERE_LESSER_THAN);
8390                                            }
8391                                    }
8392                            }
8393    
8394                            query.append(ORDER_BY_CLAUSE);
8395    
8396                            String[] orderByFields = orderByComparator.getOrderByFields();
8397    
8398                            for (int i = 0; i < orderByFields.length; i++) {
8399                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8400                                    query.append(orderByFields[i]);
8401    
8402                                    if ((i + 1) < orderByFields.length) {
8403                                            if (orderByComparator.isAscending() ^ previous) {
8404                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8405                                            }
8406                                            else {
8407                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8408                                            }
8409                                    }
8410                                    else {
8411                                            if (orderByComparator.isAscending() ^ previous) {
8412                                                    query.append(ORDER_BY_ASC);
8413                                            }
8414                                            else {
8415                                                    query.append(ORDER_BY_DESC);
8416                                            }
8417                                    }
8418                            }
8419                    }
8420    
8421                    else {
8422                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8423                    }
8424    
8425                    String sql = query.toString();
8426    
8427                    Query q = session.createQuery(sql);
8428    
8429                    q.setFirstResult(0);
8430                    q.setMaxResults(2);
8431    
8432                    QueryPos qPos = QueryPos.getInstance(q);
8433    
8434                    qPos.add(threadId);
8435    
8436                    qPos.add(parentMessageId);
8437    
8438                    if (orderByComparator != null) {
8439                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8440    
8441                            for (Object value : values) {
8442                                    qPos.add(value);
8443                            }
8444                    }
8445    
8446                    List<MBMessage> list = q.list();
8447    
8448                    if (list.size() == 2) {
8449                            return list.get(1);
8450                    }
8451                    else {
8452                            return null;
8453                    }
8454            }
8455    
8456            /**
8457             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
8458             *
8459             * @param threadId the thread ID
8460             * @param answer the answer
8461             * @return the matching message-boards messages
8462             * @throws SystemException if a system exception occurred
8463             */
8464            public List<MBMessage> findByT_A(long threadId, boolean answer)
8465                    throws SystemException {
8466                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
8467                            QueryUtil.ALL_POS, null);
8468            }
8469    
8470            /**
8471             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8472             *
8473             * <p>
8474             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8475             * </p>
8476             *
8477             * @param threadId the thread ID
8478             * @param answer the answer
8479             * @param start the lower bound of the range of message-boards messages
8480             * @param end the upper bound of the range of message-boards messages (not inclusive)
8481             * @return the range of matching message-boards messages
8482             * @throws SystemException if a system exception occurred
8483             */
8484            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8485                    int end) throws SystemException {
8486                    return findByT_A(threadId, answer, start, end, null);
8487            }
8488    
8489            /**
8490             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8491             *
8492             * <p>
8493             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8494             * </p>
8495             *
8496             * @param threadId the thread ID
8497             * @param answer the answer
8498             * @param start the lower bound of the range of message-boards messages
8499             * @param end the upper bound of the range of message-boards messages (not inclusive)
8500             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8501             * @return the ordered range of matching message-boards messages
8502             * @throws SystemException if a system exception occurred
8503             */
8504            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8505                    int end, OrderByComparator orderByComparator) throws SystemException {
8506                    FinderPath finderPath = null;
8507                    Object[] finderArgs = null;
8508    
8509                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8510                                    (orderByComparator == null)) {
8511                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
8512                            finderArgs = new Object[] { threadId, answer };
8513                    }
8514                    else {
8515                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
8516                            finderArgs = new Object[] {
8517                                            threadId, answer,
8518                                            
8519                                            start, end, orderByComparator
8520                                    };
8521                    }
8522    
8523                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8524                                    finderArgs, this);
8525    
8526                    if ((list != null) && !list.isEmpty()) {
8527                            for (MBMessage mbMessage : list) {
8528                                    if ((threadId != mbMessage.getThreadId()) ||
8529                                                    (answer != mbMessage.getAnswer())) {
8530                                            list = null;
8531    
8532                                            break;
8533                                    }
8534                            }
8535                    }
8536    
8537                    if (list == null) {
8538                            StringBundler query = null;
8539    
8540                            if (orderByComparator != null) {
8541                                    query = new StringBundler(4 +
8542                                                    (orderByComparator.getOrderByFields().length * 3));
8543                            }
8544                            else {
8545                                    query = new StringBundler(4);
8546                            }
8547    
8548                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8549    
8550                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
8551    
8552                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8553    
8554                            if (orderByComparator != null) {
8555                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8556                                            orderByComparator);
8557                            }
8558    
8559                            else {
8560                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8561                            }
8562    
8563                            String sql = query.toString();
8564    
8565                            Session session = null;
8566    
8567                            try {
8568                                    session = openSession();
8569    
8570                                    Query q = session.createQuery(sql);
8571    
8572                                    QueryPos qPos = QueryPos.getInstance(q);
8573    
8574                                    qPos.add(threadId);
8575    
8576                                    qPos.add(answer);
8577    
8578                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8579                                                    end);
8580                            }
8581                            catch (Exception e) {
8582                                    throw processException(e);
8583                            }
8584                            finally {
8585                                    if (list == null) {
8586                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8587                                    }
8588                                    else {
8589                                            cacheResult(list);
8590    
8591                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8592                                    }
8593    
8594                                    closeSession(session);
8595                            }
8596                    }
8597    
8598                    return list;
8599            }
8600    
8601            /**
8602             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8603             *
8604             * @param threadId the thread ID
8605             * @param answer the answer
8606             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8607             * @return the first matching message-boards message
8608             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8609             * @throws SystemException if a system exception occurred
8610             */
8611            public MBMessage findByT_A_First(long threadId, boolean answer,
8612                    OrderByComparator orderByComparator)
8613                    throws NoSuchMessageException, SystemException {
8614                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
8615                                    orderByComparator);
8616    
8617                    if (mbMessage != null) {
8618                            return mbMessage;
8619                    }
8620    
8621                    StringBundler msg = new StringBundler(6);
8622    
8623                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8624    
8625                    msg.append("threadId=");
8626                    msg.append(threadId);
8627    
8628                    msg.append(", answer=");
8629                    msg.append(answer);
8630    
8631                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8632    
8633                    throw new NoSuchMessageException(msg.toString());
8634            }
8635    
8636            /**
8637             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8638             *
8639             * @param threadId the thread ID
8640             * @param answer the answer
8641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8642             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8643             * @throws SystemException if a system exception occurred
8644             */
8645            public MBMessage fetchByT_A_First(long threadId, boolean answer,
8646                    OrderByComparator orderByComparator) throws SystemException {
8647                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
8648                                    orderByComparator);
8649    
8650                    if (!list.isEmpty()) {
8651                            return list.get(0);
8652                    }
8653    
8654                    return null;
8655            }
8656    
8657            /**
8658             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8659             *
8660             * @param threadId the thread ID
8661             * @param answer the answer
8662             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8663             * @return the last matching message-boards message
8664             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8665             * @throws SystemException if a system exception occurred
8666             */
8667            public MBMessage findByT_A_Last(long threadId, boolean answer,
8668                    OrderByComparator orderByComparator)
8669                    throws NoSuchMessageException, SystemException {
8670                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
8671                                    orderByComparator);
8672    
8673                    if (mbMessage != null) {
8674                            return mbMessage;
8675                    }
8676    
8677                    StringBundler msg = new StringBundler(6);
8678    
8679                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8680    
8681                    msg.append("threadId=");
8682                    msg.append(threadId);
8683    
8684                    msg.append(", answer=");
8685                    msg.append(answer);
8686    
8687                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8688    
8689                    throw new NoSuchMessageException(msg.toString());
8690            }
8691    
8692            /**
8693             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8694             *
8695             * @param threadId the thread ID
8696             * @param answer the answer
8697             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8698             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8699             * @throws SystemException if a system exception occurred
8700             */
8701            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
8702                    OrderByComparator orderByComparator) throws SystemException {
8703                    int count = countByT_A(threadId, answer);
8704    
8705                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
8706                                    orderByComparator);
8707    
8708                    if (!list.isEmpty()) {
8709                            return list.get(0);
8710                    }
8711    
8712                    return null;
8713            }
8714    
8715            /**
8716             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8717             *
8718             * @param messageId the primary key of the current message-boards message
8719             * @param threadId the thread ID
8720             * @param answer the answer
8721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8722             * @return the previous, current, and next message-boards message
8723             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8724             * @throws SystemException if a system exception occurred
8725             */
8726            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
8727                    boolean answer, OrderByComparator orderByComparator)
8728                    throws NoSuchMessageException, SystemException {
8729                    MBMessage mbMessage = findByPrimaryKey(messageId);
8730    
8731                    Session session = null;
8732    
8733                    try {
8734                            session = openSession();
8735    
8736                            MBMessage[] array = new MBMessageImpl[3];
8737    
8738                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8739                                            answer, orderByComparator, true);
8740    
8741                            array[1] = mbMessage;
8742    
8743                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8744                                            answer, orderByComparator, false);
8745    
8746                            return array;
8747                    }
8748                    catch (Exception e) {
8749                            throw processException(e);
8750                    }
8751                    finally {
8752                            closeSession(session);
8753                    }
8754            }
8755    
8756            protected MBMessage getByT_A_PrevAndNext(Session session,
8757                    MBMessage mbMessage, long threadId, boolean answer,
8758                    OrderByComparator orderByComparator, boolean previous) {
8759                    StringBundler query = null;
8760    
8761                    if (orderByComparator != null) {
8762                            query = new StringBundler(6 +
8763                                            (orderByComparator.getOrderByFields().length * 6));
8764                    }
8765                    else {
8766                            query = new StringBundler(3);
8767                    }
8768    
8769                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8770    
8771                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
8772    
8773                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8774    
8775                    if (orderByComparator != null) {
8776                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8777    
8778                            if (orderByConditionFields.length > 0) {
8779                                    query.append(WHERE_AND);
8780                            }
8781    
8782                            for (int i = 0; i < orderByConditionFields.length; i++) {
8783                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8784                                    query.append(orderByConditionFields[i]);
8785    
8786                                    if ((i + 1) < orderByConditionFields.length) {
8787                                            if (orderByComparator.isAscending() ^ previous) {
8788                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8789                                            }
8790                                            else {
8791                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8792                                            }
8793                                    }
8794                                    else {
8795                                            if (orderByComparator.isAscending() ^ previous) {
8796                                                    query.append(WHERE_GREATER_THAN);
8797                                            }
8798                                            else {
8799                                                    query.append(WHERE_LESSER_THAN);
8800                                            }
8801                                    }
8802                            }
8803    
8804                            query.append(ORDER_BY_CLAUSE);
8805    
8806                            String[] orderByFields = orderByComparator.getOrderByFields();
8807    
8808                            for (int i = 0; i < orderByFields.length; i++) {
8809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8810                                    query.append(orderByFields[i]);
8811    
8812                                    if ((i + 1) < orderByFields.length) {
8813                                            if (orderByComparator.isAscending() ^ previous) {
8814                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8815                                            }
8816                                            else {
8817                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8818                                            }
8819                                    }
8820                                    else {
8821                                            if (orderByComparator.isAscending() ^ previous) {
8822                                                    query.append(ORDER_BY_ASC);
8823                                            }
8824                                            else {
8825                                                    query.append(ORDER_BY_DESC);
8826                                            }
8827                                    }
8828                            }
8829                    }
8830    
8831                    else {
8832                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8833                    }
8834    
8835                    String sql = query.toString();
8836    
8837                    Query q = session.createQuery(sql);
8838    
8839                    q.setFirstResult(0);
8840                    q.setMaxResults(2);
8841    
8842                    QueryPos qPos = QueryPos.getInstance(q);
8843    
8844                    qPos.add(threadId);
8845    
8846                    qPos.add(answer);
8847    
8848                    if (orderByComparator != null) {
8849                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8850    
8851                            for (Object value : values) {
8852                                    qPos.add(value);
8853                            }
8854                    }
8855    
8856                    List<MBMessage> list = q.list();
8857    
8858                    if (list.size() == 2) {
8859                            return list.get(1);
8860                    }
8861                    else {
8862                            return null;
8863                    }
8864            }
8865    
8866            /**
8867             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
8868             *
8869             * @param threadId the thread ID
8870             * @param status the status
8871             * @return the matching message-boards messages
8872             * @throws SystemException if a system exception occurred
8873             */
8874            public List<MBMessage> findByT_S(long threadId, int status)
8875                    throws SystemException {
8876                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
8877                            QueryUtil.ALL_POS, null);
8878            }
8879    
8880            /**
8881             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
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 threadId the thread ID
8888             * @param status the status
8889             * @param start the lower bound of the range of message-boards messages
8890             * @param end the upper bound of the range of message-boards messages (not inclusive)
8891             * @return the range of matching message-boards messages
8892             * @throws SystemException if a system exception occurred
8893             */
8894            public List<MBMessage> findByT_S(long threadId, int status, int start,
8895                    int end) throws SystemException {
8896                    return findByT_S(threadId, status, start, end, null);
8897            }
8898    
8899            /**
8900             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
8901             *
8902             * <p>
8903             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8904             * </p>
8905             *
8906             * @param threadId the thread ID
8907             * @param status the status
8908             * @param start the lower bound of the range of message-boards messages
8909             * @param end the upper bound of the range of message-boards messages (not inclusive)
8910             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8911             * @return the ordered range of matching message-boards messages
8912             * @throws SystemException if a system exception occurred
8913             */
8914            public List<MBMessage> findByT_S(long threadId, int status, int start,
8915                    int end, OrderByComparator orderByComparator) throws SystemException {
8916                    FinderPath finderPath = null;
8917                    Object[] finderArgs = null;
8918    
8919                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8920                                    (orderByComparator == null)) {
8921                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
8922                            finderArgs = new Object[] { threadId, status };
8923                    }
8924                    else {
8925                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
8926                            finderArgs = new Object[] {
8927                                            threadId, status,
8928                                            
8929                                            start, end, orderByComparator
8930                                    };
8931                    }
8932    
8933                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8934                                    finderArgs, this);
8935    
8936                    if ((list != null) && !list.isEmpty()) {
8937                            for (MBMessage mbMessage : list) {
8938                                    if ((threadId != mbMessage.getThreadId()) ||
8939                                                    (status != mbMessage.getStatus())) {
8940                                            list = null;
8941    
8942                                            break;
8943                                    }
8944                            }
8945                    }
8946    
8947                    if (list == null) {
8948                            StringBundler query = null;
8949    
8950                            if (orderByComparator != null) {
8951                                    query = new StringBundler(4 +
8952                                                    (orderByComparator.getOrderByFields().length * 3));
8953                            }
8954                            else {
8955                                    query = new StringBundler(4);
8956                            }
8957    
8958                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8959    
8960                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
8961    
8962                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
8963    
8964                            if (orderByComparator != null) {
8965                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8966                                            orderByComparator);
8967                            }
8968    
8969                            else {
8970                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8971                            }
8972    
8973                            String sql = query.toString();
8974    
8975                            Session session = null;
8976    
8977                            try {
8978                                    session = openSession();
8979    
8980                                    Query q = session.createQuery(sql);
8981    
8982                                    QueryPos qPos = QueryPos.getInstance(q);
8983    
8984                                    qPos.add(threadId);
8985    
8986                                    qPos.add(status);
8987    
8988                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8989                                                    end);
8990                            }
8991                            catch (Exception e) {
8992                                    throw processException(e);
8993                            }
8994                            finally {
8995                                    if (list == null) {
8996                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8997                                    }
8998                                    else {
8999                                            cacheResult(list);
9000    
9001                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9002                                    }
9003    
9004                                    closeSession(session);
9005                            }
9006                    }
9007    
9008                    return list;
9009            }
9010    
9011            /**
9012             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9013             *
9014             * @param threadId the thread ID
9015             * @param status the status
9016             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9017             * @return the first matching message-boards message
9018             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9019             * @throws SystemException if a system exception occurred
9020             */
9021            public MBMessage findByT_S_First(long threadId, int status,
9022                    OrderByComparator orderByComparator)
9023                    throws NoSuchMessageException, SystemException {
9024                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9025                                    orderByComparator);
9026    
9027                    if (mbMessage != null) {
9028                            return mbMessage;
9029                    }
9030    
9031                    StringBundler msg = new StringBundler(6);
9032    
9033                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9034    
9035                    msg.append("threadId=");
9036                    msg.append(threadId);
9037    
9038                    msg.append(", status=");
9039                    msg.append(status);
9040    
9041                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9042    
9043                    throw new NoSuchMessageException(msg.toString());
9044            }
9045    
9046            /**
9047             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9048             *
9049             * @param threadId the thread ID
9050             * @param status the status
9051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9052             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9053             * @throws SystemException if a system exception occurred
9054             */
9055            public MBMessage fetchByT_S_First(long threadId, int status,
9056                    OrderByComparator orderByComparator) throws SystemException {
9057                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9058                                    orderByComparator);
9059    
9060                    if (!list.isEmpty()) {
9061                            return list.get(0);
9062                    }
9063    
9064                    return null;
9065            }
9066    
9067            /**
9068             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9069             *
9070             * @param threadId the thread ID
9071             * @param status the status
9072             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9073             * @return the last matching message-boards message
9074             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9075             * @throws SystemException if a system exception occurred
9076             */
9077            public MBMessage findByT_S_Last(long threadId, int status,
9078                    OrderByComparator orderByComparator)
9079                    throws NoSuchMessageException, SystemException {
9080                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9081                                    orderByComparator);
9082    
9083                    if (mbMessage != null) {
9084                            return mbMessage;
9085                    }
9086    
9087                    StringBundler msg = new StringBundler(6);
9088    
9089                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9090    
9091                    msg.append("threadId=");
9092                    msg.append(threadId);
9093    
9094                    msg.append(", status=");
9095                    msg.append(status);
9096    
9097                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9098    
9099                    throw new NoSuchMessageException(msg.toString());
9100            }
9101    
9102            /**
9103             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9104             *
9105             * @param threadId the thread ID
9106             * @param status the status
9107             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9108             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9109             * @throws SystemException if a system exception occurred
9110             */
9111            public MBMessage fetchByT_S_Last(long threadId, int status,
9112                    OrderByComparator orderByComparator) throws SystemException {
9113                    int count = countByT_S(threadId, status);
9114    
9115                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9116                                    orderByComparator);
9117    
9118                    if (!list.isEmpty()) {
9119                            return list.get(0);
9120                    }
9121    
9122                    return null;
9123            }
9124    
9125            /**
9126             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9127             *
9128             * @param messageId the primary key of the current message-boards message
9129             * @param threadId the thread ID
9130             * @param status the status
9131             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9132             * @return the previous, current, and next message-boards message
9133             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9134             * @throws SystemException if a system exception occurred
9135             */
9136            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9137                    int status, OrderByComparator orderByComparator)
9138                    throws NoSuchMessageException, SystemException {
9139                    MBMessage mbMessage = findByPrimaryKey(messageId);
9140    
9141                    Session session = null;
9142    
9143                    try {
9144                            session = openSession();
9145    
9146                            MBMessage[] array = new MBMessageImpl[3];
9147    
9148                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9149                                            status, orderByComparator, true);
9150    
9151                            array[1] = mbMessage;
9152    
9153                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9154                                            status, orderByComparator, false);
9155    
9156                            return array;
9157                    }
9158                    catch (Exception e) {
9159                            throw processException(e);
9160                    }
9161                    finally {
9162                            closeSession(session);
9163                    }
9164            }
9165    
9166            protected MBMessage getByT_S_PrevAndNext(Session session,
9167                    MBMessage mbMessage, long threadId, int status,
9168                    OrderByComparator orderByComparator, boolean previous) {
9169                    StringBundler query = null;
9170    
9171                    if (orderByComparator != null) {
9172                            query = new StringBundler(6 +
9173                                            (orderByComparator.getOrderByFields().length * 6));
9174                    }
9175                    else {
9176                            query = new StringBundler(3);
9177                    }
9178    
9179                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9180    
9181                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
9182    
9183                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
9184    
9185                    if (orderByComparator != null) {
9186                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9187    
9188                            if (orderByConditionFields.length > 0) {
9189                                    query.append(WHERE_AND);
9190                            }
9191    
9192                            for (int i = 0; i < orderByConditionFields.length; i++) {
9193                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9194                                    query.append(orderByConditionFields[i]);
9195    
9196                                    if ((i + 1) < orderByConditionFields.length) {
9197                                            if (orderByComparator.isAscending() ^ previous) {
9198                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9199                                            }
9200                                            else {
9201                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9202                                            }
9203                                    }
9204                                    else {
9205                                            if (orderByComparator.isAscending() ^ previous) {
9206                                                    query.append(WHERE_GREATER_THAN);
9207                                            }
9208                                            else {
9209                                                    query.append(WHERE_LESSER_THAN);
9210                                            }
9211                                    }
9212                            }
9213    
9214                            query.append(ORDER_BY_CLAUSE);
9215    
9216                            String[] orderByFields = orderByComparator.getOrderByFields();
9217    
9218                            for (int i = 0; i < orderByFields.length; i++) {
9219                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9220                                    query.append(orderByFields[i]);
9221    
9222                                    if ((i + 1) < orderByFields.length) {
9223                                            if (orderByComparator.isAscending() ^ previous) {
9224                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9225                                            }
9226                                            else {
9227                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9228                                            }
9229                                    }
9230                                    else {
9231                                            if (orderByComparator.isAscending() ^ previous) {
9232                                                    query.append(ORDER_BY_ASC);
9233                                            }
9234                                            else {
9235                                                    query.append(ORDER_BY_DESC);
9236                                            }
9237                                    }
9238                            }
9239                    }
9240    
9241                    else {
9242                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9243                    }
9244    
9245                    String sql = query.toString();
9246    
9247                    Query q = session.createQuery(sql);
9248    
9249                    q.setFirstResult(0);
9250                    q.setMaxResults(2);
9251    
9252                    QueryPos qPos = QueryPos.getInstance(q);
9253    
9254                    qPos.add(threadId);
9255    
9256                    qPos.add(status);
9257    
9258                    if (orderByComparator != null) {
9259                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9260    
9261                            for (Object value : values) {
9262                                    qPos.add(value);
9263                            }
9264                    }
9265    
9266                    List<MBMessage> list = q.list();
9267    
9268                    if (list.size() == 2) {
9269                            return list.get(1);
9270                    }
9271                    else {
9272                            return null;
9273                    }
9274            }
9275    
9276            /**
9277             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9278             *
9279             * @param threadId the thread ID
9280             * @param status the status
9281             * @return the matching message-boards messages
9282             * @throws SystemException if a system exception occurred
9283             */
9284            public List<MBMessage> findByTR_S(long threadId, int status)
9285                    throws SystemException {
9286                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
9287                            QueryUtil.ALL_POS, null);
9288            }
9289    
9290            /**
9291             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9292             *
9293             * <p>
9294             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9295             * </p>
9296             *
9297             * @param threadId the thread ID
9298             * @param status the status
9299             * @param start the lower bound of the range of message-boards messages
9300             * @param end the upper bound of the range of message-boards messages (not inclusive)
9301             * @return the range of matching message-boards messages
9302             * @throws SystemException if a system exception occurred
9303             */
9304            public List<MBMessage> findByTR_S(long threadId, int status, int start,
9305                    int end) throws SystemException {
9306                    return findByTR_S(threadId, status, start, end, null);
9307            }
9308    
9309            /**
9310             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9311             *
9312             * <p>
9313             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9314             * </p>
9315             *
9316             * @param threadId the thread ID
9317             * @param status the status
9318             * @param start the lower bound of the range of message-boards messages
9319             * @param end the upper bound of the range of message-boards messages (not inclusive)
9320             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9321             * @return the ordered range of matching message-boards messages
9322             * @throws SystemException if a system exception occurred
9323             */
9324            public List<MBMessage> findByTR_S(long threadId, int status, int start,
9325                    int end, OrderByComparator orderByComparator) throws SystemException {
9326                    FinderPath finderPath = null;
9327                    Object[] finderArgs = null;
9328    
9329                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9330                                    (orderByComparator == null)) {
9331                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
9332                            finderArgs = new Object[] { threadId, status };
9333                    }
9334                    else {
9335                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
9336                            finderArgs = new Object[] {
9337                                            threadId, status,
9338                                            
9339                                            start, end, orderByComparator
9340                                    };
9341                    }
9342    
9343                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9344                                    finderArgs, this);
9345    
9346                    if ((list != null) && !list.isEmpty()) {
9347                            for (MBMessage mbMessage : list) {
9348                                    if ((threadId != mbMessage.getThreadId()) ||
9349                                                    (status != mbMessage.getStatus())) {
9350                                            list = null;
9351    
9352                                            break;
9353                                    }
9354                            }
9355                    }
9356    
9357                    if (list == null) {
9358                            StringBundler query = null;
9359    
9360                            if (orderByComparator != null) {
9361                                    query = new StringBundler(4 +
9362                                                    (orderByComparator.getOrderByFields().length * 3));
9363                            }
9364                            else {
9365                                    query = new StringBundler(4);
9366                            }
9367    
9368                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9369    
9370                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
9371    
9372                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
9373    
9374                            if (orderByComparator != null) {
9375                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9376                                            orderByComparator);
9377                            }
9378    
9379                            else {
9380                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9381                            }
9382    
9383                            String sql = query.toString();
9384    
9385                            Session session = null;
9386    
9387                            try {
9388                                    session = openSession();
9389    
9390                                    Query q = session.createQuery(sql);
9391    
9392                                    QueryPos qPos = QueryPos.getInstance(q);
9393    
9394                                    qPos.add(threadId);
9395    
9396                                    qPos.add(status);
9397    
9398                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9399                                                    end);
9400                            }
9401                            catch (Exception e) {
9402                                    throw processException(e);
9403                            }
9404                            finally {
9405                                    if (list == null) {
9406                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9407                                    }
9408                                    else {
9409                                            cacheResult(list);
9410    
9411                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9412                                    }
9413    
9414                                    closeSession(session);
9415                            }
9416                    }
9417    
9418                    return list;
9419            }
9420    
9421            /**
9422             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9423             *
9424             * @param threadId the thread ID
9425             * @param status the status
9426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9427             * @return the first matching message-boards message
9428             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9429             * @throws SystemException if a system exception occurred
9430             */
9431            public MBMessage findByTR_S_First(long threadId, int status,
9432                    OrderByComparator orderByComparator)
9433                    throws NoSuchMessageException, SystemException {
9434                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
9435                                    orderByComparator);
9436    
9437                    if (mbMessage != null) {
9438                            return mbMessage;
9439                    }
9440    
9441                    StringBundler msg = new StringBundler(6);
9442    
9443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9444    
9445                    msg.append("threadId=");
9446                    msg.append(threadId);
9447    
9448                    msg.append(", status=");
9449                    msg.append(status);
9450    
9451                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9452    
9453                    throw new NoSuchMessageException(msg.toString());
9454            }
9455    
9456            /**
9457             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9458             *
9459             * @param threadId the thread ID
9460             * @param status the status
9461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9462             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9463             * @throws SystemException if a system exception occurred
9464             */
9465            public MBMessage fetchByTR_S_First(long threadId, int status,
9466                    OrderByComparator orderByComparator) throws SystemException {
9467                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
9468                                    orderByComparator);
9469    
9470                    if (!list.isEmpty()) {
9471                            return list.get(0);
9472                    }
9473    
9474                    return null;
9475            }
9476    
9477            /**
9478             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9479             *
9480             * @param threadId the thread ID
9481             * @param status the status
9482             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9483             * @return the last matching message-boards message
9484             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9485             * @throws SystemException if a system exception occurred
9486             */
9487            public MBMessage findByTR_S_Last(long threadId, int status,
9488                    OrderByComparator orderByComparator)
9489                    throws NoSuchMessageException, SystemException {
9490                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
9491                                    orderByComparator);
9492    
9493                    if (mbMessage != null) {
9494                            return mbMessage;
9495                    }
9496    
9497                    StringBundler msg = new StringBundler(6);
9498    
9499                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9500    
9501                    msg.append("threadId=");
9502                    msg.append(threadId);
9503    
9504                    msg.append(", status=");
9505                    msg.append(status);
9506    
9507                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9508    
9509                    throw new NoSuchMessageException(msg.toString());
9510            }
9511    
9512            /**
9513             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9514             *
9515             * @param threadId the thread ID
9516             * @param status the status
9517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9518             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9519             * @throws SystemException if a system exception occurred
9520             */
9521            public MBMessage fetchByTR_S_Last(long threadId, int status,
9522                    OrderByComparator orderByComparator) throws SystemException {
9523                    int count = countByTR_S(threadId, status);
9524    
9525                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
9526                                    orderByComparator);
9527    
9528                    if (!list.isEmpty()) {
9529                            return list.get(0);
9530                    }
9531    
9532                    return null;
9533            }
9534    
9535            /**
9536             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9537             *
9538             * @param messageId the primary key of the current message-boards message
9539             * @param threadId the thread ID
9540             * @param status the status
9541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9542             * @return the previous, current, and next message-boards message
9543             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9544             * @throws SystemException if a system exception occurred
9545             */
9546            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
9547                    int status, OrderByComparator orderByComparator)
9548                    throws NoSuchMessageException, SystemException {
9549                    MBMessage mbMessage = findByPrimaryKey(messageId);
9550    
9551                    Session session = null;
9552    
9553                    try {
9554                            session = openSession();
9555    
9556                            MBMessage[] array = new MBMessageImpl[3];
9557    
9558                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
9559                                            status, orderByComparator, true);
9560    
9561                            array[1] = mbMessage;
9562    
9563                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
9564                                            status, orderByComparator, false);
9565    
9566                            return array;
9567                    }
9568                    catch (Exception e) {
9569                            throw processException(e);
9570                    }
9571                    finally {
9572                            closeSession(session);
9573                    }
9574            }
9575    
9576            protected MBMessage getByTR_S_PrevAndNext(Session session,
9577                    MBMessage mbMessage, long threadId, int status,
9578                    OrderByComparator orderByComparator, boolean previous) {
9579                    StringBundler query = null;
9580    
9581                    if (orderByComparator != null) {
9582                            query = new StringBundler(6 +
9583                                            (orderByComparator.getOrderByFields().length * 6));
9584                    }
9585                    else {
9586                            query = new StringBundler(3);
9587                    }
9588    
9589                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9590    
9591                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
9592    
9593                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
9594    
9595                    if (orderByComparator != null) {
9596                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9597    
9598                            if (orderByConditionFields.length > 0) {
9599                                    query.append(WHERE_AND);
9600                            }
9601    
9602                            for (int i = 0; i < orderByConditionFields.length; i++) {
9603                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9604                                    query.append(orderByConditionFields[i]);
9605    
9606                                    if ((i + 1) < orderByConditionFields.length) {
9607                                            if (orderByComparator.isAscending() ^ previous) {
9608                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9609                                            }
9610                                            else {
9611                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9612                                            }
9613                                    }
9614                                    else {
9615                                            if (orderByComparator.isAscending() ^ previous) {
9616                                                    query.append(WHERE_GREATER_THAN);
9617                                            }
9618                                            else {
9619                                                    query.append(WHERE_LESSER_THAN);
9620                                            }
9621                                    }
9622                            }
9623    
9624                            query.append(ORDER_BY_CLAUSE);
9625    
9626                            String[] orderByFields = orderByComparator.getOrderByFields();
9627    
9628                            for (int i = 0; i < orderByFields.length; i++) {
9629                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9630                                    query.append(orderByFields[i]);
9631    
9632                                    if ((i + 1) < orderByFields.length) {
9633                                            if (orderByComparator.isAscending() ^ previous) {
9634                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9635                                            }
9636                                            else {
9637                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9638                                            }
9639                                    }
9640                                    else {
9641                                            if (orderByComparator.isAscending() ^ previous) {
9642                                                    query.append(ORDER_BY_ASC);
9643                                            }
9644                                            else {
9645                                                    query.append(ORDER_BY_DESC);
9646                                            }
9647                                    }
9648                            }
9649                    }
9650    
9651                    else {
9652                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9653                    }
9654    
9655                    String sql = query.toString();
9656    
9657                    Query q = session.createQuery(sql);
9658    
9659                    q.setFirstResult(0);
9660                    q.setMaxResults(2);
9661    
9662                    QueryPos qPos = QueryPos.getInstance(q);
9663    
9664                    qPos.add(threadId);
9665    
9666                    qPos.add(status);
9667    
9668                    if (orderByComparator != null) {
9669                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9670    
9671                            for (Object value : values) {
9672                                    qPos.add(value);
9673                            }
9674                    }
9675    
9676                    List<MBMessage> list = q.list();
9677    
9678                    if (list.size() == 2) {
9679                            return list.get(1);
9680                    }
9681                    else {
9682                            return null;
9683                    }
9684            }
9685    
9686            /**
9687             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9688             *
9689             * @param groupId the group ID
9690             * @param userId the user ID
9691             * @param status the status
9692             * @return the matching message-boards messages
9693             * @throws SystemException if a system exception occurred
9694             */
9695            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
9696                    throws SystemException {
9697                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
9698                            QueryUtil.ALL_POS, null);
9699            }
9700    
9701            /**
9702             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9703             *
9704             * <p>
9705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9706             * </p>
9707             *
9708             * @param groupId the group ID
9709             * @param userId the user ID
9710             * @param status the status
9711             * @param start the lower bound of the range of message-boards messages
9712             * @param end the upper bound of the range of message-boards messages (not inclusive)
9713             * @return the range of matching message-boards messages
9714             * @throws SystemException if a system exception occurred
9715             */
9716            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
9717                    int start, int end) throws SystemException {
9718                    return findByG_U_S(groupId, userId, status, start, end, null);
9719            }
9720    
9721            /**
9722             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9723             *
9724             * <p>
9725             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9726             * </p>
9727             *
9728             * @param groupId the group ID
9729             * @param userId the user ID
9730             * @param status the status
9731             * @param start the lower bound of the range of message-boards messages
9732             * @param end the upper bound of the range of message-boards messages (not inclusive)
9733             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9734             * @return the ordered range of matching message-boards messages
9735             * @throws SystemException if a system exception occurred
9736             */
9737            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
9738                    int start, int end, OrderByComparator orderByComparator)
9739                    throws SystemException {
9740                    FinderPath finderPath = null;
9741                    Object[] finderArgs = null;
9742    
9743                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9744                                    (orderByComparator == null)) {
9745                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
9746                            finderArgs = new Object[] { groupId, userId, status };
9747                    }
9748                    else {
9749                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
9750                            finderArgs = new Object[] {
9751                                            groupId, userId, status,
9752                                            
9753                                            start, end, orderByComparator
9754                                    };
9755                    }
9756    
9757                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9758                                    finderArgs, this);
9759    
9760                    if ((list != null) && !list.isEmpty()) {
9761                            for (MBMessage mbMessage : list) {
9762                                    if ((groupId != mbMessage.getGroupId()) ||
9763                                                    (userId != mbMessage.getUserId()) ||
9764                                                    (status != mbMessage.getStatus())) {
9765                                            list = null;
9766    
9767                                            break;
9768                                    }
9769                            }
9770                    }
9771    
9772                    if (list == null) {
9773                            StringBundler query = null;
9774    
9775                            if (orderByComparator != null) {
9776                                    query = new StringBundler(5 +
9777                                                    (orderByComparator.getOrderByFields().length * 3));
9778                            }
9779                            else {
9780                                    query = new StringBundler(5);
9781                            }
9782    
9783                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9784    
9785                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9786    
9787                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9788    
9789                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9790    
9791                            if (orderByComparator != null) {
9792                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9793                                            orderByComparator);
9794                            }
9795    
9796                            else {
9797                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9798                            }
9799    
9800                            String sql = query.toString();
9801    
9802                            Session session = null;
9803    
9804                            try {
9805                                    session = openSession();
9806    
9807                                    Query q = session.createQuery(sql);
9808    
9809                                    QueryPos qPos = QueryPos.getInstance(q);
9810    
9811                                    qPos.add(groupId);
9812    
9813                                    qPos.add(userId);
9814    
9815                                    qPos.add(status);
9816    
9817                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9818                                                    end);
9819                            }
9820                            catch (Exception e) {
9821                                    throw processException(e);
9822                            }
9823                            finally {
9824                                    if (list == null) {
9825                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9826                                    }
9827                                    else {
9828                                            cacheResult(list);
9829    
9830                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9831                                    }
9832    
9833                                    closeSession(session);
9834                            }
9835                    }
9836    
9837                    return list;
9838            }
9839    
9840            /**
9841             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9842             *
9843             * @param groupId the group ID
9844             * @param userId the user ID
9845             * @param status the status
9846             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9847             * @return the first matching message-boards message
9848             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9849             * @throws SystemException if a system exception occurred
9850             */
9851            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
9852                    OrderByComparator orderByComparator)
9853                    throws NoSuchMessageException, SystemException {
9854                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
9855                                    orderByComparator);
9856    
9857                    if (mbMessage != null) {
9858                            return mbMessage;
9859                    }
9860    
9861                    StringBundler msg = new StringBundler(8);
9862    
9863                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9864    
9865                    msg.append("groupId=");
9866                    msg.append(groupId);
9867    
9868                    msg.append(", userId=");
9869                    msg.append(userId);
9870    
9871                    msg.append(", status=");
9872                    msg.append(status);
9873    
9874                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9875    
9876                    throw new NoSuchMessageException(msg.toString());
9877            }
9878    
9879            /**
9880             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9881             *
9882             * @param groupId the group ID
9883             * @param userId the user ID
9884             * @param status the status
9885             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9886             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9887             * @throws SystemException if a system exception occurred
9888             */
9889            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
9890                    OrderByComparator orderByComparator) throws SystemException {
9891                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
9892                                    orderByComparator);
9893    
9894                    if (!list.isEmpty()) {
9895                            return list.get(0);
9896                    }
9897    
9898                    return null;
9899            }
9900    
9901            /**
9902             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9903             *
9904             * @param groupId the group ID
9905             * @param userId the user ID
9906             * @param status the status
9907             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9908             * @return the last matching message-boards message
9909             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9910             * @throws SystemException if a system exception occurred
9911             */
9912            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
9913                    OrderByComparator orderByComparator)
9914                    throws NoSuchMessageException, SystemException {
9915                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
9916                                    orderByComparator);
9917    
9918                    if (mbMessage != null) {
9919                            return mbMessage;
9920                    }
9921    
9922                    StringBundler msg = new StringBundler(8);
9923    
9924                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9925    
9926                    msg.append("groupId=");
9927                    msg.append(groupId);
9928    
9929                    msg.append(", userId=");
9930                    msg.append(userId);
9931    
9932                    msg.append(", status=");
9933                    msg.append(status);
9934    
9935                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9936    
9937                    throw new NoSuchMessageException(msg.toString());
9938            }
9939    
9940            /**
9941             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9942             *
9943             * @param groupId the group ID
9944             * @param userId the user ID
9945             * @param status the status
9946             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9947             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9948             * @throws SystemException if a system exception occurred
9949             */
9950            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
9951                    OrderByComparator orderByComparator) throws SystemException {
9952                    int count = countByG_U_S(groupId, userId, status);
9953    
9954                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
9955                                    count, orderByComparator);
9956    
9957                    if (!list.isEmpty()) {
9958                            return list.get(0);
9959                    }
9960    
9961                    return null;
9962            }
9963    
9964            /**
9965             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9966             *
9967             * @param messageId the primary key of the current message-boards message
9968             * @param groupId the group ID
9969             * @param userId the user ID
9970             * @param status the status
9971             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9972             * @return the previous, current, and next message-boards message
9973             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9974             * @throws SystemException if a system exception occurred
9975             */
9976            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
9977                    long userId, int status, OrderByComparator orderByComparator)
9978                    throws NoSuchMessageException, SystemException {
9979                    MBMessage mbMessage = findByPrimaryKey(messageId);
9980    
9981                    Session session = null;
9982    
9983                    try {
9984                            session = openSession();
9985    
9986                            MBMessage[] array = new MBMessageImpl[3];
9987    
9988                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9989                                            userId, status, orderByComparator, true);
9990    
9991                            array[1] = mbMessage;
9992    
9993                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9994                                            userId, status, orderByComparator, false);
9995    
9996                            return array;
9997                    }
9998                    catch (Exception e) {
9999                            throw processException(e);
10000                    }
10001                    finally {
10002                            closeSession(session);
10003                    }
10004            }
10005    
10006            protected MBMessage getByG_U_S_PrevAndNext(Session session,
10007                    MBMessage mbMessage, long groupId, long userId, int status,
10008                    OrderByComparator orderByComparator, boolean previous) {
10009                    StringBundler query = null;
10010    
10011                    if (orderByComparator != null) {
10012                            query = new StringBundler(6 +
10013                                            (orderByComparator.getOrderByFields().length * 6));
10014                    }
10015                    else {
10016                            query = new StringBundler(3);
10017                    }
10018    
10019                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10020    
10021                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10022    
10023                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10024    
10025                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10026    
10027                    if (orderByComparator != null) {
10028                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10029    
10030                            if (orderByConditionFields.length > 0) {
10031                                    query.append(WHERE_AND);
10032                            }
10033    
10034                            for (int i = 0; i < orderByConditionFields.length; i++) {
10035                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10036                                    query.append(orderByConditionFields[i]);
10037    
10038                                    if ((i + 1) < orderByConditionFields.length) {
10039                                            if (orderByComparator.isAscending() ^ previous) {
10040                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10041                                            }
10042                                            else {
10043                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10044                                            }
10045                                    }
10046                                    else {
10047                                            if (orderByComparator.isAscending() ^ previous) {
10048                                                    query.append(WHERE_GREATER_THAN);
10049                                            }
10050                                            else {
10051                                                    query.append(WHERE_LESSER_THAN);
10052                                            }
10053                                    }
10054                            }
10055    
10056                            query.append(ORDER_BY_CLAUSE);
10057    
10058                            String[] orderByFields = orderByComparator.getOrderByFields();
10059    
10060                            for (int i = 0; i < orderByFields.length; i++) {
10061                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10062                                    query.append(orderByFields[i]);
10063    
10064                                    if ((i + 1) < orderByFields.length) {
10065                                            if (orderByComparator.isAscending() ^ previous) {
10066                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10067                                            }
10068                                            else {
10069                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10070                                            }
10071                                    }
10072                                    else {
10073                                            if (orderByComparator.isAscending() ^ previous) {
10074                                                    query.append(ORDER_BY_ASC);
10075                                            }
10076                                            else {
10077                                                    query.append(ORDER_BY_DESC);
10078                                            }
10079                                    }
10080                            }
10081                    }
10082    
10083                    else {
10084                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10085                    }
10086    
10087                    String sql = query.toString();
10088    
10089                    Query q = session.createQuery(sql);
10090    
10091                    q.setFirstResult(0);
10092                    q.setMaxResults(2);
10093    
10094                    QueryPos qPos = QueryPos.getInstance(q);
10095    
10096                    qPos.add(groupId);
10097    
10098                    qPos.add(userId);
10099    
10100                    qPos.add(status);
10101    
10102                    if (orderByComparator != null) {
10103                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10104    
10105                            for (Object value : values) {
10106                                    qPos.add(value);
10107                            }
10108                    }
10109    
10110                    List<MBMessage> list = q.list();
10111    
10112                    if (list.size() == 2) {
10113                            return list.get(1);
10114                    }
10115                    else {
10116                            return null;
10117                    }
10118            }
10119    
10120            /**
10121             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
10122             *
10123             * @param groupId the group ID
10124             * @param userId the user ID
10125             * @param status the status
10126             * @return the matching message-boards messages that the user has permission to view
10127             * @throws SystemException if a system exception occurred
10128             */
10129            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10130                    int status) throws SystemException {
10131                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10132                            QueryUtil.ALL_POS, null);
10133            }
10134    
10135            /**
10136             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
10137             *
10138             * <p>
10139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10140             * </p>
10141             *
10142             * @param groupId the group ID
10143             * @param userId the user ID
10144             * @param status the status
10145             * @param start the lower bound of the range of message-boards messages
10146             * @param end the upper bound of the range of message-boards messages (not inclusive)
10147             * @return the range of matching message-boards messages that the user has permission to view
10148             * @throws SystemException if a system exception occurred
10149             */
10150            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10151                    int status, int start, int end) throws SystemException {
10152                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
10153            }
10154    
10155            /**
10156             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63; and status = &#63;.
10157             *
10158             * <p>
10159             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10160             * </p>
10161             *
10162             * @param groupId the group ID
10163             * @param userId the user ID
10164             * @param status the status
10165             * @param start the lower bound of the range of message-boards messages
10166             * @param end the upper bound of the range of message-boards messages (not inclusive)
10167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10168             * @return the ordered range of matching message-boards messages that the user has permission to view
10169             * @throws SystemException if a system exception occurred
10170             */
10171            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10172                    int status, int start, int end, OrderByComparator orderByComparator)
10173                    throws SystemException {
10174                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10175                            return findByG_U_S(groupId, userId, status, start, end,
10176                                    orderByComparator);
10177                    }
10178    
10179                    StringBundler query = null;
10180    
10181                    if (orderByComparator != null) {
10182                            query = new StringBundler(5 +
10183                                            (orderByComparator.getOrderByFields().length * 3));
10184                    }
10185                    else {
10186                            query = new StringBundler(5);
10187                    }
10188    
10189                    if (getDB().isSupportsInlineDistinct()) {
10190                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10191                    }
10192                    else {
10193                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10194                    }
10195    
10196                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10197    
10198                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10199    
10200                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10201    
10202                    if (!getDB().isSupportsInlineDistinct()) {
10203                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10204                    }
10205    
10206                    if (orderByComparator != null) {
10207                            if (getDB().isSupportsInlineDistinct()) {
10208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10209                                            orderByComparator);
10210                            }
10211                            else {
10212                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10213                                            orderByComparator);
10214                            }
10215                    }
10216    
10217                    else {
10218                            if (getDB().isSupportsInlineDistinct()) {
10219                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10220                            }
10221                            else {
10222                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10223                            }
10224                    }
10225    
10226                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10227                                    MBMessage.class.getName(),
10228                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10229    
10230                    Session session = null;
10231    
10232                    try {
10233                            session = openSession();
10234    
10235                            SQLQuery q = session.createSQLQuery(sql);
10236    
10237                            if (getDB().isSupportsInlineDistinct()) {
10238                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10239                            }
10240                            else {
10241                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10242                            }
10243    
10244                            QueryPos qPos = QueryPos.getInstance(q);
10245    
10246                            qPos.add(groupId);
10247    
10248                            qPos.add(userId);
10249    
10250                            qPos.add(status);
10251    
10252                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
10253                    }
10254                    catch (Exception e) {
10255                            throw processException(e);
10256                    }
10257                    finally {
10258                            closeSession(session);
10259                    }
10260            }
10261    
10262            /**
10263             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
10264             *
10265             * @param messageId the primary key of the current message-boards message
10266             * @param groupId the group ID
10267             * @param userId the user ID
10268             * @param status the status
10269             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10270             * @return the previous, current, and next message-boards message
10271             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10272             * @throws SystemException if a system exception occurred
10273             */
10274            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
10275                    long groupId, long userId, int status,
10276                    OrderByComparator orderByComparator)
10277                    throws NoSuchMessageException, SystemException {
10278                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10279                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
10280                                    orderByComparator);
10281                    }
10282    
10283                    MBMessage mbMessage = findByPrimaryKey(messageId);
10284    
10285                    Session session = null;
10286    
10287                    try {
10288                            session = openSession();
10289    
10290                            MBMessage[] array = new MBMessageImpl[3];
10291    
10292                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
10293                                            groupId, userId, status, orderByComparator, true);
10294    
10295                            array[1] = mbMessage;
10296    
10297                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
10298                                            groupId, userId, status, orderByComparator, false);
10299    
10300                            return array;
10301                    }
10302                    catch (Exception e) {
10303                            throw processException(e);
10304                    }
10305                    finally {
10306                            closeSession(session);
10307                    }
10308            }
10309    
10310            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
10311                    MBMessage mbMessage, long groupId, long userId, int status,
10312                    OrderByComparator orderByComparator, boolean previous) {
10313                    StringBundler query = null;
10314    
10315                    if (orderByComparator != null) {
10316                            query = new StringBundler(6 +
10317                                            (orderByComparator.getOrderByFields().length * 6));
10318                    }
10319                    else {
10320                            query = new StringBundler(3);
10321                    }
10322    
10323                    if (getDB().isSupportsInlineDistinct()) {
10324                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10325                    }
10326                    else {
10327                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10328                    }
10329    
10330                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10331    
10332                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10333    
10334                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10335    
10336                    if (!getDB().isSupportsInlineDistinct()) {
10337                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10338                    }
10339    
10340                    if (orderByComparator != null) {
10341                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10342    
10343                            if (orderByConditionFields.length > 0) {
10344                                    query.append(WHERE_AND);
10345                            }
10346    
10347                            for (int i = 0; i < orderByConditionFields.length; i++) {
10348                                    if (getDB().isSupportsInlineDistinct()) {
10349                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10350                                    }
10351                                    else {
10352                                            query.append(_ORDER_BY_ENTITY_TABLE);
10353                                    }
10354    
10355                                    query.append(orderByConditionFields[i]);
10356    
10357                                    if ((i + 1) < orderByConditionFields.length) {
10358                                            if (orderByComparator.isAscending() ^ previous) {
10359                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10360                                            }
10361                                            else {
10362                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10363                                            }
10364                                    }
10365                                    else {
10366                                            if (orderByComparator.isAscending() ^ previous) {
10367                                                    query.append(WHERE_GREATER_THAN);
10368                                            }
10369                                            else {
10370                                                    query.append(WHERE_LESSER_THAN);
10371                                            }
10372                                    }
10373                            }
10374    
10375                            query.append(ORDER_BY_CLAUSE);
10376    
10377                            String[] orderByFields = orderByComparator.getOrderByFields();
10378    
10379                            for (int i = 0; i < orderByFields.length; i++) {
10380                                    if (getDB().isSupportsInlineDistinct()) {
10381                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10382                                    }
10383                                    else {
10384                                            query.append(_ORDER_BY_ENTITY_TABLE);
10385                                    }
10386    
10387                                    query.append(orderByFields[i]);
10388    
10389                                    if ((i + 1) < orderByFields.length) {
10390                                            if (orderByComparator.isAscending() ^ previous) {
10391                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10392                                            }
10393                                            else {
10394                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10395                                            }
10396                                    }
10397                                    else {
10398                                            if (orderByComparator.isAscending() ^ previous) {
10399                                                    query.append(ORDER_BY_ASC);
10400                                            }
10401                                            else {
10402                                                    query.append(ORDER_BY_DESC);
10403                                            }
10404                                    }
10405                            }
10406                    }
10407    
10408                    else {
10409                            if (getDB().isSupportsInlineDistinct()) {
10410                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10411                            }
10412                            else {
10413                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10414                            }
10415                    }
10416    
10417                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10418                                    MBMessage.class.getName(),
10419                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10420    
10421                    SQLQuery q = session.createSQLQuery(sql);
10422    
10423                    q.setFirstResult(0);
10424                    q.setMaxResults(2);
10425    
10426                    if (getDB().isSupportsInlineDistinct()) {
10427                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10428                    }
10429                    else {
10430                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10431                    }
10432    
10433                    QueryPos qPos = QueryPos.getInstance(q);
10434    
10435                    qPos.add(groupId);
10436    
10437                    qPos.add(userId);
10438    
10439                    qPos.add(status);
10440    
10441                    if (orderByComparator != null) {
10442                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10443    
10444                            for (Object value : values) {
10445                                    qPos.add(value);
10446                            }
10447                    }
10448    
10449                    List<MBMessage> list = q.list();
10450    
10451                    if (list.size() == 2) {
10452                            return list.get(1);
10453                    }
10454                    else {
10455                            return null;
10456                    }
10457            }
10458    
10459            /**
10460             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10461             *
10462             * @param groupId the group ID
10463             * @param categoryId the category ID
10464             * @param threadId the thread ID
10465             * @return the matching message-boards messages
10466             * @throws SystemException if a system exception occurred
10467             */
10468            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10469                    long threadId) throws SystemException {
10470                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
10471                            QueryUtil.ALL_POS, null);
10472            }
10473    
10474            /**
10475             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10476             *
10477             * <p>
10478             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10479             * </p>
10480             *
10481             * @param groupId the group ID
10482             * @param categoryId the category ID
10483             * @param threadId the thread ID
10484             * @param start the lower bound of the range of message-boards messages
10485             * @param end the upper bound of the range of message-boards messages (not inclusive)
10486             * @return the range of matching message-boards messages
10487             * @throws SystemException if a system exception occurred
10488             */
10489            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10490                    long threadId, int start, int end) throws SystemException {
10491                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
10492            }
10493    
10494            /**
10495             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10496             *
10497             * <p>
10498             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10499             * </p>
10500             *
10501             * @param groupId the group ID
10502             * @param categoryId the category ID
10503             * @param threadId the thread ID
10504             * @param start the lower bound of the range of message-boards messages
10505             * @param end the upper bound of the range of message-boards messages (not inclusive)
10506             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10507             * @return the ordered range of matching message-boards messages
10508             * @throws SystemException if a system exception occurred
10509             */
10510            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10511                    long threadId, int start, int end, OrderByComparator orderByComparator)
10512                    throws SystemException {
10513                    FinderPath finderPath = null;
10514                    Object[] finderArgs = null;
10515    
10516                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10517                                    (orderByComparator == null)) {
10518                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
10519                            finderArgs = new Object[] { groupId, categoryId, threadId };
10520                    }
10521                    else {
10522                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
10523                            finderArgs = new Object[] {
10524                                            groupId, categoryId, threadId,
10525                                            
10526                                            start, end, orderByComparator
10527                                    };
10528                    }
10529    
10530                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10531                                    finderArgs, this);
10532    
10533                    if ((list != null) && !list.isEmpty()) {
10534                            for (MBMessage mbMessage : list) {
10535                                    if ((groupId != mbMessage.getGroupId()) ||
10536                                                    (categoryId != mbMessage.getCategoryId()) ||
10537                                                    (threadId != mbMessage.getThreadId())) {
10538                                            list = null;
10539    
10540                                            break;
10541                                    }
10542                            }
10543                    }
10544    
10545                    if (list == null) {
10546                            StringBundler query = null;
10547    
10548                            if (orderByComparator != null) {
10549                                    query = new StringBundler(5 +
10550                                                    (orderByComparator.getOrderByFields().length * 3));
10551                            }
10552                            else {
10553                                    query = new StringBundler(5);
10554                            }
10555    
10556                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10557    
10558                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10559    
10560                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10561    
10562                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10563    
10564                            if (orderByComparator != null) {
10565                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10566                                            orderByComparator);
10567                            }
10568    
10569                            else {
10570                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10571                            }
10572    
10573                            String sql = query.toString();
10574    
10575                            Session session = null;
10576    
10577                            try {
10578                                    session = openSession();
10579    
10580                                    Query q = session.createQuery(sql);
10581    
10582                                    QueryPos qPos = QueryPos.getInstance(q);
10583    
10584                                    qPos.add(groupId);
10585    
10586                                    qPos.add(categoryId);
10587    
10588                                    qPos.add(threadId);
10589    
10590                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
10591                                                    end);
10592                            }
10593                            catch (Exception e) {
10594                                    throw processException(e);
10595                            }
10596                            finally {
10597                                    if (list == null) {
10598                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
10599                                    }
10600                                    else {
10601                                            cacheResult(list);
10602    
10603                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
10604                                    }
10605    
10606                                    closeSession(session);
10607                            }
10608                    }
10609    
10610                    return list;
10611            }
10612    
10613            /**
10614             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10615             *
10616             * @param groupId the group ID
10617             * @param categoryId the category ID
10618             * @param threadId the thread ID
10619             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10620             * @return the first matching message-boards message
10621             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10622             * @throws SystemException if a system exception occurred
10623             */
10624            public MBMessage findByG_C_T_First(long groupId, long categoryId,
10625                    long threadId, OrderByComparator orderByComparator)
10626                    throws NoSuchMessageException, SystemException {
10627                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
10628                                    orderByComparator);
10629    
10630                    if (mbMessage != null) {
10631                            return mbMessage;
10632                    }
10633    
10634                    StringBundler msg = new StringBundler(8);
10635    
10636                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10637    
10638                    msg.append("groupId=");
10639                    msg.append(groupId);
10640    
10641                    msg.append(", categoryId=");
10642                    msg.append(categoryId);
10643    
10644                    msg.append(", threadId=");
10645                    msg.append(threadId);
10646    
10647                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10648    
10649                    throw new NoSuchMessageException(msg.toString());
10650            }
10651    
10652            /**
10653             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10654             *
10655             * @param groupId the group ID
10656             * @param categoryId the category ID
10657             * @param threadId the thread ID
10658             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10659             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10660             * @throws SystemException if a system exception occurred
10661             */
10662            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
10663                    long threadId, OrderByComparator orderByComparator)
10664                    throws SystemException {
10665                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
10666                                    orderByComparator);
10667    
10668                    if (!list.isEmpty()) {
10669                            return list.get(0);
10670                    }
10671    
10672                    return null;
10673            }
10674    
10675            /**
10676             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10677             *
10678             * @param groupId the group ID
10679             * @param categoryId the category ID
10680             * @param threadId the thread ID
10681             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10682             * @return the last matching message-boards message
10683             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10684             * @throws SystemException if a system exception occurred
10685             */
10686            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
10687                    long threadId, OrderByComparator orderByComparator)
10688                    throws NoSuchMessageException, SystemException {
10689                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
10690                                    orderByComparator);
10691    
10692                    if (mbMessage != null) {
10693                            return mbMessage;
10694                    }
10695    
10696                    StringBundler msg = new StringBundler(8);
10697    
10698                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10699    
10700                    msg.append("groupId=");
10701                    msg.append(groupId);
10702    
10703                    msg.append(", categoryId=");
10704                    msg.append(categoryId);
10705    
10706                    msg.append(", threadId=");
10707                    msg.append(threadId);
10708    
10709                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10710    
10711                    throw new NoSuchMessageException(msg.toString());
10712            }
10713    
10714            /**
10715             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10716             *
10717             * @param groupId the group ID
10718             * @param categoryId the category ID
10719             * @param threadId the thread ID
10720             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10721             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10722             * @throws SystemException if a system exception occurred
10723             */
10724            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
10725                    long threadId, OrderByComparator orderByComparator)
10726                    throws SystemException {
10727                    int count = countByG_C_T(groupId, categoryId, threadId);
10728    
10729                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
10730                                    count - 1, count, orderByComparator);
10731    
10732                    if (!list.isEmpty()) {
10733                            return list.get(0);
10734                    }
10735    
10736                    return null;
10737            }
10738    
10739            /**
10740             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10741             *
10742             * @param messageId the primary key of the current message-boards message
10743             * @param groupId the group ID
10744             * @param categoryId the category ID
10745             * @param threadId the thread ID
10746             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10747             * @return the previous, current, and next message-boards message
10748             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10749             * @throws SystemException if a system exception occurred
10750             */
10751            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
10752                    long categoryId, long threadId, OrderByComparator orderByComparator)
10753                    throws NoSuchMessageException, SystemException {
10754                    MBMessage mbMessage = findByPrimaryKey(messageId);
10755    
10756                    Session session = null;
10757    
10758                    try {
10759                            session = openSession();
10760    
10761                            MBMessage[] array = new MBMessageImpl[3];
10762    
10763                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10764                                            categoryId, threadId, orderByComparator, true);
10765    
10766                            array[1] = mbMessage;
10767    
10768                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10769                                            categoryId, threadId, orderByComparator, false);
10770    
10771                            return array;
10772                    }
10773                    catch (Exception e) {
10774                            throw processException(e);
10775                    }
10776                    finally {
10777                            closeSession(session);
10778                    }
10779            }
10780    
10781            protected MBMessage getByG_C_T_PrevAndNext(Session session,
10782                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
10783                    OrderByComparator orderByComparator, boolean previous) {
10784                    StringBundler query = null;
10785    
10786                    if (orderByComparator != null) {
10787                            query = new StringBundler(6 +
10788                                            (orderByComparator.getOrderByFields().length * 6));
10789                    }
10790                    else {
10791                            query = new StringBundler(3);
10792                    }
10793    
10794                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10795    
10796                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10797    
10798                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10799    
10800                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10801    
10802                    if (orderByComparator != null) {
10803                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10804    
10805                            if (orderByConditionFields.length > 0) {
10806                                    query.append(WHERE_AND);
10807                            }
10808    
10809                            for (int i = 0; i < orderByConditionFields.length; i++) {
10810                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10811                                    query.append(orderByConditionFields[i]);
10812    
10813                                    if ((i + 1) < orderByConditionFields.length) {
10814                                            if (orderByComparator.isAscending() ^ previous) {
10815                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10816                                            }
10817                                            else {
10818                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10819                                            }
10820                                    }
10821                                    else {
10822                                            if (orderByComparator.isAscending() ^ previous) {
10823                                                    query.append(WHERE_GREATER_THAN);
10824                                            }
10825                                            else {
10826                                                    query.append(WHERE_LESSER_THAN);
10827                                            }
10828                                    }
10829                            }
10830    
10831                            query.append(ORDER_BY_CLAUSE);
10832    
10833                            String[] orderByFields = orderByComparator.getOrderByFields();
10834    
10835                            for (int i = 0; i < orderByFields.length; i++) {
10836                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10837                                    query.append(orderByFields[i]);
10838    
10839                                    if ((i + 1) < orderByFields.length) {
10840                                            if (orderByComparator.isAscending() ^ previous) {
10841                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10842                                            }
10843                                            else {
10844                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10845                                            }
10846                                    }
10847                                    else {
10848                                            if (orderByComparator.isAscending() ^ previous) {
10849                                                    query.append(ORDER_BY_ASC);
10850                                            }
10851                                            else {
10852                                                    query.append(ORDER_BY_DESC);
10853                                            }
10854                                    }
10855                            }
10856                    }
10857    
10858                    else {
10859                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10860                    }
10861    
10862                    String sql = query.toString();
10863    
10864                    Query q = session.createQuery(sql);
10865    
10866                    q.setFirstResult(0);
10867                    q.setMaxResults(2);
10868    
10869                    QueryPos qPos = QueryPos.getInstance(q);
10870    
10871                    qPos.add(groupId);
10872    
10873                    qPos.add(categoryId);
10874    
10875                    qPos.add(threadId);
10876    
10877                    if (orderByComparator != null) {
10878                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10879    
10880                            for (Object value : values) {
10881                                    qPos.add(value);
10882                            }
10883                    }
10884    
10885                    List<MBMessage> list = q.list();
10886    
10887                    if (list.size() == 2) {
10888                            return list.get(1);
10889                    }
10890                    else {
10891                            return null;
10892                    }
10893            }
10894    
10895            /**
10896             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10897             *
10898             * @param groupId the group ID
10899             * @param categoryId the category ID
10900             * @param threadId the thread ID
10901             * @return the matching message-boards messages that the user has permission to view
10902             * @throws SystemException if a system exception occurred
10903             */
10904            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10905                    long threadId) throws SystemException {
10906                    return filterFindByG_C_T(groupId, categoryId, threadId,
10907                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10908            }
10909    
10910            /**
10911             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10912             *
10913             * <p>
10914             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10915             * </p>
10916             *
10917             * @param groupId the group ID
10918             * @param categoryId the category ID
10919             * @param threadId the thread ID
10920             * @param start the lower bound of the range of message-boards messages
10921             * @param end the upper bound of the range of message-boards messages (not inclusive)
10922             * @return the range of matching message-boards messages that the user has permission to view
10923             * @throws SystemException if a system exception occurred
10924             */
10925            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10926                    long threadId, int start, int end) throws SystemException {
10927                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
10928            }
10929    
10930            /**
10931             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10932             *
10933             * <p>
10934             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10935             * </p>
10936             *
10937             * @param groupId the group ID
10938             * @param categoryId the category ID
10939             * @param threadId the thread ID
10940             * @param start the lower bound of the range of message-boards messages
10941             * @param end the upper bound of the range of message-boards messages (not inclusive)
10942             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10943             * @return the ordered range of matching message-boards messages that the user has permission to view
10944             * @throws SystemException if a system exception occurred
10945             */
10946            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10947                    long threadId, int start, int end, OrderByComparator orderByComparator)
10948                    throws SystemException {
10949                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10950                            return findByG_C_T(groupId, categoryId, threadId, start, end,
10951                                    orderByComparator);
10952                    }
10953    
10954                    StringBundler query = null;
10955    
10956                    if (orderByComparator != null) {
10957                            query = new StringBundler(5 +
10958                                            (orderByComparator.getOrderByFields().length * 3));
10959                    }
10960                    else {
10961                            query = new StringBundler(5);
10962                    }
10963    
10964                    if (getDB().isSupportsInlineDistinct()) {
10965                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10966                    }
10967                    else {
10968                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10969                    }
10970    
10971                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10972    
10973                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10974    
10975                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10976    
10977                    if (!getDB().isSupportsInlineDistinct()) {
10978                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10979                    }
10980    
10981                    if (orderByComparator != null) {
10982                            if (getDB().isSupportsInlineDistinct()) {
10983                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10984                                            orderByComparator);
10985                            }
10986                            else {
10987                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10988                                            orderByComparator);
10989                            }
10990                    }
10991    
10992                    else {
10993                            if (getDB().isSupportsInlineDistinct()) {
10994                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10995                            }
10996                            else {
10997                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10998                            }
10999                    }
11000    
11001                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11002                                    MBMessage.class.getName(),
11003                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11004    
11005                    Session session = null;
11006    
11007                    try {
11008                            session = openSession();
11009    
11010                            SQLQuery q = session.createSQLQuery(sql);
11011    
11012                            if (getDB().isSupportsInlineDistinct()) {
11013                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11014                            }
11015                            else {
11016                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11017                            }
11018    
11019                            QueryPos qPos = QueryPos.getInstance(q);
11020    
11021                            qPos.add(groupId);
11022    
11023                            qPos.add(categoryId);
11024    
11025                            qPos.add(threadId);
11026    
11027                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11028                    }
11029                    catch (Exception e) {
11030                            throw processException(e);
11031                    }
11032                    finally {
11033                            closeSession(session);
11034                    }
11035            }
11036    
11037            /**
11038             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11039             *
11040             * @param messageId the primary key of the current message-boards message
11041             * @param groupId the group ID
11042             * @param categoryId the category ID
11043             * @param threadId the thread ID
11044             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11045             * @return the previous, current, and next message-boards message
11046             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11047             * @throws SystemException if a system exception occurred
11048             */
11049            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
11050                    long groupId, long categoryId, long threadId,
11051                    OrderByComparator orderByComparator)
11052                    throws NoSuchMessageException, SystemException {
11053                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11054                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
11055                                    threadId, orderByComparator);
11056                    }
11057    
11058                    MBMessage mbMessage = findByPrimaryKey(messageId);
11059    
11060                    Session session = null;
11061    
11062                    try {
11063                            session = openSession();
11064    
11065                            MBMessage[] array = new MBMessageImpl[3];
11066    
11067                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
11068                                            groupId, categoryId, threadId, orderByComparator, true);
11069    
11070                            array[1] = mbMessage;
11071    
11072                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
11073                                            groupId, categoryId, threadId, orderByComparator, false);
11074    
11075                            return array;
11076                    }
11077                    catch (Exception e) {
11078                            throw processException(e);
11079                    }
11080                    finally {
11081                            closeSession(session);
11082                    }
11083            }
11084    
11085            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
11086                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
11087                    OrderByComparator orderByComparator, boolean previous) {
11088                    StringBundler query = null;
11089    
11090                    if (orderByComparator != null) {
11091                            query = new StringBundler(6 +
11092                                            (orderByComparator.getOrderByFields().length * 6));
11093                    }
11094                    else {
11095                            query = new StringBundler(3);
11096                    }
11097    
11098                    if (getDB().isSupportsInlineDistinct()) {
11099                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11100                    }
11101                    else {
11102                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11103                    }
11104    
11105                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11106    
11107                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11108    
11109                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11110    
11111                    if (!getDB().isSupportsInlineDistinct()) {
11112                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11113                    }
11114    
11115                    if (orderByComparator != null) {
11116                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11117    
11118                            if (orderByConditionFields.length > 0) {
11119                                    query.append(WHERE_AND);
11120                            }
11121    
11122                            for (int i = 0; i < orderByConditionFields.length; i++) {
11123                                    if (getDB().isSupportsInlineDistinct()) {
11124                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11125                                    }
11126                                    else {
11127                                            query.append(_ORDER_BY_ENTITY_TABLE);
11128                                    }
11129    
11130                                    query.append(orderByConditionFields[i]);
11131    
11132                                    if ((i + 1) < orderByConditionFields.length) {
11133                                            if (orderByComparator.isAscending() ^ previous) {
11134                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11135                                            }
11136                                            else {
11137                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11138                                            }
11139                                    }
11140                                    else {
11141                                            if (orderByComparator.isAscending() ^ previous) {
11142                                                    query.append(WHERE_GREATER_THAN);
11143                                            }
11144                                            else {
11145                                                    query.append(WHERE_LESSER_THAN);
11146                                            }
11147                                    }
11148                            }
11149    
11150                            query.append(ORDER_BY_CLAUSE);
11151    
11152                            String[] orderByFields = orderByComparator.getOrderByFields();
11153    
11154                            for (int i = 0; i < orderByFields.length; i++) {
11155                                    if (getDB().isSupportsInlineDistinct()) {
11156                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11157                                    }
11158                                    else {
11159                                            query.append(_ORDER_BY_ENTITY_TABLE);
11160                                    }
11161    
11162                                    query.append(orderByFields[i]);
11163    
11164                                    if ((i + 1) < orderByFields.length) {
11165                                            if (orderByComparator.isAscending() ^ previous) {
11166                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11167                                            }
11168                                            else {
11169                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11170                                            }
11171                                    }
11172                                    else {
11173                                            if (orderByComparator.isAscending() ^ previous) {
11174                                                    query.append(ORDER_BY_ASC);
11175                                            }
11176                                            else {
11177                                                    query.append(ORDER_BY_DESC);
11178                                            }
11179                                    }
11180                            }
11181                    }
11182    
11183                    else {
11184                            if (getDB().isSupportsInlineDistinct()) {
11185                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11186                            }
11187                            else {
11188                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11189                            }
11190                    }
11191    
11192                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11193                                    MBMessage.class.getName(),
11194                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11195    
11196                    SQLQuery q = session.createSQLQuery(sql);
11197    
11198                    q.setFirstResult(0);
11199                    q.setMaxResults(2);
11200    
11201                    if (getDB().isSupportsInlineDistinct()) {
11202                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11203                    }
11204                    else {
11205                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11206                    }
11207    
11208                    QueryPos qPos = QueryPos.getInstance(q);
11209    
11210                    qPos.add(groupId);
11211    
11212                    qPos.add(categoryId);
11213    
11214                    qPos.add(threadId);
11215    
11216                    if (orderByComparator != null) {
11217                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11218    
11219                            for (Object value : values) {
11220                                    qPos.add(value);
11221                            }
11222                    }
11223    
11224                    List<MBMessage> list = q.list();
11225    
11226                    if (list.size() == 2) {
11227                            return list.get(1);
11228                    }
11229                    else {
11230                            return null;
11231                    }
11232            }
11233    
11234            /**
11235             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11236             *
11237             * @param groupId the group ID
11238             * @param categoryId the category ID
11239             * @param status the status
11240             * @return the matching message-boards messages
11241             * @throws SystemException if a system exception occurred
11242             */
11243            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
11244                    throws SystemException {
11245                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
11246                            QueryUtil.ALL_POS, null);
11247            }
11248    
11249            /**
11250             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11251             *
11252             * <p>
11253             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11254             * </p>
11255             *
11256             * @param groupId the group ID
11257             * @param categoryId the category ID
11258             * @param status the status
11259             * @param start the lower bound of the range of message-boards messages
11260             * @param end the upper bound of the range of message-boards messages (not inclusive)
11261             * @return the range of matching message-boards messages
11262             * @throws SystemException if a system exception occurred
11263             */
11264            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
11265                    int status, int start, int end) throws SystemException {
11266                    return findByG_C_S(groupId, categoryId, status, start, end, null);
11267            }
11268    
11269            /**
11270             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11271             *
11272             * <p>
11273             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11274             * </p>
11275             *
11276             * @param groupId the group ID
11277             * @param categoryId the category ID
11278             * @param status the status
11279             * @param start the lower bound of the range of message-boards messages
11280             * @param end the upper bound of the range of message-boards messages (not inclusive)
11281             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11282             * @return the ordered range of matching message-boards messages
11283             * @throws SystemException if a system exception occurred
11284             */
11285            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
11286                    int status, int start, int end, OrderByComparator orderByComparator)
11287                    throws SystemException {
11288                    FinderPath finderPath = null;
11289                    Object[] finderArgs = null;
11290    
11291                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11292                                    (orderByComparator == null)) {
11293                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
11294                            finderArgs = new Object[] { groupId, categoryId, status };
11295                    }
11296                    else {
11297                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
11298                            finderArgs = new Object[] {
11299                                            groupId, categoryId, status,
11300                                            
11301                                            start, end, orderByComparator
11302                                    };
11303                    }
11304    
11305                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11306                                    finderArgs, this);
11307    
11308                    if ((list != null) && !list.isEmpty()) {
11309                            for (MBMessage mbMessage : list) {
11310                                    if ((groupId != mbMessage.getGroupId()) ||
11311                                                    (categoryId != mbMessage.getCategoryId()) ||
11312                                                    (status != mbMessage.getStatus())) {
11313                                            list = null;
11314    
11315                                            break;
11316                                    }
11317                            }
11318                    }
11319    
11320                    if (list == null) {
11321                            StringBundler query = null;
11322    
11323                            if (orderByComparator != null) {
11324                                    query = new StringBundler(5 +
11325                                                    (orderByComparator.getOrderByFields().length * 3));
11326                            }
11327                            else {
11328                                    query = new StringBundler(5);
11329                            }
11330    
11331                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11332    
11333                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11334    
11335                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11336    
11337                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11338    
11339                            if (orderByComparator != null) {
11340                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11341                                            orderByComparator);
11342                            }
11343    
11344                            else {
11345                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11346                            }
11347    
11348                            String sql = query.toString();
11349    
11350                            Session session = null;
11351    
11352                            try {
11353                                    session = openSession();
11354    
11355                                    Query q = session.createQuery(sql);
11356    
11357                                    QueryPos qPos = QueryPos.getInstance(q);
11358    
11359                                    qPos.add(groupId);
11360    
11361                                    qPos.add(categoryId);
11362    
11363                                    qPos.add(status);
11364    
11365                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11366                                                    end);
11367                            }
11368                            catch (Exception e) {
11369                                    throw processException(e);
11370                            }
11371                            finally {
11372                                    if (list == null) {
11373                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11374                                    }
11375                                    else {
11376                                            cacheResult(list);
11377    
11378                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11379                                    }
11380    
11381                                    closeSession(session);
11382                            }
11383                    }
11384    
11385                    return list;
11386            }
11387    
11388            /**
11389             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11390             *
11391             * @param groupId the group ID
11392             * @param categoryId the category ID
11393             * @param status the status
11394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11395             * @return the first matching message-boards message
11396             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11397             * @throws SystemException if a system exception occurred
11398             */
11399            public MBMessage findByG_C_S_First(long groupId, long categoryId,
11400                    int status, OrderByComparator orderByComparator)
11401                    throws NoSuchMessageException, SystemException {
11402                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
11403                                    orderByComparator);
11404    
11405                    if (mbMessage != null) {
11406                            return mbMessage;
11407                    }
11408    
11409                    StringBundler msg = new StringBundler(8);
11410    
11411                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11412    
11413                    msg.append("groupId=");
11414                    msg.append(groupId);
11415    
11416                    msg.append(", categoryId=");
11417                    msg.append(categoryId);
11418    
11419                    msg.append(", status=");
11420                    msg.append(status);
11421    
11422                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11423    
11424                    throw new NoSuchMessageException(msg.toString());
11425            }
11426    
11427            /**
11428             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11429             *
11430             * @param groupId the group ID
11431             * @param categoryId the category ID
11432             * @param status the status
11433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11434             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11435             * @throws SystemException if a system exception occurred
11436             */
11437            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
11438                    int status, OrderByComparator orderByComparator)
11439                    throws SystemException {
11440                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
11441                                    orderByComparator);
11442    
11443                    if (!list.isEmpty()) {
11444                            return list.get(0);
11445                    }
11446    
11447                    return null;
11448            }
11449    
11450            /**
11451             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11452             *
11453             * @param groupId the group ID
11454             * @param categoryId the category ID
11455             * @param status the status
11456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11457             * @return the last matching message-boards message
11458             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11459             * @throws SystemException if a system exception occurred
11460             */
11461            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
11462                    int status, OrderByComparator orderByComparator)
11463                    throws NoSuchMessageException, SystemException {
11464                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
11465                                    orderByComparator);
11466    
11467                    if (mbMessage != null) {
11468                            return mbMessage;
11469                    }
11470    
11471                    StringBundler msg = new StringBundler(8);
11472    
11473                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11474    
11475                    msg.append("groupId=");
11476                    msg.append(groupId);
11477    
11478                    msg.append(", categoryId=");
11479                    msg.append(categoryId);
11480    
11481                    msg.append(", status=");
11482                    msg.append(status);
11483    
11484                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11485    
11486                    throw new NoSuchMessageException(msg.toString());
11487            }
11488    
11489            /**
11490             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11491             *
11492             * @param groupId the group ID
11493             * @param categoryId the category ID
11494             * @param status the status
11495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11496             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11497             * @throws SystemException if a system exception occurred
11498             */
11499            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
11500                    int status, OrderByComparator orderByComparator)
11501                    throws SystemException {
11502                    int count = countByG_C_S(groupId, categoryId, status);
11503    
11504                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
11505                                    count - 1, count, orderByComparator);
11506    
11507                    if (!list.isEmpty()) {
11508                            return list.get(0);
11509                    }
11510    
11511                    return null;
11512            }
11513    
11514            /**
11515             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11516             *
11517             * @param messageId the primary key of the current message-boards message
11518             * @param groupId the group ID
11519             * @param categoryId the category ID
11520             * @param status the status
11521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11522             * @return the previous, current, and next message-boards message
11523             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11524             * @throws SystemException if a system exception occurred
11525             */
11526            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
11527                    long categoryId, int status, OrderByComparator orderByComparator)
11528                    throws NoSuchMessageException, SystemException {
11529                    MBMessage mbMessage = findByPrimaryKey(messageId);
11530    
11531                    Session session = null;
11532    
11533                    try {
11534                            session = openSession();
11535    
11536                            MBMessage[] array = new MBMessageImpl[3];
11537    
11538                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
11539                                            categoryId, status, orderByComparator, true);
11540    
11541                            array[1] = mbMessage;
11542    
11543                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
11544                                            categoryId, status, orderByComparator, false);
11545    
11546                            return array;
11547                    }
11548                    catch (Exception e) {
11549                            throw processException(e);
11550                    }
11551                    finally {
11552                            closeSession(session);
11553                    }
11554            }
11555    
11556            protected MBMessage getByG_C_S_PrevAndNext(Session session,
11557                    MBMessage mbMessage, long groupId, long categoryId, int status,
11558                    OrderByComparator orderByComparator, boolean previous) {
11559                    StringBundler query = null;
11560    
11561                    if (orderByComparator != null) {
11562                            query = new StringBundler(6 +
11563                                            (orderByComparator.getOrderByFields().length * 6));
11564                    }
11565                    else {
11566                            query = new StringBundler(3);
11567                    }
11568    
11569                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11570    
11571                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11572    
11573                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11574    
11575                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11576    
11577                    if (orderByComparator != null) {
11578                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11579    
11580                            if (orderByConditionFields.length > 0) {
11581                                    query.append(WHERE_AND);
11582                            }
11583    
11584                            for (int i = 0; i < orderByConditionFields.length; i++) {
11585                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11586                                    query.append(orderByConditionFields[i]);
11587    
11588                                    if ((i + 1) < orderByConditionFields.length) {
11589                                            if (orderByComparator.isAscending() ^ previous) {
11590                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11591                                            }
11592                                            else {
11593                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11594                                            }
11595                                    }
11596                                    else {
11597                                            if (orderByComparator.isAscending() ^ previous) {
11598                                                    query.append(WHERE_GREATER_THAN);
11599                                            }
11600                                            else {
11601                                                    query.append(WHERE_LESSER_THAN);
11602                                            }
11603                                    }
11604                            }
11605    
11606                            query.append(ORDER_BY_CLAUSE);
11607    
11608                            String[] orderByFields = orderByComparator.getOrderByFields();
11609    
11610                            for (int i = 0; i < orderByFields.length; i++) {
11611                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11612                                    query.append(orderByFields[i]);
11613    
11614                                    if ((i + 1) < orderByFields.length) {
11615                                            if (orderByComparator.isAscending() ^ previous) {
11616                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11617                                            }
11618                                            else {
11619                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11620                                            }
11621                                    }
11622                                    else {
11623                                            if (orderByComparator.isAscending() ^ previous) {
11624                                                    query.append(ORDER_BY_ASC);
11625                                            }
11626                                            else {
11627                                                    query.append(ORDER_BY_DESC);
11628                                            }
11629                                    }
11630                            }
11631                    }
11632    
11633                    else {
11634                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11635                    }
11636    
11637                    String sql = query.toString();
11638    
11639                    Query q = session.createQuery(sql);
11640    
11641                    q.setFirstResult(0);
11642                    q.setMaxResults(2);
11643    
11644                    QueryPos qPos = QueryPos.getInstance(q);
11645    
11646                    qPos.add(groupId);
11647    
11648                    qPos.add(categoryId);
11649    
11650                    qPos.add(status);
11651    
11652                    if (orderByComparator != null) {
11653                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11654    
11655                            for (Object value : values) {
11656                                    qPos.add(value);
11657                            }
11658                    }
11659    
11660                    List<MBMessage> list = q.list();
11661    
11662                    if (list.size() == 2) {
11663                            return list.get(1);
11664                    }
11665                    else {
11666                            return null;
11667                    }
11668            }
11669    
11670            /**
11671             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
11672             *
11673             * @param groupId the group ID
11674             * @param categoryId the category ID
11675             * @param status the status
11676             * @return the matching message-boards messages that the user has permission to view
11677             * @throws SystemException if a system exception occurred
11678             */
11679            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11680                    int status) throws SystemException {
11681                    return filterFindByG_C_S(groupId, categoryId, status,
11682                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11683            }
11684    
11685            /**
11686             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
11687             *
11688             * <p>
11689             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11690             * </p>
11691             *
11692             * @param groupId the group ID
11693             * @param categoryId the category ID
11694             * @param status the status
11695             * @param start the lower bound of the range of message-boards messages
11696             * @param end the upper bound of the range of message-boards messages (not inclusive)
11697             * @return the range of matching message-boards messages that the user has permission to view
11698             * @throws SystemException if a system exception occurred
11699             */
11700            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11701                    int status, int start, int end) throws SystemException {
11702                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
11703            }
11704    
11705            /**
11706             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
11707             *
11708             * <p>
11709             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11710             * </p>
11711             *
11712             * @param groupId the group ID
11713             * @param categoryId the category ID
11714             * @param status the status
11715             * @param start the lower bound of the range of message-boards messages
11716             * @param end the upper bound of the range of message-boards messages (not inclusive)
11717             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11718             * @return the ordered range of matching message-boards messages that the user has permission to view
11719             * @throws SystemException if a system exception occurred
11720             */
11721            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11722                    int status, int start, int end, OrderByComparator orderByComparator)
11723                    throws SystemException {
11724                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11725                            return findByG_C_S(groupId, categoryId, status, start, end,
11726                                    orderByComparator);
11727                    }
11728    
11729                    StringBundler query = null;
11730    
11731                    if (orderByComparator != null) {
11732                            query = new StringBundler(5 +
11733                                            (orderByComparator.getOrderByFields().length * 3));
11734                    }
11735                    else {
11736                            query = new StringBundler(5);
11737                    }
11738    
11739                    if (getDB().isSupportsInlineDistinct()) {
11740                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11741                    }
11742                    else {
11743                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11744                    }
11745    
11746                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11747    
11748                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11749    
11750                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11751    
11752                    if (!getDB().isSupportsInlineDistinct()) {
11753                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11754                    }
11755    
11756                    if (orderByComparator != null) {
11757                            if (getDB().isSupportsInlineDistinct()) {
11758                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11759                                            orderByComparator);
11760                            }
11761                            else {
11762                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11763                                            orderByComparator);
11764                            }
11765                    }
11766    
11767                    else {
11768                            if (getDB().isSupportsInlineDistinct()) {
11769                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11770                            }
11771                            else {
11772                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11773                            }
11774                    }
11775    
11776                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11777                                    MBMessage.class.getName(),
11778                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11779    
11780                    Session session = null;
11781    
11782                    try {
11783                            session = openSession();
11784    
11785                            SQLQuery q = session.createSQLQuery(sql);
11786    
11787                            if (getDB().isSupportsInlineDistinct()) {
11788                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11789                            }
11790                            else {
11791                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11792                            }
11793    
11794                            QueryPos qPos = QueryPos.getInstance(q);
11795    
11796                            qPos.add(groupId);
11797    
11798                            qPos.add(categoryId);
11799    
11800                            qPos.add(status);
11801    
11802                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11803                    }
11804                    catch (Exception e) {
11805                            throw processException(e);
11806                    }
11807                    finally {
11808                            closeSession(session);
11809                    }
11810            }
11811    
11812            /**
11813             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
11814             *
11815             * @param messageId the primary key of the current message-boards message
11816             * @param groupId the group ID
11817             * @param categoryId the category ID
11818             * @param status the status
11819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11820             * @return the previous, current, and next message-boards message
11821             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11822             * @throws SystemException if a system exception occurred
11823             */
11824            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
11825                    long groupId, long categoryId, int status,
11826                    OrderByComparator orderByComparator)
11827                    throws NoSuchMessageException, SystemException {
11828                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11829                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
11830                                    status, orderByComparator);
11831                    }
11832    
11833                    MBMessage mbMessage = findByPrimaryKey(messageId);
11834    
11835                    Session session = null;
11836    
11837                    try {
11838                            session = openSession();
11839    
11840                            MBMessage[] array = new MBMessageImpl[3];
11841    
11842                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11843                                            groupId, categoryId, status, orderByComparator, true);
11844    
11845                            array[1] = mbMessage;
11846    
11847                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11848                                            groupId, categoryId, status, orderByComparator, false);
11849    
11850                            return array;
11851                    }
11852                    catch (Exception e) {
11853                            throw processException(e);
11854                    }
11855                    finally {
11856                            closeSession(session);
11857                    }
11858            }
11859    
11860            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
11861                    MBMessage mbMessage, long groupId, long categoryId, int status,
11862                    OrderByComparator orderByComparator, boolean previous) {
11863                    StringBundler query = null;
11864    
11865                    if (orderByComparator != null) {
11866                            query = new StringBundler(6 +
11867                                            (orderByComparator.getOrderByFields().length * 6));
11868                    }
11869                    else {
11870                            query = new StringBundler(3);
11871                    }
11872    
11873                    if (getDB().isSupportsInlineDistinct()) {
11874                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11875                    }
11876                    else {
11877                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11878                    }
11879    
11880                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11881    
11882                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11883    
11884                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11885    
11886                    if (!getDB().isSupportsInlineDistinct()) {
11887                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11888                    }
11889    
11890                    if (orderByComparator != null) {
11891                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11892    
11893                            if (orderByConditionFields.length > 0) {
11894                                    query.append(WHERE_AND);
11895                            }
11896    
11897                            for (int i = 0; i < orderByConditionFields.length; i++) {
11898                                    if (getDB().isSupportsInlineDistinct()) {
11899                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11900                                    }
11901                                    else {
11902                                            query.append(_ORDER_BY_ENTITY_TABLE);
11903                                    }
11904    
11905                                    query.append(orderByConditionFields[i]);
11906    
11907                                    if ((i + 1) < orderByConditionFields.length) {
11908                                            if (orderByComparator.isAscending() ^ previous) {
11909                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11910                                            }
11911                                            else {
11912                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11913                                            }
11914                                    }
11915                                    else {
11916                                            if (orderByComparator.isAscending() ^ previous) {
11917                                                    query.append(WHERE_GREATER_THAN);
11918                                            }
11919                                            else {
11920                                                    query.append(WHERE_LESSER_THAN);
11921                                            }
11922                                    }
11923                            }
11924    
11925                            query.append(ORDER_BY_CLAUSE);
11926    
11927                            String[] orderByFields = orderByComparator.getOrderByFields();
11928    
11929                            for (int i = 0; i < orderByFields.length; i++) {
11930                                    if (getDB().isSupportsInlineDistinct()) {
11931                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11932                                    }
11933                                    else {
11934                                            query.append(_ORDER_BY_ENTITY_TABLE);
11935                                    }
11936    
11937                                    query.append(orderByFields[i]);
11938    
11939                                    if ((i + 1) < orderByFields.length) {
11940                                            if (orderByComparator.isAscending() ^ previous) {
11941                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11942                                            }
11943                                            else {
11944                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11945                                            }
11946                                    }
11947                                    else {
11948                                            if (orderByComparator.isAscending() ^ previous) {
11949                                                    query.append(ORDER_BY_ASC);
11950                                            }
11951                                            else {
11952                                                    query.append(ORDER_BY_DESC);
11953                                            }
11954                                    }
11955                            }
11956                    }
11957    
11958                    else {
11959                            if (getDB().isSupportsInlineDistinct()) {
11960                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11961                            }
11962                            else {
11963                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11964                            }
11965                    }
11966    
11967                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11968                                    MBMessage.class.getName(),
11969                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11970    
11971                    SQLQuery q = session.createSQLQuery(sql);
11972    
11973                    q.setFirstResult(0);
11974                    q.setMaxResults(2);
11975    
11976                    if (getDB().isSupportsInlineDistinct()) {
11977                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11978                    }
11979                    else {
11980                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11981                    }
11982    
11983                    QueryPos qPos = QueryPos.getInstance(q);
11984    
11985                    qPos.add(groupId);
11986    
11987                    qPos.add(categoryId);
11988    
11989                    qPos.add(status);
11990    
11991                    if (orderByComparator != null) {
11992                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11993    
11994                            for (Object value : values) {
11995                                    qPos.add(value);
11996                            }
11997                    }
11998    
11999                    List<MBMessage> list = q.list();
12000    
12001                    if (list.size() == 2) {
12002                            return list.get(1);
12003                    }
12004                    else {
12005                            return null;
12006                    }
12007            }
12008    
12009            /**
12010             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12011             *
12012             * @param userId the user ID
12013             * @param classNameId the class name ID
12014             * @param classPK the class p k
12015             * @return the matching message-boards messages
12016             * @throws SystemException if a system exception occurred
12017             */
12018            public List<MBMessage> findByU_C_C(long userId, long classNameId,
12019                    long classPK) throws SystemException {
12020                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
12021                            QueryUtil.ALL_POS, null);
12022            }
12023    
12024            /**
12025             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12026             *
12027             * <p>
12028             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12029             * </p>
12030             *
12031             * @param userId the user ID
12032             * @param classNameId the class name ID
12033             * @param classPK the class p k
12034             * @param start the lower bound of the range of message-boards messages
12035             * @param end the upper bound of the range of message-boards messages (not inclusive)
12036             * @return the range of matching message-boards messages
12037             * @throws SystemException if a system exception occurred
12038             */
12039            public List<MBMessage> findByU_C_C(long userId, long classNameId,
12040                    long classPK, int start, int end) throws SystemException {
12041                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
12042            }
12043    
12044            /**
12045             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12046             *
12047             * <p>
12048             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12049             * </p>
12050             *
12051             * @param userId the user ID
12052             * @param classNameId the class name ID
12053             * @param classPK the class p k
12054             * @param start the lower bound of the range of message-boards messages
12055             * @param end the upper bound of the range of message-boards messages (not inclusive)
12056             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12057             * @return the ordered range of matching message-boards messages
12058             * @throws SystemException if a system exception occurred
12059             */
12060            public List<MBMessage> findByU_C_C(long userId, long classNameId,
12061                    long classPK, int start, int end, OrderByComparator orderByComparator)
12062                    throws SystemException {
12063                    FinderPath finderPath = null;
12064                    Object[] finderArgs = null;
12065    
12066                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12067                                    (orderByComparator == null)) {
12068                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
12069                            finderArgs = new Object[] { userId, classNameId, classPK };
12070                    }
12071                    else {
12072                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
12073                            finderArgs = new Object[] {
12074                                            userId, classNameId, classPK,
12075                                            
12076                                            start, end, orderByComparator
12077                                    };
12078                    }
12079    
12080                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12081                                    finderArgs, this);
12082    
12083                    if ((list != null) && !list.isEmpty()) {
12084                            for (MBMessage mbMessage : list) {
12085                                    if ((userId != mbMessage.getUserId()) ||
12086                                                    (classNameId != mbMessage.getClassNameId()) ||
12087                                                    (classPK != mbMessage.getClassPK())) {
12088                                            list = null;
12089    
12090                                            break;
12091                                    }
12092                            }
12093                    }
12094    
12095                    if (list == null) {
12096                            StringBundler query = null;
12097    
12098                            if (orderByComparator != null) {
12099                                    query = new StringBundler(5 +
12100                                                    (orderByComparator.getOrderByFields().length * 3));
12101                            }
12102                            else {
12103                                    query = new StringBundler(5);
12104                            }
12105    
12106                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12107    
12108                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
12109    
12110                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
12111    
12112                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
12113    
12114                            if (orderByComparator != null) {
12115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12116                                            orderByComparator);
12117                            }
12118    
12119                            else {
12120                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12121                            }
12122    
12123                            String sql = query.toString();
12124    
12125                            Session session = null;
12126    
12127                            try {
12128                                    session = openSession();
12129    
12130                                    Query q = session.createQuery(sql);
12131    
12132                                    QueryPos qPos = QueryPos.getInstance(q);
12133    
12134                                    qPos.add(userId);
12135    
12136                                    qPos.add(classNameId);
12137    
12138                                    qPos.add(classPK);
12139    
12140                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12141                                                    end);
12142                            }
12143                            catch (Exception e) {
12144                                    throw processException(e);
12145                            }
12146                            finally {
12147                                    if (list == null) {
12148                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12149                                    }
12150                                    else {
12151                                            cacheResult(list);
12152    
12153                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12154                                    }
12155    
12156                                    closeSession(session);
12157                            }
12158                    }
12159    
12160                    return list;
12161            }
12162    
12163            /**
12164             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12165             *
12166             * @param userId the user ID
12167             * @param classNameId the class name ID
12168             * @param classPK the class p k
12169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12170             * @return the first matching message-boards message
12171             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12172             * @throws SystemException if a system exception occurred
12173             */
12174            public MBMessage findByU_C_C_First(long userId, long classNameId,
12175                    long classPK, OrderByComparator orderByComparator)
12176                    throws NoSuchMessageException, SystemException {
12177                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
12178                                    orderByComparator);
12179    
12180                    if (mbMessage != null) {
12181                            return mbMessage;
12182                    }
12183    
12184                    StringBundler msg = new StringBundler(8);
12185    
12186                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12187    
12188                    msg.append("userId=");
12189                    msg.append(userId);
12190    
12191                    msg.append(", classNameId=");
12192                    msg.append(classNameId);
12193    
12194                    msg.append(", classPK=");
12195                    msg.append(classPK);
12196    
12197                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12198    
12199                    throw new NoSuchMessageException(msg.toString());
12200            }
12201    
12202            /**
12203             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12204             *
12205             * @param userId the user ID
12206             * @param classNameId the class name ID
12207             * @param classPK the class p k
12208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12209             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12210             * @throws SystemException if a system exception occurred
12211             */
12212            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
12213                    long classPK, OrderByComparator orderByComparator)
12214                    throws SystemException {
12215                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
12216                                    orderByComparator);
12217    
12218                    if (!list.isEmpty()) {
12219                            return list.get(0);
12220                    }
12221    
12222                    return null;
12223            }
12224    
12225            /**
12226             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12227             *
12228             * @param userId the user ID
12229             * @param classNameId the class name ID
12230             * @param classPK the class p k
12231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12232             * @return the last matching message-boards message
12233             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12234             * @throws SystemException if a system exception occurred
12235             */
12236            public MBMessage findByU_C_C_Last(long userId, long classNameId,
12237                    long classPK, OrderByComparator orderByComparator)
12238                    throws NoSuchMessageException, SystemException {
12239                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
12240                                    orderByComparator);
12241    
12242                    if (mbMessage != null) {
12243                            return mbMessage;
12244                    }
12245    
12246                    StringBundler msg = new StringBundler(8);
12247    
12248                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12249    
12250                    msg.append("userId=");
12251                    msg.append(userId);
12252    
12253                    msg.append(", classNameId=");
12254                    msg.append(classNameId);
12255    
12256                    msg.append(", classPK=");
12257                    msg.append(classPK);
12258    
12259                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12260    
12261                    throw new NoSuchMessageException(msg.toString());
12262            }
12263    
12264            /**
12265             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12266             *
12267             * @param userId the user ID
12268             * @param classNameId the class name ID
12269             * @param classPK the class p k
12270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12271             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12272             * @throws SystemException if a system exception occurred
12273             */
12274            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
12275                    long classPK, OrderByComparator orderByComparator)
12276                    throws SystemException {
12277                    int count = countByU_C_C(userId, classNameId, classPK);
12278    
12279                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
12280                                    count - 1, count, orderByComparator);
12281    
12282                    if (!list.isEmpty()) {
12283                            return list.get(0);
12284                    }
12285    
12286                    return null;
12287            }
12288    
12289            /**
12290             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12291             *
12292             * @param messageId the primary key of the current message-boards message
12293             * @param userId the user ID
12294             * @param classNameId the class name ID
12295             * @param classPK the class p k
12296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12297             * @return the previous, current, and next message-boards message
12298             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12299             * @throws SystemException if a system exception occurred
12300             */
12301            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
12302                    long classNameId, long classPK, OrderByComparator orderByComparator)
12303                    throws NoSuchMessageException, SystemException {
12304                    MBMessage mbMessage = findByPrimaryKey(messageId);
12305    
12306                    Session session = null;
12307    
12308                    try {
12309                            session = openSession();
12310    
12311                            MBMessage[] array = new MBMessageImpl[3];
12312    
12313                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
12314                                            classNameId, classPK, orderByComparator, true);
12315    
12316                            array[1] = mbMessage;
12317    
12318                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
12319                                            classNameId, classPK, orderByComparator, false);
12320    
12321                            return array;
12322                    }
12323                    catch (Exception e) {
12324                            throw processException(e);
12325                    }
12326                    finally {
12327                            closeSession(session);
12328                    }
12329            }
12330    
12331            protected MBMessage getByU_C_C_PrevAndNext(Session session,
12332                    MBMessage mbMessage, long userId, long classNameId, long classPK,
12333                    OrderByComparator orderByComparator, boolean previous) {
12334                    StringBundler query = null;
12335    
12336                    if (orderByComparator != null) {
12337                            query = new StringBundler(6 +
12338                                            (orderByComparator.getOrderByFields().length * 6));
12339                    }
12340                    else {
12341                            query = new StringBundler(3);
12342                    }
12343    
12344                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12345    
12346                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
12347    
12348                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
12349    
12350                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
12351    
12352                    if (orderByComparator != null) {
12353                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12354    
12355                            if (orderByConditionFields.length > 0) {
12356                                    query.append(WHERE_AND);
12357                            }
12358    
12359                            for (int i = 0; i < orderByConditionFields.length; i++) {
12360                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12361                                    query.append(orderByConditionFields[i]);
12362    
12363                                    if ((i + 1) < orderByConditionFields.length) {
12364                                            if (orderByComparator.isAscending() ^ previous) {
12365                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12366                                            }
12367                                            else {
12368                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12369                                            }
12370                                    }
12371                                    else {
12372                                            if (orderByComparator.isAscending() ^ previous) {
12373                                                    query.append(WHERE_GREATER_THAN);
12374                                            }
12375                                            else {
12376                                                    query.append(WHERE_LESSER_THAN);
12377                                            }
12378                                    }
12379                            }
12380    
12381                            query.append(ORDER_BY_CLAUSE);
12382    
12383                            String[] orderByFields = orderByComparator.getOrderByFields();
12384    
12385                            for (int i = 0; i < orderByFields.length; i++) {
12386                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12387                                    query.append(orderByFields[i]);
12388    
12389                                    if ((i + 1) < orderByFields.length) {
12390                                            if (orderByComparator.isAscending() ^ previous) {
12391                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12392                                            }
12393                                            else {
12394                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12395                                            }
12396                                    }
12397                                    else {
12398                                            if (orderByComparator.isAscending() ^ previous) {
12399                                                    query.append(ORDER_BY_ASC);
12400                                            }
12401                                            else {
12402                                                    query.append(ORDER_BY_DESC);
12403                                            }
12404                                    }
12405                            }
12406                    }
12407    
12408                    else {
12409                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12410                    }
12411    
12412                    String sql = query.toString();
12413    
12414                    Query q = session.createQuery(sql);
12415    
12416                    q.setFirstResult(0);
12417                    q.setMaxResults(2);
12418    
12419                    QueryPos qPos = QueryPos.getInstance(q);
12420    
12421                    qPos.add(userId);
12422    
12423                    qPos.add(classNameId);
12424    
12425                    qPos.add(classPK);
12426    
12427                    if (orderByComparator != null) {
12428                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12429    
12430                            for (Object value : values) {
12431                                    qPos.add(value);
12432                            }
12433                    }
12434    
12435                    List<MBMessage> list = q.list();
12436    
12437                    if (list.size() == 2) {
12438                            return list.get(1);
12439                    }
12440                    else {
12441                            return null;
12442                    }
12443            }
12444    
12445            /**
12446             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12447             *
12448             * @param userId the user ID
12449             * @param classNameId the class name ID
12450             * @param status the status
12451             * @return the matching message-boards messages
12452             * @throws SystemException if a system exception occurred
12453             */
12454            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
12455                    throws SystemException {
12456                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
12457                            QueryUtil.ALL_POS, null);
12458            }
12459    
12460            /**
12461             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12462             *
12463             * <p>
12464             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12465             * </p>
12466             *
12467             * @param userId the user ID
12468             * @param classNameId the class name ID
12469             * @param status the status
12470             * @param start the lower bound of the range of message-boards messages
12471             * @param end the upper bound of the range of message-boards messages (not inclusive)
12472             * @return the range of matching message-boards messages
12473             * @throws SystemException if a system exception occurred
12474             */
12475            public List<MBMessage> findByU_C_S(long userId, long classNameId,
12476                    int status, int start, int end) throws SystemException {
12477                    return findByU_C_S(userId, classNameId, status, start, end, null);
12478            }
12479    
12480            /**
12481             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12482             *
12483             * <p>
12484             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12485             * </p>
12486             *
12487             * @param userId the user ID
12488             * @param classNameId the class name ID
12489             * @param status the status
12490             * @param start the lower bound of the range of message-boards messages
12491             * @param end the upper bound of the range of message-boards messages (not inclusive)
12492             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12493             * @return the ordered range of matching message-boards messages
12494             * @throws SystemException if a system exception occurred
12495             */
12496            public List<MBMessage> findByU_C_S(long userId, long classNameId,
12497                    int status, int start, int end, OrderByComparator orderByComparator)
12498                    throws SystemException {
12499                    FinderPath finderPath = null;
12500                    Object[] finderArgs = null;
12501    
12502                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12503                                    (orderByComparator == null)) {
12504                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
12505                            finderArgs = new Object[] { userId, classNameId, status };
12506                    }
12507                    else {
12508                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12509                            finderArgs = new Object[] {
12510                                            userId, classNameId, status,
12511                                            
12512                                            start, end, orderByComparator
12513                                    };
12514                    }
12515    
12516                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12517                                    finderArgs, this);
12518    
12519                    if ((list != null) && !list.isEmpty()) {
12520                            for (MBMessage mbMessage : list) {
12521                                    if ((userId != mbMessage.getUserId()) ||
12522                                                    (classNameId != mbMessage.getClassNameId()) ||
12523                                                    (status != mbMessage.getStatus())) {
12524                                            list = null;
12525    
12526                                            break;
12527                                    }
12528                            }
12529                    }
12530    
12531                    if (list == null) {
12532                            StringBundler query = null;
12533    
12534                            if (orderByComparator != null) {
12535                                    query = new StringBundler(5 +
12536                                                    (orderByComparator.getOrderByFields().length * 3));
12537                            }
12538                            else {
12539                                    query = new StringBundler(5);
12540                            }
12541    
12542                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12543    
12544                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
12545    
12546                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
12547    
12548                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
12549    
12550                            if (orderByComparator != null) {
12551                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12552                                            orderByComparator);
12553                            }
12554    
12555                            else {
12556                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12557                            }
12558    
12559                            String sql = query.toString();
12560    
12561                            Session session = null;
12562    
12563                            try {
12564                                    session = openSession();
12565    
12566                                    Query q = session.createQuery(sql);
12567    
12568                                    QueryPos qPos = QueryPos.getInstance(q);
12569    
12570                                    qPos.add(userId);
12571    
12572                                    qPos.add(classNameId);
12573    
12574                                    qPos.add(status);
12575    
12576                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12577                                                    end);
12578                            }
12579                            catch (Exception e) {
12580                                    throw processException(e);
12581                            }
12582                            finally {
12583                                    if (list == null) {
12584                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12585                                    }
12586                                    else {
12587                                            cacheResult(list);
12588    
12589                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12590                                    }
12591    
12592                                    closeSession(session);
12593                            }
12594                    }
12595    
12596                    return list;
12597            }
12598    
12599            /**
12600             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12601             *
12602             * @param userId the user ID
12603             * @param classNameId the class name ID
12604             * @param status the status
12605             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12606             * @return the first matching message-boards message
12607             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12608             * @throws SystemException if a system exception occurred
12609             */
12610            public MBMessage findByU_C_S_First(long userId, long classNameId,
12611                    int status, OrderByComparator orderByComparator)
12612                    throws NoSuchMessageException, SystemException {
12613                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
12614                                    orderByComparator);
12615    
12616                    if (mbMessage != null) {
12617                            return mbMessage;
12618                    }
12619    
12620                    StringBundler msg = new StringBundler(8);
12621    
12622                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12623    
12624                    msg.append("userId=");
12625                    msg.append(userId);
12626    
12627                    msg.append(", classNameId=");
12628                    msg.append(classNameId);
12629    
12630                    msg.append(", status=");
12631                    msg.append(status);
12632    
12633                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12634    
12635                    throw new NoSuchMessageException(msg.toString());
12636            }
12637    
12638            /**
12639             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12640             *
12641             * @param userId the user ID
12642             * @param classNameId the class name ID
12643             * @param status the status
12644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12645             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12646             * @throws SystemException if a system exception occurred
12647             */
12648            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
12649                    int status, OrderByComparator orderByComparator)
12650                    throws SystemException {
12651                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
12652                                    orderByComparator);
12653    
12654                    if (!list.isEmpty()) {
12655                            return list.get(0);
12656                    }
12657    
12658                    return null;
12659            }
12660    
12661            /**
12662             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12663             *
12664             * @param userId the user ID
12665             * @param classNameId the class name ID
12666             * @param status the status
12667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12668             * @return the last matching message-boards message
12669             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12670             * @throws SystemException if a system exception occurred
12671             */
12672            public MBMessage findByU_C_S_Last(long userId, long classNameId,
12673                    int status, OrderByComparator orderByComparator)
12674                    throws NoSuchMessageException, SystemException {
12675                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
12676                                    orderByComparator);
12677    
12678                    if (mbMessage != null) {
12679                            return mbMessage;
12680                    }
12681    
12682                    StringBundler msg = new StringBundler(8);
12683    
12684                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12685    
12686                    msg.append("userId=");
12687                    msg.append(userId);
12688    
12689                    msg.append(", classNameId=");
12690                    msg.append(classNameId);
12691    
12692                    msg.append(", status=");
12693                    msg.append(status);
12694    
12695                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12696    
12697                    throw new NoSuchMessageException(msg.toString());
12698            }
12699    
12700            /**
12701             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12702             *
12703             * @param userId the user ID
12704             * @param classNameId the class name ID
12705             * @param status the status
12706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12707             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12708             * @throws SystemException if a system exception occurred
12709             */
12710            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
12711                    int status, OrderByComparator orderByComparator)
12712                    throws SystemException {
12713                    int count = countByU_C_S(userId, classNameId, status);
12714    
12715                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
12716                                    count - 1, count, orderByComparator);
12717    
12718                    if (!list.isEmpty()) {
12719                            return list.get(0);
12720                    }
12721    
12722                    return null;
12723            }
12724    
12725            /**
12726             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12727             *
12728             * @param messageId the primary key of the current message-boards message
12729             * @param userId the user ID
12730             * @param classNameId the class name ID
12731             * @param status the status
12732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12733             * @return the previous, current, and next message-boards message
12734             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12735             * @throws SystemException if a system exception occurred
12736             */
12737            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
12738                    long classNameId, int status, OrderByComparator orderByComparator)
12739                    throws NoSuchMessageException, SystemException {
12740                    MBMessage mbMessage = findByPrimaryKey(messageId);
12741    
12742                    Session session = null;
12743    
12744                    try {
12745                            session = openSession();
12746    
12747                            MBMessage[] array = new MBMessageImpl[3];
12748    
12749                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
12750                                            classNameId, status, orderByComparator, true);
12751    
12752                            array[1] = mbMessage;
12753    
12754                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
12755                                            classNameId, status, orderByComparator, false);
12756    
12757                            return array;
12758                    }
12759                    catch (Exception e) {
12760                            throw processException(e);
12761                    }
12762                    finally {
12763                            closeSession(session);
12764                    }
12765            }
12766    
12767            protected MBMessage getByU_C_S_PrevAndNext(Session session,
12768                    MBMessage mbMessage, long userId, long classNameId, int status,
12769                    OrderByComparator orderByComparator, boolean previous) {
12770                    StringBundler query = null;
12771    
12772                    if (orderByComparator != null) {
12773                            query = new StringBundler(6 +
12774                                            (orderByComparator.getOrderByFields().length * 6));
12775                    }
12776                    else {
12777                            query = new StringBundler(3);
12778                    }
12779    
12780                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12781    
12782                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
12783    
12784                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
12785    
12786                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
12787    
12788                    if (orderByComparator != null) {
12789                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12790    
12791                            if (orderByConditionFields.length > 0) {
12792                                    query.append(WHERE_AND);
12793                            }
12794    
12795                            for (int i = 0; i < orderByConditionFields.length; i++) {
12796                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12797                                    query.append(orderByConditionFields[i]);
12798    
12799                                    if ((i + 1) < orderByConditionFields.length) {
12800                                            if (orderByComparator.isAscending() ^ previous) {
12801                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12802                                            }
12803                                            else {
12804                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12805                                            }
12806                                    }
12807                                    else {
12808                                            if (orderByComparator.isAscending() ^ previous) {
12809                                                    query.append(WHERE_GREATER_THAN);
12810                                            }
12811                                            else {
12812                                                    query.append(WHERE_LESSER_THAN);
12813                                            }
12814                                    }
12815                            }
12816    
12817                            query.append(ORDER_BY_CLAUSE);
12818    
12819                            String[] orderByFields = orderByComparator.getOrderByFields();
12820    
12821                            for (int i = 0; i < orderByFields.length; i++) {
12822                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12823                                    query.append(orderByFields[i]);
12824    
12825                                    if ((i + 1) < orderByFields.length) {
12826                                            if (orderByComparator.isAscending() ^ previous) {
12827                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12828                                            }
12829                                            else {
12830                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12831                                            }
12832                                    }
12833                                    else {
12834                                            if (orderByComparator.isAscending() ^ previous) {
12835                                                    query.append(ORDER_BY_ASC);
12836                                            }
12837                                            else {
12838                                                    query.append(ORDER_BY_DESC);
12839                                            }
12840                                    }
12841                            }
12842                    }
12843    
12844                    else {
12845                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12846                    }
12847    
12848                    String sql = query.toString();
12849    
12850                    Query q = session.createQuery(sql);
12851    
12852                    q.setFirstResult(0);
12853                    q.setMaxResults(2);
12854    
12855                    QueryPos qPos = QueryPos.getInstance(q);
12856    
12857                    qPos.add(userId);
12858    
12859                    qPos.add(classNameId);
12860    
12861                    qPos.add(status);
12862    
12863                    if (orderByComparator != null) {
12864                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12865    
12866                            for (Object value : values) {
12867                                    qPos.add(value);
12868                            }
12869                    }
12870    
12871                    List<MBMessage> list = q.list();
12872    
12873                    if (list.size() == 2) {
12874                            return list.get(1);
12875                    }
12876                    else {
12877                            return null;
12878                    }
12879            }
12880    
12881            /**
12882             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12883             *
12884             * <p>
12885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12886             * </p>
12887             *
12888             * @param userId the user ID
12889             * @param classNameIds the class name IDs
12890             * @param status the status
12891             * @return the matching message-boards messages
12892             * @throws SystemException if a system exception occurred
12893             */
12894            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12895                    int status) throws SystemException {
12896                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
12897                            QueryUtil.ALL_POS, null);
12898            }
12899    
12900            /**
12901             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12902             *
12903             * <p>
12904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12905             * </p>
12906             *
12907             * @param userId the user ID
12908             * @param classNameIds the class name IDs
12909             * @param status the status
12910             * @param start the lower bound of the range of message-boards messages
12911             * @param end the upper bound of the range of message-boards messages (not inclusive)
12912             * @return the range of matching message-boards messages
12913             * @throws SystemException if a system exception occurred
12914             */
12915            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12916                    int status, int start, int end) throws SystemException {
12917                    return findByU_C_S(userId, classNameIds, status, start, end, null);
12918            }
12919    
12920            /**
12921             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12922             *
12923             * <p>
12924             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12925             * </p>
12926             *
12927             * @param userId the user ID
12928             * @param classNameIds the class name IDs
12929             * @param status the status
12930             * @param start the lower bound of the range of message-boards messages
12931             * @param end the upper bound of the range of message-boards messages (not inclusive)
12932             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12933             * @return the ordered range of matching message-boards messages
12934             * @throws SystemException if a system exception occurred
12935             */
12936            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12937                    int status, int start, int end, OrderByComparator orderByComparator)
12938                    throws SystemException {
12939                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12940                    Object[] finderArgs = null;
12941    
12942                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12943                                    (orderByComparator == null)) {
12944                            finderArgs = new Object[] {
12945                                            userId, StringUtil.merge(classNameIds), status
12946                                    };
12947                    }
12948                    else {
12949                            finderArgs = new Object[] {
12950                                            userId, StringUtil.merge(classNameIds), status,
12951                                            
12952                                            start, end, orderByComparator
12953                                    };
12954                    }
12955    
12956                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12957                                    finderArgs, this);
12958    
12959                    if ((list != null) && !list.isEmpty()) {
12960                            for (MBMessage mbMessage : list) {
12961                                    if ((userId != mbMessage.getUserId()) ||
12962                                                    !ArrayUtil.contains(classNameIds,
12963                                                            mbMessage.getClassNameId()) ||
12964                                                    (status != mbMessage.getStatus())) {
12965                                            list = null;
12966    
12967                                            break;
12968                                    }
12969                            }
12970                    }
12971    
12972                    if (list == null) {
12973                            StringBundler query = new StringBundler();
12974    
12975                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12976    
12977                            boolean conjunctionable = false;
12978    
12979                            if (conjunctionable) {
12980                                    query.append(WHERE_AND);
12981                            }
12982    
12983                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
12984    
12985                            conjunctionable = true;
12986    
12987                            if ((classNameIds == null) || (classNameIds.length > 0)) {
12988                                    if (conjunctionable) {
12989                                            query.append(WHERE_AND);
12990                                    }
12991    
12992                                    query.append(StringPool.OPEN_PARENTHESIS);
12993    
12994                                    for (int i = 0; i < classNameIds.length; i++) {
12995                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
12996    
12997                                            if ((i + 1) < classNameIds.length) {
12998                                                    query.append(WHERE_OR);
12999                                            }
13000                                    }
13001    
13002                                    query.append(StringPool.CLOSE_PARENTHESIS);
13003    
13004                                    conjunctionable = true;
13005                            }
13006    
13007                            if (conjunctionable) {
13008                                    query.append(WHERE_AND);
13009                            }
13010    
13011                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
13012    
13013                            conjunctionable = true;
13014    
13015                            if (orderByComparator != null) {
13016                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13017                                            orderByComparator);
13018                            }
13019    
13020                            else {
13021                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13022                            }
13023    
13024                            String sql = query.toString();
13025    
13026                            Session session = null;
13027    
13028                            try {
13029                                    session = openSession();
13030    
13031                                    Query q = session.createQuery(sql);
13032    
13033                                    QueryPos qPos = QueryPos.getInstance(q);
13034    
13035                                    qPos.add(userId);
13036    
13037                                    if (classNameIds != null) {
13038                                            qPos.add(classNameIds);
13039                                    }
13040    
13041                                    qPos.add(status);
13042    
13043                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13044                                                    end);
13045                            }
13046                            catch (Exception e) {
13047                                    throw processException(e);
13048                            }
13049                            finally {
13050                                    if (list == null) {
13051                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13052                                    }
13053                                    else {
13054                                            cacheResult(list);
13055    
13056                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13057                                    }
13058    
13059                                    closeSession(session);
13060                            }
13061                    }
13062    
13063                    return list;
13064            }
13065    
13066            /**
13067             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13068             *
13069             * @param classNameId the class name ID
13070             * @param classPK the class p k
13071             * @param status the status
13072             * @return the matching message-boards messages
13073             * @throws SystemException if a system exception occurred
13074             */
13075            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13076                    int status) throws SystemException {
13077                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
13078                            QueryUtil.ALL_POS, null);
13079            }
13080    
13081            /**
13082             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13083             *
13084             * <p>
13085             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13086             * </p>
13087             *
13088             * @param classNameId the class name ID
13089             * @param classPK the class p k
13090             * @param status the status
13091             * @param start the lower bound of the range of message-boards messages
13092             * @param end the upper bound of the range of message-boards messages (not inclusive)
13093             * @return the range of matching message-boards messages
13094             * @throws SystemException if a system exception occurred
13095             */
13096            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13097                    int status, int start, int end) throws SystemException {
13098                    return findByC_C_S(classNameId, classPK, status, start, end, null);
13099            }
13100    
13101            /**
13102             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13103             *
13104             * <p>
13105             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13106             * </p>
13107             *
13108             * @param classNameId the class name ID
13109             * @param classPK the class p k
13110             * @param status the status
13111             * @param start the lower bound of the range of message-boards messages
13112             * @param end the upper bound of the range of message-boards messages (not inclusive)
13113             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13114             * @return the ordered range of matching message-boards messages
13115             * @throws SystemException if a system exception occurred
13116             */
13117            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13118                    int status, int start, int end, OrderByComparator orderByComparator)
13119                    throws SystemException {
13120                    FinderPath finderPath = null;
13121                    Object[] finderArgs = null;
13122    
13123                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13124                                    (orderByComparator == null)) {
13125                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
13126                            finderArgs = new Object[] { classNameId, classPK, status };
13127                    }
13128                    else {
13129                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
13130                            finderArgs = new Object[] {
13131                                            classNameId, classPK, status,
13132                                            
13133                                            start, end, orderByComparator
13134                                    };
13135                    }
13136    
13137                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13138                                    finderArgs, this);
13139    
13140                    if ((list != null) && !list.isEmpty()) {
13141                            for (MBMessage mbMessage : list) {
13142                                    if ((classNameId != mbMessage.getClassNameId()) ||
13143                                                    (classPK != mbMessage.getClassPK()) ||
13144                                                    (status != mbMessage.getStatus())) {
13145                                            list = null;
13146    
13147                                            break;
13148                                    }
13149                            }
13150                    }
13151    
13152                    if (list == null) {
13153                            StringBundler query = null;
13154    
13155                            if (orderByComparator != null) {
13156                                    query = new StringBundler(5 +
13157                                                    (orderByComparator.getOrderByFields().length * 3));
13158                            }
13159                            else {
13160                                    query = new StringBundler(5);
13161                            }
13162    
13163                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13164    
13165                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
13166    
13167                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
13168    
13169                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
13170    
13171                            if (orderByComparator != null) {
13172                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13173                                            orderByComparator);
13174                            }
13175    
13176                            else {
13177                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13178                            }
13179    
13180                            String sql = query.toString();
13181    
13182                            Session session = null;
13183    
13184                            try {
13185                                    session = openSession();
13186    
13187                                    Query q = session.createQuery(sql);
13188    
13189                                    QueryPos qPos = QueryPos.getInstance(q);
13190    
13191                                    qPos.add(classNameId);
13192    
13193                                    qPos.add(classPK);
13194    
13195                                    qPos.add(status);
13196    
13197                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13198                                                    end);
13199                            }
13200                            catch (Exception e) {
13201                                    throw processException(e);
13202                            }
13203                            finally {
13204                                    if (list == null) {
13205                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13206                                    }
13207                                    else {
13208                                            cacheResult(list);
13209    
13210                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13211                                    }
13212    
13213                                    closeSession(session);
13214                            }
13215                    }
13216    
13217                    return list;
13218            }
13219    
13220            /**
13221             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13222             *
13223             * @param classNameId the class name ID
13224             * @param classPK the class p k
13225             * @param status the status
13226             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13227             * @return the first matching message-boards message
13228             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13229             * @throws SystemException if a system exception occurred
13230             */
13231            public MBMessage findByC_C_S_First(long classNameId, long classPK,
13232                    int status, OrderByComparator orderByComparator)
13233                    throws NoSuchMessageException, SystemException {
13234                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
13235                                    orderByComparator);
13236    
13237                    if (mbMessage != null) {
13238                            return mbMessage;
13239                    }
13240    
13241                    StringBundler msg = new StringBundler(8);
13242    
13243                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13244    
13245                    msg.append("classNameId=");
13246                    msg.append(classNameId);
13247    
13248                    msg.append(", classPK=");
13249                    msg.append(classPK);
13250    
13251                    msg.append(", status=");
13252                    msg.append(status);
13253    
13254                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13255    
13256                    throw new NoSuchMessageException(msg.toString());
13257            }
13258    
13259            /**
13260             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13261             *
13262             * @param classNameId the class name ID
13263             * @param classPK the class p k
13264             * @param status the status
13265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13266             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13267             * @throws SystemException if a system exception occurred
13268             */
13269            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
13270                    int status, OrderByComparator orderByComparator)
13271                    throws SystemException {
13272                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
13273                                    orderByComparator);
13274    
13275                    if (!list.isEmpty()) {
13276                            return list.get(0);
13277                    }
13278    
13279                    return null;
13280            }
13281    
13282            /**
13283             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13284             *
13285             * @param classNameId the class name ID
13286             * @param classPK the class p k
13287             * @param status the status
13288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13289             * @return the last matching message-boards message
13290             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13291             * @throws SystemException if a system exception occurred
13292             */
13293            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
13294                    int status, OrderByComparator orderByComparator)
13295                    throws NoSuchMessageException, SystemException {
13296                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
13297                                    orderByComparator);
13298    
13299                    if (mbMessage != null) {
13300                            return mbMessage;
13301                    }
13302    
13303                    StringBundler msg = new StringBundler(8);
13304    
13305                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13306    
13307                    msg.append("classNameId=");
13308                    msg.append(classNameId);
13309    
13310                    msg.append(", classPK=");
13311                    msg.append(classPK);
13312    
13313                    msg.append(", status=");
13314                    msg.append(status);
13315    
13316                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13317    
13318                    throw new NoSuchMessageException(msg.toString());
13319            }
13320    
13321            /**
13322             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13323             *
13324             * @param classNameId the class name ID
13325             * @param classPK the class p k
13326             * @param status the status
13327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13328             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13329             * @throws SystemException if a system exception occurred
13330             */
13331            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
13332                    int status, OrderByComparator orderByComparator)
13333                    throws SystemException {
13334                    int count = countByC_C_S(classNameId, classPK, status);
13335    
13336                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
13337                                    count - 1, count, orderByComparator);
13338    
13339                    if (!list.isEmpty()) {
13340                            return list.get(0);
13341                    }
13342    
13343                    return null;
13344            }
13345    
13346            /**
13347             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13348             *
13349             * @param messageId the primary key of the current message-boards message
13350             * @param classNameId the class name ID
13351             * @param classPK the class p k
13352             * @param status the status
13353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13354             * @return the previous, current, and next message-boards message
13355             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13356             * @throws SystemException if a system exception occurred
13357             */
13358            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
13359                    long classNameId, long classPK, int status,
13360                    OrderByComparator orderByComparator)
13361                    throws NoSuchMessageException, SystemException {
13362                    MBMessage mbMessage = findByPrimaryKey(messageId);
13363    
13364                    Session session = null;
13365    
13366                    try {
13367                            session = openSession();
13368    
13369                            MBMessage[] array = new MBMessageImpl[3];
13370    
13371                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
13372                                            classPK, status, orderByComparator, true);
13373    
13374                            array[1] = mbMessage;
13375    
13376                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
13377                                            classPK, status, orderByComparator, false);
13378    
13379                            return array;
13380                    }
13381                    catch (Exception e) {
13382                            throw processException(e);
13383                    }
13384                    finally {
13385                            closeSession(session);
13386                    }
13387            }
13388    
13389            protected MBMessage getByC_C_S_PrevAndNext(Session session,
13390                    MBMessage mbMessage, long classNameId, long classPK, int status,
13391                    OrderByComparator orderByComparator, boolean previous) {
13392                    StringBundler query = null;
13393    
13394                    if (orderByComparator != null) {
13395                            query = new StringBundler(6 +
13396                                            (orderByComparator.getOrderByFields().length * 6));
13397                    }
13398                    else {
13399                            query = new StringBundler(3);
13400                    }
13401    
13402                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13403    
13404                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
13405    
13406                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
13407    
13408                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
13409    
13410                    if (orderByComparator != null) {
13411                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13412    
13413                            if (orderByConditionFields.length > 0) {
13414                                    query.append(WHERE_AND);
13415                            }
13416    
13417                            for (int i = 0; i < orderByConditionFields.length; i++) {
13418                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13419                                    query.append(orderByConditionFields[i]);
13420    
13421                                    if ((i + 1) < orderByConditionFields.length) {
13422                                            if (orderByComparator.isAscending() ^ previous) {
13423                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13424                                            }
13425                                            else {
13426                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13427                                            }
13428                                    }
13429                                    else {
13430                                            if (orderByComparator.isAscending() ^ previous) {
13431                                                    query.append(WHERE_GREATER_THAN);
13432                                            }
13433                                            else {
13434                                                    query.append(WHERE_LESSER_THAN);
13435                                            }
13436                                    }
13437                            }
13438    
13439                            query.append(ORDER_BY_CLAUSE);
13440    
13441                            String[] orderByFields = orderByComparator.getOrderByFields();
13442    
13443                            for (int i = 0; i < orderByFields.length; i++) {
13444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13445                                    query.append(orderByFields[i]);
13446    
13447                                    if ((i + 1) < orderByFields.length) {
13448                                            if (orderByComparator.isAscending() ^ previous) {
13449                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13450                                            }
13451                                            else {
13452                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13453                                            }
13454                                    }
13455                                    else {
13456                                            if (orderByComparator.isAscending() ^ previous) {
13457                                                    query.append(ORDER_BY_ASC);
13458                                            }
13459                                            else {
13460                                                    query.append(ORDER_BY_DESC);
13461                                            }
13462                                    }
13463                            }
13464                    }
13465    
13466                    else {
13467                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13468                    }
13469    
13470                    String sql = query.toString();
13471    
13472                    Query q = session.createQuery(sql);
13473    
13474                    q.setFirstResult(0);
13475                    q.setMaxResults(2);
13476    
13477                    QueryPos qPos = QueryPos.getInstance(q);
13478    
13479                    qPos.add(classNameId);
13480    
13481                    qPos.add(classPK);
13482    
13483                    qPos.add(status);
13484    
13485                    if (orderByComparator != null) {
13486                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13487    
13488                            for (Object value : values) {
13489                                    qPos.add(value);
13490                            }
13491                    }
13492    
13493                    List<MBMessage> list = q.list();
13494    
13495                    if (list.size() == 2) {
13496                            return list.get(1);
13497                    }
13498                    else {
13499                            return null;
13500                    }
13501            }
13502    
13503            /**
13504             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13505             *
13506             * @param groupId the group ID
13507             * @param categoryId the category ID
13508             * @param threadId the thread ID
13509             * @param answer the answer
13510             * @return the matching message-boards messages
13511             * @throws SystemException if a system exception occurred
13512             */
13513            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13514                    long threadId, boolean answer) throws SystemException {
13515                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
13516                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13517            }
13518    
13519            /**
13520             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13521             *
13522             * <p>
13523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13524             * </p>
13525             *
13526             * @param groupId the group ID
13527             * @param categoryId the category ID
13528             * @param threadId the thread ID
13529             * @param answer the answer
13530             * @param start the lower bound of the range of message-boards messages
13531             * @param end the upper bound of the range of message-boards messages (not inclusive)
13532             * @return the range of matching message-boards messages
13533             * @throws SystemException if a system exception occurred
13534             */
13535            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13536                    long threadId, boolean answer, int start, int end)
13537                    throws SystemException {
13538                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
13539                            null);
13540            }
13541    
13542            /**
13543             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13544             *
13545             * <p>
13546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13547             * </p>
13548             *
13549             * @param groupId the group ID
13550             * @param categoryId the category ID
13551             * @param threadId the thread ID
13552             * @param answer the answer
13553             * @param start the lower bound of the range of message-boards messages
13554             * @param end the upper bound of the range of message-boards messages (not inclusive)
13555             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13556             * @return the ordered range of matching message-boards messages
13557             * @throws SystemException if a system exception occurred
13558             */
13559            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13560                    long threadId, boolean answer, int start, int end,
13561                    OrderByComparator orderByComparator) throws SystemException {
13562                    FinderPath finderPath = null;
13563                    Object[] finderArgs = null;
13564    
13565                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13566                                    (orderByComparator == null)) {
13567                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
13568                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
13569                    }
13570                    else {
13571                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
13572                            finderArgs = new Object[] {
13573                                            groupId, categoryId, threadId, answer,
13574                                            
13575                                            start, end, orderByComparator
13576                                    };
13577                    }
13578    
13579                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13580                                    finderArgs, this);
13581    
13582                    if ((list != null) && !list.isEmpty()) {
13583                            for (MBMessage mbMessage : list) {
13584                                    if ((groupId != mbMessage.getGroupId()) ||
13585                                                    (categoryId != mbMessage.getCategoryId()) ||
13586                                                    (threadId != mbMessage.getThreadId()) ||
13587                                                    (answer != mbMessage.getAnswer())) {
13588                                            list = null;
13589    
13590                                            break;
13591                                    }
13592                            }
13593                    }
13594    
13595                    if (list == null) {
13596                            StringBundler query = null;
13597    
13598                            if (orderByComparator != null) {
13599                                    query = new StringBundler(6 +
13600                                                    (orderByComparator.getOrderByFields().length * 3));
13601                            }
13602                            else {
13603                                    query = new StringBundler(6);
13604                            }
13605    
13606                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13607    
13608                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13609    
13610                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13611    
13612                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13613    
13614                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13615    
13616                            if (orderByComparator != null) {
13617                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13618                                            orderByComparator);
13619                            }
13620    
13621                            else {
13622                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13623                            }
13624    
13625                            String sql = query.toString();
13626    
13627                            Session session = null;
13628    
13629                            try {
13630                                    session = openSession();
13631    
13632                                    Query q = session.createQuery(sql);
13633    
13634                                    QueryPos qPos = QueryPos.getInstance(q);
13635    
13636                                    qPos.add(groupId);
13637    
13638                                    qPos.add(categoryId);
13639    
13640                                    qPos.add(threadId);
13641    
13642                                    qPos.add(answer);
13643    
13644                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13645                                                    end);
13646                            }
13647                            catch (Exception e) {
13648                                    throw processException(e);
13649                            }
13650                            finally {
13651                                    if (list == null) {
13652                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13653                                    }
13654                                    else {
13655                                            cacheResult(list);
13656    
13657                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13658                                    }
13659    
13660                                    closeSession(session);
13661                            }
13662                    }
13663    
13664                    return list;
13665            }
13666    
13667            /**
13668             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13669             *
13670             * @param groupId the group ID
13671             * @param categoryId the category ID
13672             * @param threadId the thread ID
13673             * @param answer the answer
13674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13675             * @return the first matching message-boards message
13676             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13677             * @throws SystemException if a system exception occurred
13678             */
13679            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
13680                    long threadId, boolean answer, OrderByComparator orderByComparator)
13681                    throws NoSuchMessageException, SystemException {
13682                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
13683                                    threadId, answer, orderByComparator);
13684    
13685                    if (mbMessage != null) {
13686                            return mbMessage;
13687                    }
13688    
13689                    StringBundler msg = new StringBundler(10);
13690    
13691                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13692    
13693                    msg.append("groupId=");
13694                    msg.append(groupId);
13695    
13696                    msg.append(", categoryId=");
13697                    msg.append(categoryId);
13698    
13699                    msg.append(", threadId=");
13700                    msg.append(threadId);
13701    
13702                    msg.append(", answer=");
13703                    msg.append(answer);
13704    
13705                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13706    
13707                    throw new NoSuchMessageException(msg.toString());
13708            }
13709    
13710            /**
13711             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13712             *
13713             * @param groupId the group ID
13714             * @param categoryId the category ID
13715             * @param threadId the thread ID
13716             * @param answer the answer
13717             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13718             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13719             * @throws SystemException if a system exception occurred
13720             */
13721            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
13722                    long threadId, boolean answer, OrderByComparator orderByComparator)
13723                    throws SystemException {
13724                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
13725                                    answer, 0, 1, orderByComparator);
13726    
13727                    if (!list.isEmpty()) {
13728                            return list.get(0);
13729                    }
13730    
13731                    return null;
13732            }
13733    
13734            /**
13735             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13736             *
13737             * @param groupId the group ID
13738             * @param categoryId the category ID
13739             * @param threadId the thread ID
13740             * @param answer the answer
13741             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13742             * @return the last matching message-boards message
13743             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13744             * @throws SystemException if a system exception occurred
13745             */
13746            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
13747                    long threadId, boolean answer, OrderByComparator orderByComparator)
13748                    throws NoSuchMessageException, SystemException {
13749                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
13750                                    threadId, answer, orderByComparator);
13751    
13752                    if (mbMessage != null) {
13753                            return mbMessage;
13754                    }
13755    
13756                    StringBundler msg = new StringBundler(10);
13757    
13758                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13759    
13760                    msg.append("groupId=");
13761                    msg.append(groupId);
13762    
13763                    msg.append(", categoryId=");
13764                    msg.append(categoryId);
13765    
13766                    msg.append(", threadId=");
13767                    msg.append(threadId);
13768    
13769                    msg.append(", answer=");
13770                    msg.append(answer);
13771    
13772                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13773    
13774                    throw new NoSuchMessageException(msg.toString());
13775            }
13776    
13777            /**
13778             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13779             *
13780             * @param groupId the group ID
13781             * @param categoryId the category ID
13782             * @param threadId the thread ID
13783             * @param answer the answer
13784             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13785             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13786             * @throws SystemException if a system exception occurred
13787             */
13788            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
13789                    long threadId, boolean answer, OrderByComparator orderByComparator)
13790                    throws SystemException {
13791                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
13792    
13793                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
13794                                    answer, count - 1, count, orderByComparator);
13795    
13796                    if (!list.isEmpty()) {
13797                            return list.get(0);
13798                    }
13799    
13800                    return null;
13801            }
13802    
13803            /**
13804             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13805             *
13806             * @param messageId the primary key of the current message-boards message
13807             * @param groupId the group ID
13808             * @param categoryId the category ID
13809             * @param threadId the thread ID
13810             * @param answer the answer
13811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13812             * @return the previous, current, and next message-boards message
13813             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13814             * @throws SystemException if a system exception occurred
13815             */
13816            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
13817                    long categoryId, long threadId, boolean answer,
13818                    OrderByComparator orderByComparator)
13819                    throws NoSuchMessageException, SystemException {
13820                    MBMessage mbMessage = findByPrimaryKey(messageId);
13821    
13822                    Session session = null;
13823    
13824                    try {
13825                            session = openSession();
13826    
13827                            MBMessage[] array = new MBMessageImpl[3];
13828    
13829                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
13830                                            categoryId, threadId, answer, orderByComparator, true);
13831    
13832                            array[1] = mbMessage;
13833    
13834                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
13835                                            categoryId, threadId, answer, orderByComparator, false);
13836    
13837                            return array;
13838                    }
13839                    catch (Exception e) {
13840                            throw processException(e);
13841                    }
13842                    finally {
13843                            closeSession(session);
13844                    }
13845            }
13846    
13847            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
13848                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13849                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
13850                    StringBundler query = null;
13851    
13852                    if (orderByComparator != null) {
13853                            query = new StringBundler(6 +
13854                                            (orderByComparator.getOrderByFields().length * 6));
13855                    }
13856                    else {
13857                            query = new StringBundler(3);
13858                    }
13859    
13860                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13861    
13862                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13863    
13864                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13865    
13866                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13867    
13868                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13869    
13870                    if (orderByComparator != null) {
13871                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13872    
13873                            if (orderByConditionFields.length > 0) {
13874                                    query.append(WHERE_AND);
13875                            }
13876    
13877                            for (int i = 0; i < orderByConditionFields.length; i++) {
13878                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13879                                    query.append(orderByConditionFields[i]);
13880    
13881                                    if ((i + 1) < orderByConditionFields.length) {
13882                                            if (orderByComparator.isAscending() ^ previous) {
13883                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13884                                            }
13885                                            else {
13886                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13887                                            }
13888                                    }
13889                                    else {
13890                                            if (orderByComparator.isAscending() ^ previous) {
13891                                                    query.append(WHERE_GREATER_THAN);
13892                                            }
13893                                            else {
13894                                                    query.append(WHERE_LESSER_THAN);
13895                                            }
13896                                    }
13897                            }
13898    
13899                            query.append(ORDER_BY_CLAUSE);
13900    
13901                            String[] orderByFields = orderByComparator.getOrderByFields();
13902    
13903                            for (int i = 0; i < orderByFields.length; i++) {
13904                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13905                                    query.append(orderByFields[i]);
13906    
13907                                    if ((i + 1) < orderByFields.length) {
13908                                            if (orderByComparator.isAscending() ^ previous) {
13909                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13910                                            }
13911                                            else {
13912                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13913                                            }
13914                                    }
13915                                    else {
13916                                            if (orderByComparator.isAscending() ^ previous) {
13917                                                    query.append(ORDER_BY_ASC);
13918                                            }
13919                                            else {
13920                                                    query.append(ORDER_BY_DESC);
13921                                            }
13922                                    }
13923                            }
13924                    }
13925    
13926                    else {
13927                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13928                    }
13929    
13930                    String sql = query.toString();
13931    
13932                    Query q = session.createQuery(sql);
13933    
13934                    q.setFirstResult(0);
13935                    q.setMaxResults(2);
13936    
13937                    QueryPos qPos = QueryPos.getInstance(q);
13938    
13939                    qPos.add(groupId);
13940    
13941                    qPos.add(categoryId);
13942    
13943                    qPos.add(threadId);
13944    
13945                    qPos.add(answer);
13946    
13947                    if (orderByComparator != null) {
13948                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13949    
13950                            for (Object value : values) {
13951                                    qPos.add(value);
13952                            }
13953                    }
13954    
13955                    List<MBMessage> list = q.list();
13956    
13957                    if (list.size() == 2) {
13958                            return list.get(1);
13959                    }
13960                    else {
13961                            return null;
13962                    }
13963            }
13964    
13965            /**
13966             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13967             *
13968             * @param groupId the group ID
13969             * @param categoryId the category ID
13970             * @param threadId the thread ID
13971             * @param answer the answer
13972             * @return the matching message-boards messages that the user has permission to view
13973             * @throws SystemException if a system exception occurred
13974             */
13975            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13976                    long threadId, boolean answer) throws SystemException {
13977                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13978                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13979            }
13980    
13981            /**
13982             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13983             *
13984             * <p>
13985             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13986             * </p>
13987             *
13988             * @param groupId the group ID
13989             * @param categoryId the category ID
13990             * @param threadId the thread ID
13991             * @param answer the answer
13992             * @param start the lower bound of the range of message-boards messages
13993             * @param end the upper bound of the range of message-boards messages (not inclusive)
13994             * @return the range of matching message-boards messages that the user has permission to view
13995             * @throws SystemException if a system exception occurred
13996             */
13997            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13998                    long threadId, boolean answer, int start, int end)
13999                    throws SystemException {
14000                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
14001                            start, end, null);
14002            }
14003    
14004            /**
14005             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14006             *
14007             * <p>
14008             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14009             * </p>
14010             *
14011             * @param groupId the group ID
14012             * @param categoryId the category ID
14013             * @param threadId the thread ID
14014             * @param answer the answer
14015             * @param start the lower bound of the range of message-boards messages
14016             * @param end the upper bound of the range of message-boards messages (not inclusive)
14017             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14018             * @return the ordered range of matching message-boards messages that the user has permission to view
14019             * @throws SystemException if a system exception occurred
14020             */
14021            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
14022                    long threadId, boolean answer, int start, int end,
14023                    OrderByComparator orderByComparator) throws SystemException {
14024                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14025                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
14026                                    end, orderByComparator);
14027                    }
14028    
14029                    StringBundler query = null;
14030    
14031                    if (orderByComparator != null) {
14032                            query = new StringBundler(6 +
14033                                            (orderByComparator.getOrderByFields().length * 3));
14034                    }
14035                    else {
14036                            query = new StringBundler(6);
14037                    }
14038    
14039                    if (getDB().isSupportsInlineDistinct()) {
14040                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14041                    }
14042                    else {
14043                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14044                    }
14045    
14046                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14047    
14048                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14049    
14050                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14051    
14052                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14053    
14054                    if (!getDB().isSupportsInlineDistinct()) {
14055                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14056                    }
14057    
14058                    if (orderByComparator != null) {
14059                            if (getDB().isSupportsInlineDistinct()) {
14060                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14061                                            orderByComparator);
14062                            }
14063                            else {
14064                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14065                                            orderByComparator);
14066                            }
14067                    }
14068    
14069                    else {
14070                            if (getDB().isSupportsInlineDistinct()) {
14071                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14072                            }
14073                            else {
14074                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14075                            }
14076                    }
14077    
14078                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14079                                    MBMessage.class.getName(),
14080                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14081    
14082                    Session session = null;
14083    
14084                    try {
14085                            session = openSession();
14086    
14087                            SQLQuery q = session.createSQLQuery(sql);
14088    
14089                            if (getDB().isSupportsInlineDistinct()) {
14090                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14091                            }
14092                            else {
14093                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14094                            }
14095    
14096                            QueryPos qPos = QueryPos.getInstance(q);
14097    
14098                            qPos.add(groupId);
14099    
14100                            qPos.add(categoryId);
14101    
14102                            qPos.add(threadId);
14103    
14104                            qPos.add(answer);
14105    
14106                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
14107                    }
14108                    catch (Exception e) {
14109                            throw processException(e);
14110                    }
14111                    finally {
14112                            closeSession(session);
14113                    }
14114            }
14115    
14116            /**
14117             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14118             *
14119             * @param messageId the primary key of the current message-boards message
14120             * @param groupId the group ID
14121             * @param categoryId the category ID
14122             * @param threadId the thread ID
14123             * @param answer the answer
14124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14125             * @return the previous, current, and next message-boards message
14126             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14127             * @throws SystemException if a system exception occurred
14128             */
14129            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
14130                    long groupId, long categoryId, long threadId, boolean answer,
14131                    OrderByComparator orderByComparator)
14132                    throws NoSuchMessageException, SystemException {
14133                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14134                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
14135                                    threadId, answer, orderByComparator);
14136                    }
14137    
14138                    MBMessage mbMessage = findByPrimaryKey(messageId);
14139    
14140                    Session session = null;
14141    
14142                    try {
14143                            session = openSession();
14144    
14145                            MBMessage[] array = new MBMessageImpl[3];
14146    
14147                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
14148                                            groupId, categoryId, threadId, answer, orderByComparator,
14149                                            true);
14150    
14151                            array[1] = mbMessage;
14152    
14153                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
14154                                            groupId, categoryId, threadId, answer, orderByComparator,
14155                                            false);
14156    
14157                            return array;
14158                    }
14159                    catch (Exception e) {
14160                            throw processException(e);
14161                    }
14162                    finally {
14163                            closeSession(session);
14164                    }
14165            }
14166    
14167            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
14168                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14169                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
14170                    StringBundler query = null;
14171    
14172                    if (orderByComparator != null) {
14173                            query = new StringBundler(6 +
14174                                            (orderByComparator.getOrderByFields().length * 6));
14175                    }
14176                    else {
14177                            query = new StringBundler(3);
14178                    }
14179    
14180                    if (getDB().isSupportsInlineDistinct()) {
14181                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14182                    }
14183                    else {
14184                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14185                    }
14186    
14187                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14188    
14189                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14190    
14191                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14192    
14193                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14194    
14195                    if (!getDB().isSupportsInlineDistinct()) {
14196                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14197                    }
14198    
14199                    if (orderByComparator != null) {
14200                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14201    
14202                            if (orderByConditionFields.length > 0) {
14203                                    query.append(WHERE_AND);
14204                            }
14205    
14206                            for (int i = 0; i < orderByConditionFields.length; i++) {
14207                                    if (getDB().isSupportsInlineDistinct()) {
14208                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14209                                    }
14210                                    else {
14211                                            query.append(_ORDER_BY_ENTITY_TABLE);
14212                                    }
14213    
14214                                    query.append(orderByConditionFields[i]);
14215    
14216                                    if ((i + 1) < orderByConditionFields.length) {
14217                                            if (orderByComparator.isAscending() ^ previous) {
14218                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14219                                            }
14220                                            else {
14221                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14222                                            }
14223                                    }
14224                                    else {
14225                                            if (orderByComparator.isAscending() ^ previous) {
14226                                                    query.append(WHERE_GREATER_THAN);
14227                                            }
14228                                            else {
14229                                                    query.append(WHERE_LESSER_THAN);
14230                                            }
14231                                    }
14232                            }
14233    
14234                            query.append(ORDER_BY_CLAUSE);
14235    
14236                            String[] orderByFields = orderByComparator.getOrderByFields();
14237    
14238                            for (int i = 0; i < orderByFields.length; i++) {
14239                                    if (getDB().isSupportsInlineDistinct()) {
14240                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14241                                    }
14242                                    else {
14243                                            query.append(_ORDER_BY_ENTITY_TABLE);
14244                                    }
14245    
14246                                    query.append(orderByFields[i]);
14247    
14248                                    if ((i + 1) < orderByFields.length) {
14249                                            if (orderByComparator.isAscending() ^ previous) {
14250                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14251                                            }
14252                                            else {
14253                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14254                                            }
14255                                    }
14256                                    else {
14257                                            if (orderByComparator.isAscending() ^ previous) {
14258                                                    query.append(ORDER_BY_ASC);
14259                                            }
14260                                            else {
14261                                                    query.append(ORDER_BY_DESC);
14262                                            }
14263                                    }
14264                            }
14265                    }
14266    
14267                    else {
14268                            if (getDB().isSupportsInlineDistinct()) {
14269                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14270                            }
14271                            else {
14272                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14273                            }
14274                    }
14275    
14276                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14277                                    MBMessage.class.getName(),
14278                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14279    
14280                    SQLQuery q = session.createSQLQuery(sql);
14281    
14282                    q.setFirstResult(0);
14283                    q.setMaxResults(2);
14284    
14285                    if (getDB().isSupportsInlineDistinct()) {
14286                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14287                    }
14288                    else {
14289                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14290                    }
14291    
14292                    QueryPos qPos = QueryPos.getInstance(q);
14293    
14294                    qPos.add(groupId);
14295    
14296                    qPos.add(categoryId);
14297    
14298                    qPos.add(threadId);
14299    
14300                    qPos.add(answer);
14301    
14302                    if (orderByComparator != null) {
14303                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14304    
14305                            for (Object value : values) {
14306                                    qPos.add(value);
14307                            }
14308                    }
14309    
14310                    List<MBMessage> list = q.list();
14311    
14312                    if (list.size() == 2) {
14313                            return list.get(1);
14314                    }
14315                    else {
14316                            return null;
14317                    }
14318            }
14319    
14320            /**
14321             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14322             *
14323             * @param groupId the group ID
14324             * @param categoryId the category ID
14325             * @param threadId the thread ID
14326             * @param status the status
14327             * @return the matching message-boards messages
14328             * @throws SystemException if a system exception occurred
14329             */
14330            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14331                    long threadId, int status) throws SystemException {
14332                    return findByG_C_T_S(groupId, categoryId, threadId, status,
14333                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14334            }
14335    
14336            /**
14337             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14338             *
14339             * <p>
14340             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14341             * </p>
14342             *
14343             * @param groupId the group ID
14344             * @param categoryId the category ID
14345             * @param threadId the thread ID
14346             * @param status the status
14347             * @param start the lower bound of the range of message-boards messages
14348             * @param end the upper bound of the range of message-boards messages (not inclusive)
14349             * @return the range of matching message-boards messages
14350             * @throws SystemException if a system exception occurred
14351             */
14352            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14353                    long threadId, int status, int start, int end)
14354                    throws SystemException {
14355                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
14356                            null);
14357            }
14358    
14359            /**
14360             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14361             *
14362             * <p>
14363             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14364             * </p>
14365             *
14366             * @param groupId the group ID
14367             * @param categoryId the category ID
14368             * @param threadId the thread ID
14369             * @param status the status
14370             * @param start the lower bound of the range of message-boards messages
14371             * @param end the upper bound of the range of message-boards messages (not inclusive)
14372             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14373             * @return the ordered range of matching message-boards messages
14374             * @throws SystemException if a system exception occurred
14375             */
14376            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14377                    long threadId, int status, int start, int end,
14378                    OrderByComparator orderByComparator) throws SystemException {
14379                    FinderPath finderPath = null;
14380                    Object[] finderArgs = null;
14381    
14382                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14383                                    (orderByComparator == null)) {
14384                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
14385                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
14386                    }
14387                    else {
14388                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
14389                            finderArgs = new Object[] {
14390                                            groupId, categoryId, threadId, status,
14391                                            
14392                                            start, end, orderByComparator
14393                                    };
14394                    }
14395    
14396                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14397                                    finderArgs, this);
14398    
14399                    if ((list != null) && !list.isEmpty()) {
14400                            for (MBMessage mbMessage : list) {
14401                                    if ((groupId != mbMessage.getGroupId()) ||
14402                                                    (categoryId != mbMessage.getCategoryId()) ||
14403                                                    (threadId != mbMessage.getThreadId()) ||
14404                                                    (status != mbMessage.getStatus())) {
14405                                            list = null;
14406    
14407                                            break;
14408                                    }
14409                            }
14410                    }
14411    
14412                    if (list == null) {
14413                            StringBundler query = null;
14414    
14415                            if (orderByComparator != null) {
14416                                    query = new StringBundler(6 +
14417                                                    (orderByComparator.getOrderByFields().length * 3));
14418                            }
14419                            else {
14420                                    query = new StringBundler(6);
14421                            }
14422    
14423                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14424    
14425                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14426    
14427                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14428    
14429                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14430    
14431                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14432    
14433                            if (orderByComparator != null) {
14434                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14435                                            orderByComparator);
14436                            }
14437    
14438                            else {
14439                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14440                            }
14441    
14442                            String sql = query.toString();
14443    
14444                            Session session = null;
14445    
14446                            try {
14447                                    session = openSession();
14448    
14449                                    Query q = session.createQuery(sql);
14450    
14451                                    QueryPos qPos = QueryPos.getInstance(q);
14452    
14453                                    qPos.add(groupId);
14454    
14455                                    qPos.add(categoryId);
14456    
14457                                    qPos.add(threadId);
14458    
14459                                    qPos.add(status);
14460    
14461                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
14462                                                    end);
14463                            }
14464                            catch (Exception e) {
14465                                    throw processException(e);
14466                            }
14467                            finally {
14468                                    if (list == null) {
14469                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14470                                    }
14471                                    else {
14472                                            cacheResult(list);
14473    
14474                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14475                                    }
14476    
14477                                    closeSession(session);
14478                            }
14479                    }
14480    
14481                    return list;
14482            }
14483    
14484            /**
14485             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14486             *
14487             * @param groupId the group ID
14488             * @param categoryId the category ID
14489             * @param threadId the thread ID
14490             * @param status the status
14491             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14492             * @return the first matching message-boards message
14493             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14494             * @throws SystemException if a system exception occurred
14495             */
14496            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
14497                    long threadId, int status, OrderByComparator orderByComparator)
14498                    throws NoSuchMessageException, SystemException {
14499                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
14500                                    threadId, status, orderByComparator);
14501    
14502                    if (mbMessage != null) {
14503                            return mbMessage;
14504                    }
14505    
14506                    StringBundler msg = new StringBundler(10);
14507    
14508                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14509    
14510                    msg.append("groupId=");
14511                    msg.append(groupId);
14512    
14513                    msg.append(", categoryId=");
14514                    msg.append(categoryId);
14515    
14516                    msg.append(", threadId=");
14517                    msg.append(threadId);
14518    
14519                    msg.append(", status=");
14520                    msg.append(status);
14521    
14522                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14523    
14524                    throw new NoSuchMessageException(msg.toString());
14525            }
14526    
14527            /**
14528             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14529             *
14530             * @param groupId the group ID
14531             * @param categoryId the category ID
14532             * @param threadId the thread ID
14533             * @param status the status
14534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14535             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14536             * @throws SystemException if a system exception occurred
14537             */
14538            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
14539                    long threadId, int status, OrderByComparator orderByComparator)
14540                    throws SystemException {
14541                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
14542                                    status, 0, 1, orderByComparator);
14543    
14544                    if (!list.isEmpty()) {
14545                            return list.get(0);
14546                    }
14547    
14548                    return null;
14549            }
14550    
14551            /**
14552             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14553             *
14554             * @param groupId the group ID
14555             * @param categoryId the category ID
14556             * @param threadId the thread ID
14557             * @param status the status
14558             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14559             * @return the last matching message-boards message
14560             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14561             * @throws SystemException if a system exception occurred
14562             */
14563            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
14564                    long threadId, int status, OrderByComparator orderByComparator)
14565                    throws NoSuchMessageException, SystemException {
14566                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
14567                                    threadId, status, orderByComparator);
14568    
14569                    if (mbMessage != null) {
14570                            return mbMessage;
14571                    }
14572    
14573                    StringBundler msg = new StringBundler(10);
14574    
14575                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14576    
14577                    msg.append("groupId=");
14578                    msg.append(groupId);
14579    
14580                    msg.append(", categoryId=");
14581                    msg.append(categoryId);
14582    
14583                    msg.append(", threadId=");
14584                    msg.append(threadId);
14585    
14586                    msg.append(", status=");
14587                    msg.append(status);
14588    
14589                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14590    
14591                    throw new NoSuchMessageException(msg.toString());
14592            }
14593    
14594            /**
14595             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14596             *
14597             * @param groupId the group ID
14598             * @param categoryId the category ID
14599             * @param threadId the thread ID
14600             * @param status the status
14601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14602             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14603             * @throws SystemException if a system exception occurred
14604             */
14605            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
14606                    long threadId, int status, OrderByComparator orderByComparator)
14607                    throws SystemException {
14608                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
14609    
14610                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
14611                                    status, count - 1, count, orderByComparator);
14612    
14613                    if (!list.isEmpty()) {
14614                            return list.get(0);
14615                    }
14616    
14617                    return null;
14618            }
14619    
14620            /**
14621             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14622             *
14623             * @param messageId the primary key of the current message-boards message
14624             * @param groupId the group ID
14625             * @param categoryId the category ID
14626             * @param threadId the thread ID
14627             * @param status the status
14628             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14629             * @return the previous, current, and next message-boards message
14630             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14631             * @throws SystemException if a system exception occurred
14632             */
14633            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
14634                    long categoryId, long threadId, int status,
14635                    OrderByComparator orderByComparator)
14636                    throws NoSuchMessageException, SystemException {
14637                    MBMessage mbMessage = findByPrimaryKey(messageId);
14638    
14639                    Session session = null;
14640    
14641                    try {
14642                            session = openSession();
14643    
14644                            MBMessage[] array = new MBMessageImpl[3];
14645    
14646                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
14647                                            categoryId, threadId, status, orderByComparator, true);
14648    
14649                            array[1] = mbMessage;
14650    
14651                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
14652                                            categoryId, threadId, status, orderByComparator, false);
14653    
14654                            return array;
14655                    }
14656                    catch (Exception e) {
14657                            throw processException(e);
14658                    }
14659                    finally {
14660                            closeSession(session);
14661                    }
14662            }
14663    
14664            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
14665                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14666                    int status, OrderByComparator orderByComparator, boolean previous) {
14667                    StringBundler query = null;
14668    
14669                    if (orderByComparator != null) {
14670                            query = new StringBundler(6 +
14671                                            (orderByComparator.getOrderByFields().length * 6));
14672                    }
14673                    else {
14674                            query = new StringBundler(3);
14675                    }
14676    
14677                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14678    
14679                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14680    
14681                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14682    
14683                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14684    
14685                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14686    
14687                    if (orderByComparator != null) {
14688                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14689    
14690                            if (orderByConditionFields.length > 0) {
14691                                    query.append(WHERE_AND);
14692                            }
14693    
14694                            for (int i = 0; i < orderByConditionFields.length; i++) {
14695                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14696                                    query.append(orderByConditionFields[i]);
14697    
14698                                    if ((i + 1) < orderByConditionFields.length) {
14699                                            if (orderByComparator.isAscending() ^ previous) {
14700                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14701                                            }
14702                                            else {
14703                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14704                                            }
14705                                    }
14706                                    else {
14707                                            if (orderByComparator.isAscending() ^ previous) {
14708                                                    query.append(WHERE_GREATER_THAN);
14709                                            }
14710                                            else {
14711                                                    query.append(WHERE_LESSER_THAN);
14712                                            }
14713                                    }
14714                            }
14715    
14716                            query.append(ORDER_BY_CLAUSE);
14717    
14718                            String[] orderByFields = orderByComparator.getOrderByFields();
14719    
14720                            for (int i = 0; i < orderByFields.length; i++) {
14721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14722                                    query.append(orderByFields[i]);
14723    
14724                                    if ((i + 1) < orderByFields.length) {
14725                                            if (orderByComparator.isAscending() ^ previous) {
14726                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14727                                            }
14728                                            else {
14729                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14730                                            }
14731                                    }
14732                                    else {
14733                                            if (orderByComparator.isAscending() ^ previous) {
14734                                                    query.append(ORDER_BY_ASC);
14735                                            }
14736                                            else {
14737                                                    query.append(ORDER_BY_DESC);
14738                                            }
14739                                    }
14740                            }
14741                    }
14742    
14743                    else {
14744                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14745                    }
14746    
14747                    String sql = query.toString();
14748    
14749                    Query q = session.createQuery(sql);
14750    
14751                    q.setFirstResult(0);
14752                    q.setMaxResults(2);
14753    
14754                    QueryPos qPos = QueryPos.getInstance(q);
14755    
14756                    qPos.add(groupId);
14757    
14758                    qPos.add(categoryId);
14759    
14760                    qPos.add(threadId);
14761    
14762                    qPos.add(status);
14763    
14764                    if (orderByComparator != null) {
14765                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14766    
14767                            for (Object value : values) {
14768                                    qPos.add(value);
14769                            }
14770                    }
14771    
14772                    List<MBMessage> list = q.list();
14773    
14774                    if (list.size() == 2) {
14775                            return list.get(1);
14776                    }
14777                    else {
14778                            return null;
14779                    }
14780            }
14781    
14782            /**
14783             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14784             *
14785             * @param groupId the group ID
14786             * @param categoryId the category ID
14787             * @param threadId the thread ID
14788             * @param status the status
14789             * @return the matching message-boards messages that the user has permission to view
14790             * @throws SystemException if a system exception occurred
14791             */
14792            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14793                    long threadId, int status) throws SystemException {
14794                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
14795                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14796            }
14797    
14798            /**
14799             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14800             *
14801             * <p>
14802             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14803             * </p>
14804             *
14805             * @param groupId the group ID
14806             * @param categoryId the category ID
14807             * @param threadId the thread ID
14808             * @param status the status
14809             * @param start the lower bound of the range of message-boards messages
14810             * @param end the upper bound of the range of message-boards messages (not inclusive)
14811             * @return the range of matching message-boards messages that the user has permission to view
14812             * @throws SystemException if a system exception occurred
14813             */
14814            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14815                    long threadId, int status, int start, int end)
14816                    throws SystemException {
14817                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
14818                            start, end, null);
14819            }
14820    
14821            /**
14822             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14823             *
14824             * <p>
14825             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14826             * </p>
14827             *
14828             * @param groupId the group ID
14829             * @param categoryId the category ID
14830             * @param threadId the thread ID
14831             * @param status the status
14832             * @param start the lower bound of the range of message-boards messages
14833             * @param end the upper bound of the range of message-boards messages (not inclusive)
14834             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14835             * @return the ordered range of matching message-boards messages that the user has permission to view
14836             * @throws SystemException if a system exception occurred
14837             */
14838            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14839                    long threadId, int status, int start, int end,
14840                    OrderByComparator orderByComparator) throws SystemException {
14841                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14842                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
14843                                    end, orderByComparator);
14844                    }
14845    
14846                    StringBundler query = null;
14847    
14848                    if (orderByComparator != null) {
14849                            query = new StringBundler(6 +
14850                                            (orderByComparator.getOrderByFields().length * 3));
14851                    }
14852                    else {
14853                            query = new StringBundler(6);
14854                    }
14855    
14856                    if (getDB().isSupportsInlineDistinct()) {
14857                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14858                    }
14859                    else {
14860                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14861                    }
14862    
14863                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14864    
14865                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14866    
14867                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14868    
14869                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14870    
14871                    if (!getDB().isSupportsInlineDistinct()) {
14872                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14873                    }
14874    
14875                    if (orderByComparator != null) {
14876                            if (getDB().isSupportsInlineDistinct()) {
14877                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14878                                            orderByComparator);
14879                            }
14880                            else {
14881                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14882                                            orderByComparator);
14883                            }
14884                    }
14885    
14886                    else {
14887                            if (getDB().isSupportsInlineDistinct()) {
14888                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14889                            }
14890                            else {
14891                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14892                            }
14893                    }
14894    
14895                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14896                                    MBMessage.class.getName(),
14897                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14898    
14899                    Session session = null;
14900    
14901                    try {
14902                            session = openSession();
14903    
14904                            SQLQuery q = session.createSQLQuery(sql);
14905    
14906                            if (getDB().isSupportsInlineDistinct()) {
14907                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14908                            }
14909                            else {
14910                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14911                            }
14912    
14913                            QueryPos qPos = QueryPos.getInstance(q);
14914    
14915                            qPos.add(groupId);
14916    
14917                            qPos.add(categoryId);
14918    
14919                            qPos.add(threadId);
14920    
14921                            qPos.add(status);
14922    
14923                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
14924                    }
14925                    catch (Exception e) {
14926                            throw processException(e);
14927                    }
14928                    finally {
14929                            closeSession(session);
14930                    }
14931            }
14932    
14933            /**
14934             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14935             *
14936             * @param messageId the primary key of the current message-boards message
14937             * @param groupId the group ID
14938             * @param categoryId the category ID
14939             * @param threadId the thread ID
14940             * @param status the status
14941             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14942             * @return the previous, current, and next message-boards message
14943             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14944             * @throws SystemException if a system exception occurred
14945             */
14946            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
14947                    long groupId, long categoryId, long threadId, int status,
14948                    OrderByComparator orderByComparator)
14949                    throws NoSuchMessageException, SystemException {
14950                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14951                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
14952                                    threadId, status, orderByComparator);
14953                    }
14954    
14955                    MBMessage mbMessage = findByPrimaryKey(messageId);
14956    
14957                    Session session = null;
14958    
14959                    try {
14960                            session = openSession();
14961    
14962                            MBMessage[] array = new MBMessageImpl[3];
14963    
14964                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
14965                                            groupId, categoryId, threadId, status, orderByComparator,
14966                                            true);
14967    
14968                            array[1] = mbMessage;
14969    
14970                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
14971                                            groupId, categoryId, threadId, status, orderByComparator,
14972                                            false);
14973    
14974                            return array;
14975                    }
14976                    catch (Exception e) {
14977                            throw processException(e);
14978                    }
14979                    finally {
14980                            closeSession(session);
14981                    }
14982            }
14983    
14984            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
14985                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14986                    int status, OrderByComparator orderByComparator, boolean previous) {
14987                    StringBundler query = null;
14988    
14989                    if (orderByComparator != null) {
14990                            query = new StringBundler(6 +
14991                                            (orderByComparator.getOrderByFields().length * 6));
14992                    }
14993                    else {
14994                            query = new StringBundler(3);
14995                    }
14996    
14997                    if (getDB().isSupportsInlineDistinct()) {
14998                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14999                    }
15000                    else {
15001                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
15002                    }
15003    
15004                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
15005    
15006                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
15007    
15008                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
15009    
15010                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
15011    
15012                    if (!getDB().isSupportsInlineDistinct()) {
15013                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
15014                    }
15015    
15016                    if (orderByComparator != null) {
15017                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15018    
15019                            if (orderByConditionFields.length > 0) {
15020                                    query.append(WHERE_AND);
15021                            }
15022    
15023                            for (int i = 0; i < orderByConditionFields.length; i++) {
15024                                    if (getDB().isSupportsInlineDistinct()) {
15025                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15026                                    }
15027                                    else {
15028                                            query.append(_ORDER_BY_ENTITY_TABLE);
15029                                    }
15030    
15031                                    query.append(orderByConditionFields[i]);
15032    
15033                                    if ((i + 1) < orderByConditionFields.length) {
15034                                            if (orderByComparator.isAscending() ^ previous) {
15035                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15036                                            }
15037                                            else {
15038                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15039                                            }
15040                                    }
15041                                    else {
15042                                            if (orderByComparator.isAscending() ^ previous) {
15043                                                    query.append(WHERE_GREATER_THAN);
15044                                            }
15045                                            else {
15046                                                    query.append(WHERE_LESSER_THAN);
15047                                            }
15048                                    }
15049                            }
15050    
15051                            query.append(ORDER_BY_CLAUSE);
15052    
15053                            String[] orderByFields = orderByComparator.getOrderByFields();
15054    
15055                            for (int i = 0; i < orderByFields.length; i++) {
15056                                    if (getDB().isSupportsInlineDistinct()) {
15057                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15058                                    }
15059                                    else {
15060                                            query.append(_ORDER_BY_ENTITY_TABLE);
15061                                    }
15062    
15063                                    query.append(orderByFields[i]);
15064    
15065                                    if ((i + 1) < orderByFields.length) {
15066                                            if (orderByComparator.isAscending() ^ previous) {
15067                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15068                                            }
15069                                            else {
15070                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15071                                            }
15072                                    }
15073                                    else {
15074                                            if (orderByComparator.isAscending() ^ previous) {
15075                                                    query.append(ORDER_BY_ASC);
15076                                            }
15077                                            else {
15078                                                    query.append(ORDER_BY_DESC);
15079                                            }
15080                                    }
15081                            }
15082                    }
15083    
15084                    else {
15085                            if (getDB().isSupportsInlineDistinct()) {
15086                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15087                            }
15088                            else {
15089                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
15090                            }
15091                    }
15092    
15093                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15094                                    MBMessage.class.getName(),
15095                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15096    
15097                    SQLQuery q = session.createSQLQuery(sql);
15098    
15099                    q.setFirstResult(0);
15100                    q.setMaxResults(2);
15101    
15102                    if (getDB().isSupportsInlineDistinct()) {
15103                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
15104                    }
15105                    else {
15106                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
15107                    }
15108    
15109                    QueryPos qPos = QueryPos.getInstance(q);
15110    
15111                    qPos.add(groupId);
15112    
15113                    qPos.add(categoryId);
15114    
15115                    qPos.add(threadId);
15116    
15117                    qPos.add(status);
15118    
15119                    if (orderByComparator != null) {
15120                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15121    
15122                            for (Object value : values) {
15123                                    qPos.add(value);
15124                            }
15125                    }
15126    
15127                    List<MBMessage> list = q.list();
15128    
15129                    if (list.size() == 2) {
15130                            return list.get(1);
15131                    }
15132                    else {
15133                            return null;
15134                    }
15135            }
15136    
15137            /**
15138             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15139             *
15140             * @param userId the user ID
15141             * @param classNameId the class name ID
15142             * @param classPK the class p k
15143             * @param status the status
15144             * @return the matching message-boards messages
15145             * @throws SystemException if a system exception occurred
15146             */
15147            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15148                    long classPK, int status) throws SystemException {
15149                    return findByU_C_C_S(userId, classNameId, classPK, status,
15150                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15151            }
15152    
15153            /**
15154             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15155             *
15156             * <p>
15157             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15158             * </p>
15159             *
15160             * @param userId the user ID
15161             * @param classNameId the class name ID
15162             * @param classPK the class p k
15163             * @param status the status
15164             * @param start the lower bound of the range of message-boards messages
15165             * @param end the upper bound of the range of message-boards messages (not inclusive)
15166             * @return the range of matching message-boards messages
15167             * @throws SystemException if a system exception occurred
15168             */
15169            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15170                    long classPK, int status, int start, int end) throws SystemException {
15171                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
15172                            null);
15173            }
15174    
15175            /**
15176             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15177             *
15178             * <p>
15179             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15180             * </p>
15181             *
15182             * @param userId the user ID
15183             * @param classNameId the class name ID
15184             * @param classPK the class p k
15185             * @param status the status
15186             * @param start the lower bound of the range of message-boards messages
15187             * @param end the upper bound of the range of message-boards messages (not inclusive)
15188             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15189             * @return the ordered range of matching message-boards messages
15190             * @throws SystemException if a system exception occurred
15191             */
15192            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15193                    long classPK, int status, int start, int end,
15194                    OrderByComparator orderByComparator) throws SystemException {
15195                    FinderPath finderPath = null;
15196                    Object[] finderArgs = null;
15197    
15198                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15199                                    (orderByComparator == null)) {
15200                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
15201                            finderArgs = new Object[] { userId, classNameId, classPK, status };
15202                    }
15203                    else {
15204                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
15205                            finderArgs = new Object[] {
15206                                            userId, classNameId, classPK, status,
15207                                            
15208                                            start, end, orderByComparator
15209                                    };
15210                    }
15211    
15212                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15213                                    finderArgs, this);
15214    
15215                    if ((list != null) && !list.isEmpty()) {
15216                            for (MBMessage mbMessage : list) {
15217                                    if ((userId != mbMessage.getUserId()) ||
15218                                                    (classNameId != mbMessage.getClassNameId()) ||
15219                                                    (classPK != mbMessage.getClassPK()) ||
15220                                                    (status != mbMessage.getStatus())) {
15221                                            list = null;
15222    
15223                                            break;
15224                                    }
15225                            }
15226                    }
15227    
15228                    if (list == null) {
15229                            StringBundler query = null;
15230    
15231                            if (orderByComparator != null) {
15232                                    query = new StringBundler(6 +
15233                                                    (orderByComparator.getOrderByFields().length * 3));
15234                            }
15235                            else {
15236                                    query = new StringBundler(6);
15237                            }
15238    
15239                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15240    
15241                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
15242    
15243                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
15244    
15245                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
15246    
15247                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
15248    
15249                            if (orderByComparator != null) {
15250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15251                                            orderByComparator);
15252                            }
15253    
15254                            else {
15255                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15256                            }
15257    
15258                            String sql = query.toString();
15259    
15260                            Session session = null;
15261    
15262                            try {
15263                                    session = openSession();
15264    
15265                                    Query q = session.createQuery(sql);
15266    
15267                                    QueryPos qPos = QueryPos.getInstance(q);
15268    
15269                                    qPos.add(userId);
15270    
15271                                    qPos.add(classNameId);
15272    
15273                                    qPos.add(classPK);
15274    
15275                                    qPos.add(status);
15276    
15277                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
15278                                                    end);
15279                            }
15280                            catch (Exception e) {
15281                                    throw processException(e);
15282                            }
15283                            finally {
15284                                    if (list == null) {
15285                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
15286                                    }
15287                                    else {
15288                                            cacheResult(list);
15289    
15290                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
15291                                    }
15292    
15293                                    closeSession(session);
15294                            }
15295                    }
15296    
15297                    return list;
15298            }
15299    
15300            /**
15301             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15302             *
15303             * @param userId the user ID
15304             * @param classNameId the class name ID
15305             * @param classPK the class p k
15306             * @param status the status
15307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15308             * @return the first matching message-boards message
15309             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15310             * @throws SystemException if a system exception occurred
15311             */
15312            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
15313                    long classPK, int status, OrderByComparator orderByComparator)
15314                    throws NoSuchMessageException, SystemException {
15315                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
15316                                    classPK, status, orderByComparator);
15317    
15318                    if (mbMessage != null) {
15319                            return mbMessage;
15320                    }
15321    
15322                    StringBundler msg = new StringBundler(10);
15323    
15324                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15325    
15326                    msg.append("userId=");
15327                    msg.append(userId);
15328    
15329                    msg.append(", classNameId=");
15330                    msg.append(classNameId);
15331    
15332                    msg.append(", classPK=");
15333                    msg.append(classPK);
15334    
15335                    msg.append(", status=");
15336                    msg.append(status);
15337    
15338                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15339    
15340                    throw new NoSuchMessageException(msg.toString());
15341            }
15342    
15343            /**
15344             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15345             *
15346             * @param userId the user ID
15347             * @param classNameId the class name ID
15348             * @param classPK the class p k
15349             * @param status the status
15350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15351             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15352             * @throws SystemException if a system exception occurred
15353             */
15354            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
15355                    long classPK, int status, OrderByComparator orderByComparator)
15356                    throws SystemException {
15357                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
15358                                    status, 0, 1, orderByComparator);
15359    
15360                    if (!list.isEmpty()) {
15361                            return list.get(0);
15362                    }
15363    
15364                    return null;
15365            }
15366    
15367            /**
15368             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15369             *
15370             * @param userId the user ID
15371             * @param classNameId the class name ID
15372             * @param classPK the class p k
15373             * @param status the status
15374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15375             * @return the last matching message-boards message
15376             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15377             * @throws SystemException if a system exception occurred
15378             */
15379            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
15380                    long classPK, int status, OrderByComparator orderByComparator)
15381                    throws NoSuchMessageException, SystemException {
15382                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
15383                                    status, orderByComparator);
15384    
15385                    if (mbMessage != null) {
15386                            return mbMessage;
15387                    }
15388    
15389                    StringBundler msg = new StringBundler(10);
15390    
15391                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15392    
15393                    msg.append("userId=");
15394                    msg.append(userId);
15395    
15396                    msg.append(", classNameId=");
15397                    msg.append(classNameId);
15398    
15399                    msg.append(", classPK=");
15400                    msg.append(classPK);
15401    
15402                    msg.append(", status=");
15403                    msg.append(status);
15404    
15405                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15406    
15407                    throw new NoSuchMessageException(msg.toString());
15408            }
15409    
15410            /**
15411             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15412             *
15413             * @param userId the user ID
15414             * @param classNameId the class name ID
15415             * @param classPK the class p k
15416             * @param status the status
15417             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15418             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15419             * @throws SystemException if a system exception occurred
15420             */
15421            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
15422                    long classPK, int status, OrderByComparator orderByComparator)
15423                    throws SystemException {
15424                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
15425    
15426                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
15427                                    status, count - 1, count, orderByComparator);
15428    
15429                    if (!list.isEmpty()) {
15430                            return list.get(0);
15431                    }
15432    
15433                    return null;
15434            }
15435    
15436            /**
15437             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15438             *
15439             * @param messageId the primary key of the current message-boards message
15440             * @param userId the user ID
15441             * @param classNameId the class name ID
15442             * @param classPK the class p k
15443             * @param status the status
15444             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15445             * @return the previous, current, and next message-boards message
15446             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15447             * @throws SystemException if a system exception occurred
15448             */
15449            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
15450                    long classNameId, long classPK, int status,
15451                    OrderByComparator orderByComparator)
15452                    throws NoSuchMessageException, SystemException {
15453                    MBMessage mbMessage = findByPrimaryKey(messageId);
15454    
15455                    Session session = null;
15456    
15457                    try {
15458                            session = openSession();
15459    
15460                            MBMessage[] array = new MBMessageImpl[3];
15461    
15462                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
15463                                            classNameId, classPK, status, orderByComparator, true);
15464    
15465                            array[1] = mbMessage;
15466    
15467                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
15468                                            classNameId, classPK, status, orderByComparator, false);
15469    
15470                            return array;
15471                    }
15472                    catch (Exception e) {
15473                            throw processException(e);
15474                    }
15475                    finally {
15476                            closeSession(session);
15477                    }
15478            }
15479    
15480            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
15481                    MBMessage mbMessage, long userId, long classNameId, long classPK,
15482                    int status, OrderByComparator orderByComparator, boolean previous) {
15483                    StringBundler query = null;
15484    
15485                    if (orderByComparator != null) {
15486                            query = new StringBundler(6 +
15487                                            (orderByComparator.getOrderByFields().length * 6));
15488                    }
15489                    else {
15490                            query = new StringBundler(3);
15491                    }
15492    
15493                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15494    
15495                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
15496    
15497                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
15498    
15499                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
15500    
15501                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
15502    
15503                    if (orderByComparator != null) {
15504                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15505    
15506                            if (orderByConditionFields.length > 0) {
15507                                    query.append(WHERE_AND);
15508                            }
15509    
15510                            for (int i = 0; i < orderByConditionFields.length; i++) {
15511                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15512                                    query.append(orderByConditionFields[i]);
15513    
15514                                    if ((i + 1) < orderByConditionFields.length) {
15515                                            if (orderByComparator.isAscending() ^ previous) {
15516                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15517                                            }
15518                                            else {
15519                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15520                                            }
15521                                    }
15522                                    else {
15523                                            if (orderByComparator.isAscending() ^ previous) {
15524                                                    query.append(WHERE_GREATER_THAN);
15525                                            }
15526                                            else {
15527                                                    query.append(WHERE_LESSER_THAN);
15528                                            }
15529                                    }
15530                            }
15531    
15532                            query.append(ORDER_BY_CLAUSE);
15533    
15534                            String[] orderByFields = orderByComparator.getOrderByFields();
15535    
15536                            for (int i = 0; i < orderByFields.length; i++) {
15537                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15538                                    query.append(orderByFields[i]);
15539    
15540                                    if ((i + 1) < orderByFields.length) {
15541                                            if (orderByComparator.isAscending() ^ previous) {
15542                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15543                                            }
15544                                            else {
15545                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15546                                            }
15547                                    }
15548                                    else {
15549                                            if (orderByComparator.isAscending() ^ previous) {
15550                                                    query.append(ORDER_BY_ASC);
15551                                            }
15552                                            else {
15553                                                    query.append(ORDER_BY_DESC);
15554                                            }
15555                                    }
15556                            }
15557                    }
15558    
15559                    else {
15560                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15561                    }
15562    
15563                    String sql = query.toString();
15564    
15565                    Query q = session.createQuery(sql);
15566    
15567                    q.setFirstResult(0);
15568                    q.setMaxResults(2);
15569    
15570                    QueryPos qPos = QueryPos.getInstance(q);
15571    
15572                    qPos.add(userId);
15573    
15574                    qPos.add(classNameId);
15575    
15576                    qPos.add(classPK);
15577    
15578                    qPos.add(status);
15579    
15580                    if (orderByComparator != null) {
15581                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15582    
15583                            for (Object value : values) {
15584                                    qPos.add(value);
15585                            }
15586                    }
15587    
15588                    List<MBMessage> list = q.list();
15589    
15590                    if (list.size() == 2) {
15591                            return list.get(1);
15592                    }
15593                    else {
15594                            return null;
15595                    }
15596            }
15597    
15598            /**
15599             * Returns all the message-boards messages.
15600             *
15601             * @return the message-boards messages
15602             * @throws SystemException if a system exception occurred
15603             */
15604            public List<MBMessage> findAll() throws SystemException {
15605                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15606            }
15607    
15608            /**
15609             * Returns a range of all the message-boards messages.
15610             *
15611             * <p>
15612             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15613             * </p>
15614             *
15615             * @param start the lower bound of the range of message-boards messages
15616             * @param end the upper bound of the range of message-boards messages (not inclusive)
15617             * @return the range of message-boards messages
15618             * @throws SystemException if a system exception occurred
15619             */
15620            public List<MBMessage> findAll(int start, int end)
15621                    throws SystemException {
15622                    return findAll(start, end, null);
15623            }
15624    
15625            /**
15626             * Returns an ordered range of all the message-boards messages.
15627             *
15628             * <p>
15629             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15630             * </p>
15631             *
15632             * @param start the lower bound of the range of message-boards messages
15633             * @param end the upper bound of the range of message-boards messages (not inclusive)
15634             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15635             * @return the ordered range of message-boards messages
15636             * @throws SystemException if a system exception occurred
15637             */
15638            public List<MBMessage> findAll(int start, int end,
15639                    OrderByComparator orderByComparator) throws SystemException {
15640                    FinderPath finderPath = null;
15641                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
15642    
15643                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15644                                    (orderByComparator == null)) {
15645                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
15646                            finderArgs = FINDER_ARGS_EMPTY;
15647                    }
15648                    else {
15649                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
15650                            finderArgs = new Object[] { start, end, orderByComparator };
15651                    }
15652    
15653                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15654                                    finderArgs, this);
15655    
15656                    if (list == null) {
15657                            StringBundler query = null;
15658                            String sql = null;
15659    
15660                            if (orderByComparator != null) {
15661                                    query = new StringBundler(2 +
15662                                                    (orderByComparator.getOrderByFields().length * 3));
15663    
15664                                    query.append(_SQL_SELECT_MBMESSAGE);
15665    
15666                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15667                                            orderByComparator);
15668    
15669                                    sql = query.toString();
15670                            }
15671                            else {
15672                                    sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
15673                            }
15674    
15675                            Session session = null;
15676    
15677                            try {
15678                                    session = openSession();
15679    
15680                                    Query q = session.createQuery(sql);
15681    
15682                                    if (orderByComparator == null) {
15683                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15684                                                            start, end, false);
15685    
15686                                            Collections.sort(list);
15687                                    }
15688                                    else {
15689                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15690                                                            start, end);
15691                                    }
15692                            }
15693                            catch (Exception e) {
15694                                    throw processException(e);
15695                            }
15696                            finally {
15697                                    if (list == null) {
15698                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
15699                                    }
15700                                    else {
15701                                            cacheResult(list);
15702    
15703                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
15704                                    }
15705    
15706                                    closeSession(session);
15707                            }
15708                    }
15709    
15710                    return list;
15711            }
15712    
15713            /**
15714             * Removes all the message-boards messages where uuid = &#63; from the database.
15715             *
15716             * @param uuid the uuid
15717             * @throws SystemException if a system exception occurred
15718             */
15719            public void removeByUuid(String uuid) throws SystemException {
15720                    for (MBMessage mbMessage : findByUuid(uuid)) {
15721                            remove(mbMessage);
15722                    }
15723            }
15724    
15725            /**
15726             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
15727             *
15728             * @param uuid the uuid
15729             * @param groupId the group ID
15730             * @return the message-boards message that was removed
15731             * @throws SystemException if a system exception occurred
15732             */
15733            public MBMessage removeByUUID_G(String uuid, long groupId)
15734                    throws NoSuchMessageException, SystemException {
15735                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
15736    
15737                    return remove(mbMessage);
15738            }
15739    
15740            /**
15741             * Removes all the message-boards messages where groupId = &#63; from the database.
15742             *
15743             * @param groupId the group ID
15744             * @throws SystemException if a system exception occurred
15745             */
15746            public void removeByGroupId(long groupId) throws SystemException {
15747                    for (MBMessage mbMessage : findByGroupId(groupId)) {
15748                            remove(mbMessage);
15749                    }
15750            }
15751    
15752            /**
15753             * Removes all the message-boards messages where companyId = &#63; from the database.
15754             *
15755             * @param companyId the company ID
15756             * @throws SystemException if a system exception occurred
15757             */
15758            public void removeByCompanyId(long companyId) throws SystemException {
15759                    for (MBMessage mbMessage : findByCompanyId(companyId)) {
15760                            remove(mbMessage);
15761                    }
15762            }
15763    
15764            /**
15765             * Removes all the message-boards messages where threadId = &#63; from the database.
15766             *
15767             * @param threadId the thread ID
15768             * @throws SystemException if a system exception occurred
15769             */
15770            public void removeByThreadId(long threadId) throws SystemException {
15771                    for (MBMessage mbMessage : findByThreadId(threadId)) {
15772                            remove(mbMessage);
15773                    }
15774            }
15775    
15776            /**
15777             * Removes all the message-boards messages where threadId = &#63; from the database.
15778             *
15779             * @param threadId the thread ID
15780             * @throws SystemException if a system exception occurred
15781             */
15782            public void removeByThreadReplies(long threadId) throws SystemException {
15783                    for (MBMessage mbMessage : findByThreadReplies(threadId)) {
15784                            remove(mbMessage);
15785                    }
15786            }
15787    
15788            /**
15789             * Removes all the message-boards messages where userId = &#63; from the database.
15790             *
15791             * @param userId the user ID
15792             * @throws SystemException if a system exception occurred
15793             */
15794            public void removeByUserId(long userId) throws SystemException {
15795                    for (MBMessage mbMessage : findByUserId(userId)) {
15796                            remove(mbMessage);
15797                    }
15798            }
15799    
15800            /**
15801             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
15802             *
15803             * @param groupId the group ID
15804             * @param userId the user ID
15805             * @throws SystemException if a system exception occurred
15806             */
15807            public void removeByG_U(long groupId, long userId)
15808                    throws SystemException {
15809                    for (MBMessage mbMessage : findByG_U(groupId, userId)) {
15810                            remove(mbMessage);
15811                    }
15812            }
15813    
15814            /**
15815             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
15816             *
15817             * @param groupId the group ID
15818             * @param categoryId the category ID
15819             * @throws SystemException if a system exception occurred
15820             */
15821            public void removeByG_C(long groupId, long categoryId)
15822                    throws SystemException {
15823                    for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
15824                            remove(mbMessage);
15825                    }
15826            }
15827    
15828            /**
15829             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
15830             *
15831             * @param groupId the group ID
15832             * @param status the status
15833             * @throws SystemException if a system exception occurred
15834             */
15835            public void removeByG_S(long groupId, int status) throws SystemException {
15836                    for (MBMessage mbMessage : findByG_S(groupId, status)) {
15837                            remove(mbMessage);
15838                    }
15839            }
15840    
15841            /**
15842             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
15843             *
15844             * @param companyId the company ID
15845             * @param status the status
15846             * @throws SystemException if a system exception occurred
15847             */
15848            public void removeByC_S(long companyId, int status)
15849                    throws SystemException {
15850                    for (MBMessage mbMessage : findByC_S(companyId, status)) {
15851                            remove(mbMessage);
15852                    }
15853            }
15854    
15855            /**
15856             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
15857             *
15858             * @param userId the user ID
15859             * @param classNameId the class name ID
15860             * @throws SystemException if a system exception occurred
15861             */
15862            public void removeByU_C(long userId, long classNameId)
15863                    throws SystemException {
15864                    for (MBMessage mbMessage : findByU_C(userId, classNameId)) {
15865                            remove(mbMessage);
15866                    }
15867            }
15868    
15869            /**
15870             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
15871             *
15872             * @param classNameId the class name ID
15873             * @param classPK the class p k
15874             * @throws SystemException if a system exception occurred
15875             */
15876            public void removeByC_C(long classNameId, long classPK)
15877                    throws SystemException {
15878                    for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
15879                            remove(mbMessage);
15880                    }
15881            }
15882    
15883            /**
15884             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
15885             *
15886             * @param threadId the thread ID
15887             * @param parentMessageId the parent message ID
15888             * @throws SystemException if a system exception occurred
15889             */
15890            public void removeByT_P(long threadId, long parentMessageId)
15891                    throws SystemException {
15892                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
15893                            remove(mbMessage);
15894                    }
15895            }
15896    
15897            /**
15898             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
15899             *
15900             * @param threadId the thread ID
15901             * @param answer the answer
15902             * @throws SystemException if a system exception occurred
15903             */
15904            public void removeByT_A(long threadId, boolean answer)
15905                    throws SystemException {
15906                    for (MBMessage mbMessage : findByT_A(threadId, answer)) {
15907                            remove(mbMessage);
15908                    }
15909            }
15910    
15911            /**
15912             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
15913             *
15914             * @param threadId the thread ID
15915             * @param status the status
15916             * @throws SystemException if a system exception occurred
15917             */
15918            public void removeByT_S(long threadId, int status)
15919                    throws SystemException {
15920                    for (MBMessage mbMessage : findByT_S(threadId, status)) {
15921                            remove(mbMessage);
15922                    }
15923            }
15924    
15925            /**
15926             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
15927             *
15928             * @param threadId the thread ID
15929             * @param status the status
15930             * @throws SystemException if a system exception occurred
15931             */
15932            public void removeByTR_S(long threadId, int status)
15933                    throws SystemException {
15934                    for (MBMessage mbMessage : findByTR_S(threadId, status)) {
15935                            remove(mbMessage);
15936                    }
15937            }
15938    
15939            /**
15940             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
15941             *
15942             * @param groupId the group ID
15943             * @param userId the user ID
15944             * @param status the status
15945             * @throws SystemException if a system exception occurred
15946             */
15947            public void removeByG_U_S(long groupId, long userId, int status)
15948                    throws SystemException {
15949                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
15950                            remove(mbMessage);
15951                    }
15952            }
15953    
15954            /**
15955             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
15956             *
15957             * @param groupId the group ID
15958             * @param categoryId the category ID
15959             * @param threadId the thread ID
15960             * @throws SystemException if a system exception occurred
15961             */
15962            public void removeByG_C_T(long groupId, long categoryId, long threadId)
15963                    throws SystemException {
15964                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
15965                            remove(mbMessage);
15966                    }
15967            }
15968    
15969            /**
15970             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
15971             *
15972             * @param groupId the group ID
15973             * @param categoryId the category ID
15974             * @param status the status
15975             * @throws SystemException if a system exception occurred
15976             */
15977            public void removeByG_C_S(long groupId, long categoryId, int status)
15978                    throws SystemException {
15979                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
15980                            remove(mbMessage);
15981                    }
15982            }
15983    
15984            /**
15985             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
15986             *
15987             * @param userId the user ID
15988             * @param classNameId the class name ID
15989             * @param classPK the class p k
15990             * @throws SystemException if a system exception occurred
15991             */
15992            public void removeByU_C_C(long userId, long classNameId, long classPK)
15993                    throws SystemException {
15994                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK)) {
15995                            remove(mbMessage);
15996                    }
15997            }
15998    
15999            /**
16000             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
16001             *
16002             * @param userId the user ID
16003             * @param classNameId the class name ID
16004             * @param status the status
16005             * @throws SystemException if a system exception occurred
16006             */
16007            public void removeByU_C_S(long userId, long classNameId, int status)
16008                    throws SystemException {
16009                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status)) {
16010                            remove(mbMessage);
16011                    }
16012            }
16013    
16014            /**
16015             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16016             *
16017             * @param classNameId the class name ID
16018             * @param classPK the class p k
16019             * @param status the status
16020             * @throws SystemException if a system exception occurred
16021             */
16022            public void removeByC_C_S(long classNameId, long classPK, int status)
16023                    throws SystemException {
16024                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
16025                            remove(mbMessage);
16026                    }
16027            }
16028    
16029            /**
16030             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16031             *
16032             * @param groupId the group ID
16033             * @param categoryId the category ID
16034             * @param threadId the thread ID
16035             * @param answer the answer
16036             * @throws SystemException if a system exception occurred
16037             */
16038            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16039                    boolean answer) throws SystemException {
16040                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16041                                    answer)) {
16042                            remove(mbMessage);
16043                    }
16044            }
16045    
16046            /**
16047             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
16048             *
16049             * @param groupId the group ID
16050             * @param categoryId the category ID
16051             * @param threadId the thread ID
16052             * @param status the status
16053             * @throws SystemException if a system exception occurred
16054             */
16055            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
16056                    int status) throws SystemException {
16057                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
16058                                    status)) {
16059                            remove(mbMessage);
16060                    }
16061            }
16062    
16063            /**
16064             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16065             *
16066             * @param userId the user ID
16067             * @param classNameId the class name ID
16068             * @param classPK the class p k
16069             * @param status the status
16070             * @throws SystemException if a system exception occurred
16071             */
16072            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
16073                    int status) throws SystemException {
16074                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
16075                                    status)) {
16076                            remove(mbMessage);
16077                    }
16078            }
16079    
16080            /**
16081             * Removes all the message-boards messages from the database.
16082             *
16083             * @throws SystemException if a system exception occurred
16084             */
16085            public void removeAll() throws SystemException {
16086                    for (MBMessage mbMessage : findAll()) {
16087                            remove(mbMessage);
16088                    }
16089            }
16090    
16091            /**
16092             * Returns the number of message-boards messages where uuid = &#63;.
16093             *
16094             * @param uuid the uuid
16095             * @return the number of matching message-boards messages
16096             * @throws SystemException if a system exception occurred
16097             */
16098            public int countByUuid(String uuid) throws SystemException {
16099                    Object[] finderArgs = new Object[] { uuid };
16100    
16101                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
16102                                    finderArgs, this);
16103    
16104                    if (count == null) {
16105                            StringBundler query = new StringBundler(2);
16106    
16107                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16108    
16109                            if (uuid == null) {
16110                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
16111                            }
16112                            else {
16113                                    if (uuid.equals(StringPool.BLANK)) {
16114                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
16115                                    }
16116                                    else {
16117                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
16118                                    }
16119                            }
16120    
16121                            String sql = query.toString();
16122    
16123                            Session session = null;
16124    
16125                            try {
16126                                    session = openSession();
16127    
16128                                    Query q = session.createQuery(sql);
16129    
16130                                    QueryPos qPos = QueryPos.getInstance(q);
16131    
16132                                    if (uuid != null) {
16133                                            qPos.add(uuid);
16134                                    }
16135    
16136                                    count = (Long)q.uniqueResult();
16137                            }
16138                            catch (Exception e) {
16139                                    throw processException(e);
16140                            }
16141                            finally {
16142                                    if (count == null) {
16143                                            count = Long.valueOf(0);
16144                                    }
16145    
16146                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
16147                                            finderArgs, count);
16148    
16149                                    closeSession(session);
16150                            }
16151                    }
16152    
16153                    return count.intValue();
16154            }
16155    
16156            /**
16157             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
16158             *
16159             * @param uuid the uuid
16160             * @param groupId the group ID
16161             * @return the number of matching message-boards messages
16162             * @throws SystemException if a system exception occurred
16163             */
16164            public int countByUUID_G(String uuid, long groupId)
16165                    throws SystemException {
16166                    Object[] finderArgs = new Object[] { uuid, groupId };
16167    
16168                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
16169                                    finderArgs, this);
16170    
16171                    if (count == null) {
16172                            StringBundler query = new StringBundler(3);
16173    
16174                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16175    
16176                            if (uuid == null) {
16177                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
16178                            }
16179                            else {
16180                                    if (uuid.equals(StringPool.BLANK)) {
16181                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
16182                                    }
16183                                    else {
16184                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
16185                                    }
16186                            }
16187    
16188                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
16189    
16190                            String sql = query.toString();
16191    
16192                            Session session = null;
16193    
16194                            try {
16195                                    session = openSession();
16196    
16197                                    Query q = session.createQuery(sql);
16198    
16199                                    QueryPos qPos = QueryPos.getInstance(q);
16200    
16201                                    if (uuid != null) {
16202                                            qPos.add(uuid);
16203                                    }
16204    
16205                                    qPos.add(groupId);
16206    
16207                                    count = (Long)q.uniqueResult();
16208                            }
16209                            catch (Exception e) {
16210                                    throw processException(e);
16211                            }
16212                            finally {
16213                                    if (count == null) {
16214                                            count = Long.valueOf(0);
16215                                    }
16216    
16217                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
16218                                            finderArgs, count);
16219    
16220                                    closeSession(session);
16221                            }
16222                    }
16223    
16224                    return count.intValue();
16225            }
16226    
16227            /**
16228             * Returns the number of message-boards messages where groupId = &#63;.
16229             *
16230             * @param groupId the group ID
16231             * @return the number of matching message-boards messages
16232             * @throws SystemException if a system exception occurred
16233             */
16234            public int countByGroupId(long groupId) throws SystemException {
16235                    Object[] finderArgs = new Object[] { groupId };
16236    
16237                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
16238                                    finderArgs, this);
16239    
16240                    if (count == null) {
16241                            StringBundler query = new StringBundler(2);
16242    
16243                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16244    
16245                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
16246    
16247                            String sql = query.toString();
16248    
16249                            Session session = null;
16250    
16251                            try {
16252                                    session = openSession();
16253    
16254                                    Query q = session.createQuery(sql);
16255    
16256                                    QueryPos qPos = QueryPos.getInstance(q);
16257    
16258                                    qPos.add(groupId);
16259    
16260                                    count = (Long)q.uniqueResult();
16261                            }
16262                            catch (Exception e) {
16263                                    throw processException(e);
16264                            }
16265                            finally {
16266                                    if (count == null) {
16267                                            count = Long.valueOf(0);
16268                                    }
16269    
16270                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
16271                                            finderArgs, count);
16272    
16273                                    closeSession(session);
16274                            }
16275                    }
16276    
16277                    return count.intValue();
16278            }
16279    
16280            /**
16281             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
16282             *
16283             * @param groupId the group ID
16284             * @return the number of matching message-boards messages that the user has permission to view
16285             * @throws SystemException if a system exception occurred
16286             */
16287            public int filterCountByGroupId(long groupId) throws SystemException {
16288                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16289                            return countByGroupId(groupId);
16290                    }
16291    
16292                    StringBundler query = new StringBundler(2);
16293    
16294                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16295    
16296                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
16297    
16298                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16299                                    MBMessage.class.getName(),
16300                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16301    
16302                    Session session = null;
16303    
16304                    try {
16305                            session = openSession();
16306    
16307                            SQLQuery q = session.createSQLQuery(sql);
16308    
16309                            q.addScalar(COUNT_COLUMN_NAME,
16310                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16311    
16312                            QueryPos qPos = QueryPos.getInstance(q);
16313    
16314                            qPos.add(groupId);
16315    
16316                            Long count = (Long)q.uniqueResult();
16317    
16318                            return count.intValue();
16319                    }
16320                    catch (Exception e) {
16321                            throw processException(e);
16322                    }
16323                    finally {
16324                            closeSession(session);
16325                    }
16326            }
16327    
16328            /**
16329             * Returns the number of message-boards messages where companyId = &#63;.
16330             *
16331             * @param companyId the company ID
16332             * @return the number of matching message-boards messages
16333             * @throws SystemException if a system exception occurred
16334             */
16335            public int countByCompanyId(long companyId) throws SystemException {
16336                    Object[] finderArgs = new Object[] { companyId };
16337    
16338                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
16339                                    finderArgs, this);
16340    
16341                    if (count == null) {
16342                            StringBundler query = new StringBundler(2);
16343    
16344                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16345    
16346                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
16347    
16348                            String sql = query.toString();
16349    
16350                            Session session = null;
16351    
16352                            try {
16353                                    session = openSession();
16354    
16355                                    Query q = session.createQuery(sql);
16356    
16357                                    QueryPos qPos = QueryPos.getInstance(q);
16358    
16359                                    qPos.add(companyId);
16360    
16361                                    count = (Long)q.uniqueResult();
16362                            }
16363                            catch (Exception e) {
16364                                    throw processException(e);
16365                            }
16366                            finally {
16367                                    if (count == null) {
16368                                            count = Long.valueOf(0);
16369                                    }
16370    
16371                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
16372                                            finderArgs, count);
16373    
16374                                    closeSession(session);
16375                            }
16376                    }
16377    
16378                    return count.intValue();
16379            }
16380    
16381            /**
16382             * Returns the number of message-boards messages where threadId = &#63;.
16383             *
16384             * @param threadId the thread ID
16385             * @return the number of matching message-boards messages
16386             * @throws SystemException if a system exception occurred
16387             */
16388            public int countByThreadId(long threadId) throws SystemException {
16389                    Object[] finderArgs = new Object[] { threadId };
16390    
16391                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
16392                                    finderArgs, this);
16393    
16394                    if (count == null) {
16395                            StringBundler query = new StringBundler(2);
16396    
16397                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16398    
16399                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
16400    
16401                            String sql = query.toString();
16402    
16403                            Session session = null;
16404    
16405                            try {
16406                                    session = openSession();
16407    
16408                                    Query q = session.createQuery(sql);
16409    
16410                                    QueryPos qPos = QueryPos.getInstance(q);
16411    
16412                                    qPos.add(threadId);
16413    
16414                                    count = (Long)q.uniqueResult();
16415                            }
16416                            catch (Exception e) {
16417                                    throw processException(e);
16418                            }
16419                            finally {
16420                                    if (count == null) {
16421                                            count = Long.valueOf(0);
16422                                    }
16423    
16424                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
16425                                            finderArgs, count);
16426    
16427                                    closeSession(session);
16428                            }
16429                    }
16430    
16431                    return count.intValue();
16432            }
16433    
16434            /**
16435             * Returns the number of message-boards messages where threadId = &#63;.
16436             *
16437             * @param threadId the thread ID
16438             * @return the number of matching message-boards messages
16439             * @throws SystemException if a system exception occurred
16440             */
16441            public int countByThreadReplies(long threadId) throws SystemException {
16442                    Object[] finderArgs = new Object[] { threadId };
16443    
16444                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
16445                                    finderArgs, this);
16446    
16447                    if (count == null) {
16448                            StringBundler query = new StringBundler(2);
16449    
16450                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16451    
16452                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
16453    
16454                            String sql = query.toString();
16455    
16456                            Session session = null;
16457    
16458                            try {
16459                                    session = openSession();
16460    
16461                                    Query q = session.createQuery(sql);
16462    
16463                                    QueryPos qPos = QueryPos.getInstance(q);
16464    
16465                                    qPos.add(threadId);
16466    
16467                                    count = (Long)q.uniqueResult();
16468                            }
16469                            catch (Exception e) {
16470                                    throw processException(e);
16471                            }
16472                            finally {
16473                                    if (count == null) {
16474                                            count = Long.valueOf(0);
16475                                    }
16476    
16477                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
16478                                            finderArgs, count);
16479    
16480                                    closeSession(session);
16481                            }
16482                    }
16483    
16484                    return count.intValue();
16485            }
16486    
16487            /**
16488             * Returns the number of message-boards messages where userId = &#63;.
16489             *
16490             * @param userId the user ID
16491             * @return the number of matching message-boards messages
16492             * @throws SystemException if a system exception occurred
16493             */
16494            public int countByUserId(long userId) throws SystemException {
16495                    Object[] finderArgs = new Object[] { userId };
16496    
16497                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
16498                                    finderArgs, this);
16499    
16500                    if (count == null) {
16501                            StringBundler query = new StringBundler(2);
16502    
16503                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16504    
16505                            query.append(_FINDER_COLUMN_USERID_USERID_2);
16506    
16507                            String sql = query.toString();
16508    
16509                            Session session = null;
16510    
16511                            try {
16512                                    session = openSession();
16513    
16514                                    Query q = session.createQuery(sql);
16515    
16516                                    QueryPos qPos = QueryPos.getInstance(q);
16517    
16518                                    qPos.add(userId);
16519    
16520                                    count = (Long)q.uniqueResult();
16521                            }
16522                            catch (Exception e) {
16523                                    throw processException(e);
16524                            }
16525                            finally {
16526                                    if (count == null) {
16527                                            count = Long.valueOf(0);
16528                                    }
16529    
16530                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
16531                                            finderArgs, count);
16532    
16533                                    closeSession(session);
16534                            }
16535                    }
16536    
16537                    return count.intValue();
16538            }
16539    
16540            /**
16541             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
16542             *
16543             * @param groupId the group ID
16544             * @param userId the user ID
16545             * @return the number of matching message-boards messages
16546             * @throws SystemException if a system exception occurred
16547             */
16548            public int countByG_U(long groupId, long userId) throws SystemException {
16549                    Object[] finderArgs = new Object[] { groupId, userId };
16550    
16551                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
16552                                    finderArgs, this);
16553    
16554                    if (count == null) {
16555                            StringBundler query = new StringBundler(3);
16556    
16557                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16558    
16559                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
16560    
16561                            query.append(_FINDER_COLUMN_G_U_USERID_2);
16562    
16563                            String sql = query.toString();
16564    
16565                            Session session = null;
16566    
16567                            try {
16568                                    session = openSession();
16569    
16570                                    Query q = session.createQuery(sql);
16571    
16572                                    QueryPos qPos = QueryPos.getInstance(q);
16573    
16574                                    qPos.add(groupId);
16575    
16576                                    qPos.add(userId);
16577    
16578                                    count = (Long)q.uniqueResult();
16579                            }
16580                            catch (Exception e) {
16581                                    throw processException(e);
16582                            }
16583                            finally {
16584                                    if (count == null) {
16585                                            count = Long.valueOf(0);
16586                                    }
16587    
16588                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
16589                                            count);
16590    
16591                                    closeSession(session);
16592                            }
16593                    }
16594    
16595                    return count.intValue();
16596            }
16597    
16598            /**
16599             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
16600             *
16601             * @param groupId the group ID
16602             * @param userId the user ID
16603             * @return the number of matching message-boards messages that the user has permission to view
16604             * @throws SystemException if a system exception occurred
16605             */
16606            public int filterCountByG_U(long groupId, long userId)
16607                    throws SystemException {
16608                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16609                            return countByG_U(groupId, userId);
16610                    }
16611    
16612                    StringBundler query = new StringBundler(3);
16613    
16614                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16615    
16616                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
16617    
16618                    query.append(_FINDER_COLUMN_G_U_USERID_2);
16619    
16620                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16621                                    MBMessage.class.getName(),
16622                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16623    
16624                    Session session = null;
16625    
16626                    try {
16627                            session = openSession();
16628    
16629                            SQLQuery q = session.createSQLQuery(sql);
16630    
16631                            q.addScalar(COUNT_COLUMN_NAME,
16632                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16633    
16634                            QueryPos qPos = QueryPos.getInstance(q);
16635    
16636                            qPos.add(groupId);
16637    
16638                            qPos.add(userId);
16639    
16640                            Long count = (Long)q.uniqueResult();
16641    
16642                            return count.intValue();
16643                    }
16644                    catch (Exception e) {
16645                            throw processException(e);
16646                    }
16647                    finally {
16648                            closeSession(session);
16649                    }
16650            }
16651    
16652            /**
16653             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
16654             *
16655             * @param groupId the group ID
16656             * @param categoryId the category ID
16657             * @return the number of matching message-boards messages
16658             * @throws SystemException if a system exception occurred
16659             */
16660            public int countByG_C(long groupId, long categoryId)
16661                    throws SystemException {
16662                    Object[] finderArgs = new Object[] { groupId, categoryId };
16663    
16664                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
16665                                    finderArgs, this);
16666    
16667                    if (count == null) {
16668                            StringBundler query = new StringBundler(3);
16669    
16670                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16671    
16672                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
16673    
16674                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
16675    
16676                            String sql = query.toString();
16677    
16678                            Session session = null;
16679    
16680                            try {
16681                                    session = openSession();
16682    
16683                                    Query q = session.createQuery(sql);
16684    
16685                                    QueryPos qPos = QueryPos.getInstance(q);
16686    
16687                                    qPos.add(groupId);
16688    
16689                                    qPos.add(categoryId);
16690    
16691                                    count = (Long)q.uniqueResult();
16692                            }
16693                            catch (Exception e) {
16694                                    throw processException(e);
16695                            }
16696                            finally {
16697                                    if (count == null) {
16698                                            count = Long.valueOf(0);
16699                                    }
16700    
16701                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
16702                                            count);
16703    
16704                                    closeSession(session);
16705                            }
16706                    }
16707    
16708                    return count.intValue();
16709            }
16710    
16711            /**
16712             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
16713             *
16714             * @param groupId the group ID
16715             * @param categoryId the category ID
16716             * @return the number of matching message-boards messages that the user has permission to view
16717             * @throws SystemException if a system exception occurred
16718             */
16719            public int filterCountByG_C(long groupId, long categoryId)
16720                    throws SystemException {
16721                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16722                            return countByG_C(groupId, categoryId);
16723                    }
16724    
16725                    StringBundler query = new StringBundler(3);
16726    
16727                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16728    
16729                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
16730    
16731                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
16732    
16733                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16734                                    MBMessage.class.getName(),
16735                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16736    
16737                    Session session = null;
16738    
16739                    try {
16740                            session = openSession();
16741    
16742                            SQLQuery q = session.createSQLQuery(sql);
16743    
16744                            q.addScalar(COUNT_COLUMN_NAME,
16745                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16746    
16747                            QueryPos qPos = QueryPos.getInstance(q);
16748    
16749                            qPos.add(groupId);
16750    
16751                            qPos.add(categoryId);
16752    
16753                            Long count = (Long)q.uniqueResult();
16754    
16755                            return count.intValue();
16756                    }
16757                    catch (Exception e) {
16758                            throw processException(e);
16759                    }
16760                    finally {
16761                            closeSession(session);
16762                    }
16763            }
16764    
16765            /**
16766             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
16767             *
16768             * @param groupId the group ID
16769             * @param status the status
16770             * @return the number of matching message-boards messages
16771             * @throws SystemException if a system exception occurred
16772             */
16773            public int countByG_S(long groupId, int status) throws SystemException {
16774                    Object[] finderArgs = new Object[] { groupId, status };
16775    
16776                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
16777                                    finderArgs, this);
16778    
16779                    if (count == null) {
16780                            StringBundler query = new StringBundler(3);
16781    
16782                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16783    
16784                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
16785    
16786                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
16787    
16788                            String sql = query.toString();
16789    
16790                            Session session = null;
16791    
16792                            try {
16793                                    session = openSession();
16794    
16795                                    Query q = session.createQuery(sql);
16796    
16797                                    QueryPos qPos = QueryPos.getInstance(q);
16798    
16799                                    qPos.add(groupId);
16800    
16801                                    qPos.add(status);
16802    
16803                                    count = (Long)q.uniqueResult();
16804                            }
16805                            catch (Exception e) {
16806                                    throw processException(e);
16807                            }
16808                            finally {
16809                                    if (count == null) {
16810                                            count = Long.valueOf(0);
16811                                    }
16812    
16813                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
16814                                            count);
16815    
16816                                    closeSession(session);
16817                            }
16818                    }
16819    
16820                    return count.intValue();
16821            }
16822    
16823            /**
16824             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
16825             *
16826             * @param groupId the group ID
16827             * @param status the status
16828             * @return the number of matching message-boards messages that the user has permission to view
16829             * @throws SystemException if a system exception occurred
16830             */
16831            public int filterCountByG_S(long groupId, int status)
16832                    throws SystemException {
16833                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16834                            return countByG_S(groupId, status);
16835                    }
16836    
16837                    StringBundler query = new StringBundler(3);
16838    
16839                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16840    
16841                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
16842    
16843                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
16844    
16845                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16846                                    MBMessage.class.getName(),
16847                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16848    
16849                    Session session = null;
16850    
16851                    try {
16852                            session = openSession();
16853    
16854                            SQLQuery q = session.createSQLQuery(sql);
16855    
16856                            q.addScalar(COUNT_COLUMN_NAME,
16857                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16858    
16859                            QueryPos qPos = QueryPos.getInstance(q);
16860    
16861                            qPos.add(groupId);
16862    
16863                            qPos.add(status);
16864    
16865                            Long count = (Long)q.uniqueResult();
16866    
16867                            return count.intValue();
16868                    }
16869                    catch (Exception e) {
16870                            throw processException(e);
16871                    }
16872                    finally {
16873                            closeSession(session);
16874                    }
16875            }
16876    
16877            /**
16878             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
16879             *
16880             * @param companyId the company ID
16881             * @param status the status
16882             * @return the number of matching message-boards messages
16883             * @throws SystemException if a system exception occurred
16884             */
16885            public int countByC_S(long companyId, int status) throws SystemException {
16886                    Object[] finderArgs = new Object[] { companyId, status };
16887    
16888                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
16889                                    finderArgs, this);
16890    
16891                    if (count == null) {
16892                            StringBundler query = new StringBundler(3);
16893    
16894                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16895    
16896                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
16897    
16898                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
16899    
16900                            String sql = query.toString();
16901    
16902                            Session session = null;
16903    
16904                            try {
16905                                    session = openSession();
16906    
16907                                    Query q = session.createQuery(sql);
16908    
16909                                    QueryPos qPos = QueryPos.getInstance(q);
16910    
16911                                    qPos.add(companyId);
16912    
16913                                    qPos.add(status);
16914    
16915                                    count = (Long)q.uniqueResult();
16916                            }
16917                            catch (Exception e) {
16918                                    throw processException(e);
16919                            }
16920                            finally {
16921                                    if (count == null) {
16922                                            count = Long.valueOf(0);
16923                                    }
16924    
16925                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
16926                                            count);
16927    
16928                                    closeSession(session);
16929                            }
16930                    }
16931    
16932                    return count.intValue();
16933            }
16934    
16935            /**
16936             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
16937             *
16938             * @param userId the user ID
16939             * @param classNameId the class name ID
16940             * @return the number of matching message-boards messages
16941             * @throws SystemException if a system exception occurred
16942             */
16943            public int countByU_C(long userId, long classNameId)
16944                    throws SystemException {
16945                    Object[] finderArgs = new Object[] { userId, classNameId };
16946    
16947                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
16948                                    finderArgs, this);
16949    
16950                    if (count == null) {
16951                            StringBundler query = new StringBundler(3);
16952    
16953                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16954    
16955                            query.append(_FINDER_COLUMN_U_C_USERID_2);
16956    
16957                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
16958    
16959                            String sql = query.toString();
16960    
16961                            Session session = null;
16962    
16963                            try {
16964                                    session = openSession();
16965    
16966                                    Query q = session.createQuery(sql);
16967    
16968                                    QueryPos qPos = QueryPos.getInstance(q);
16969    
16970                                    qPos.add(userId);
16971    
16972                                    qPos.add(classNameId);
16973    
16974                                    count = (Long)q.uniqueResult();
16975                            }
16976                            catch (Exception e) {
16977                                    throw processException(e);
16978                            }
16979                            finally {
16980                                    if (count == null) {
16981                                            count = Long.valueOf(0);
16982                                    }
16983    
16984                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
16985                                            count);
16986    
16987                                    closeSession(session);
16988                            }
16989                    }
16990    
16991                    return count.intValue();
16992            }
16993    
16994            /**
16995             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
16996             *
16997             * @param userId the user ID
16998             * @param classNameIds the class name IDs
16999             * @return the number of matching message-boards messages
17000             * @throws SystemException if a system exception occurred
17001             */
17002            public int countByU_C(long userId, long[] classNameIds)
17003                    throws SystemException {
17004                    Object[] finderArgs = new Object[] {
17005                                    userId, StringUtil.merge(classNameIds)
17006                            };
17007    
17008                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
17009                                    finderArgs, this);
17010    
17011                    if (count == null) {
17012                            StringBundler query = new StringBundler();
17013    
17014                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17015    
17016                            boolean conjunctionable = false;
17017    
17018                            if (conjunctionable) {
17019                                    query.append(WHERE_AND);
17020                            }
17021    
17022                            query.append(_FINDER_COLUMN_U_C_USERID_5);
17023    
17024                            conjunctionable = true;
17025    
17026                            if ((classNameIds == null) || (classNameIds.length > 0)) {
17027                                    if (conjunctionable) {
17028                                            query.append(WHERE_AND);
17029                                    }
17030    
17031                                    query.append(StringPool.OPEN_PARENTHESIS);
17032    
17033                                    for (int i = 0; i < classNameIds.length; i++) {
17034                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
17035    
17036                                            if ((i + 1) < classNameIds.length) {
17037                                                    query.append(WHERE_OR);
17038                                            }
17039                                    }
17040    
17041                                    query.append(StringPool.CLOSE_PARENTHESIS);
17042    
17043                                    conjunctionable = true;
17044                            }
17045    
17046                            String sql = query.toString();
17047    
17048                            Session session = null;
17049    
17050                            try {
17051                                    session = openSession();
17052    
17053                                    Query q = session.createQuery(sql);
17054    
17055                                    QueryPos qPos = QueryPos.getInstance(q);
17056    
17057                                    qPos.add(userId);
17058    
17059                                    if (classNameIds != null) {
17060                                            qPos.add(classNameIds);
17061                                    }
17062    
17063                                    count = (Long)q.uniqueResult();
17064                            }
17065                            catch (Exception e) {
17066                                    throw processException(e);
17067                            }
17068                            finally {
17069                                    if (count == null) {
17070                                            count = Long.valueOf(0);
17071                                    }
17072    
17073                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
17074                                            finderArgs, count);
17075    
17076                                    closeSession(session);
17077                            }
17078                    }
17079    
17080                    return count.intValue();
17081            }
17082    
17083            /**
17084             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
17085             *
17086             * @param classNameId the class name ID
17087             * @param classPK the class p k
17088             * @return the number of matching message-boards messages
17089             * @throws SystemException if a system exception occurred
17090             */
17091            public int countByC_C(long classNameId, long classPK)
17092                    throws SystemException {
17093                    Object[] finderArgs = new Object[] { classNameId, classPK };
17094    
17095                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
17096                                    finderArgs, this);
17097    
17098                    if (count == null) {
17099                            StringBundler query = new StringBundler(3);
17100    
17101                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17102    
17103                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
17104    
17105                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
17106    
17107                            String sql = query.toString();
17108    
17109                            Session session = null;
17110    
17111                            try {
17112                                    session = openSession();
17113    
17114                                    Query q = session.createQuery(sql);
17115    
17116                                    QueryPos qPos = QueryPos.getInstance(q);
17117    
17118                                    qPos.add(classNameId);
17119    
17120                                    qPos.add(classPK);
17121    
17122                                    count = (Long)q.uniqueResult();
17123                            }
17124                            catch (Exception e) {
17125                                    throw processException(e);
17126                            }
17127                            finally {
17128                                    if (count == null) {
17129                                            count = Long.valueOf(0);
17130                                    }
17131    
17132                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
17133                                            count);
17134    
17135                                    closeSession(session);
17136                            }
17137                    }
17138    
17139                    return count.intValue();
17140            }
17141    
17142            /**
17143             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
17144             *
17145             * @param threadId the thread ID
17146             * @param parentMessageId the parent message ID
17147             * @return the number of matching message-boards messages
17148             * @throws SystemException if a system exception occurred
17149             */
17150            public int countByT_P(long threadId, long parentMessageId)
17151                    throws SystemException {
17152                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
17153    
17154                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
17155                                    finderArgs, this);
17156    
17157                    if (count == null) {
17158                            StringBundler query = new StringBundler(3);
17159    
17160                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17161    
17162                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
17163    
17164                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
17165    
17166                            String sql = query.toString();
17167    
17168                            Session session = null;
17169    
17170                            try {
17171                                    session = openSession();
17172    
17173                                    Query q = session.createQuery(sql);
17174    
17175                                    QueryPos qPos = QueryPos.getInstance(q);
17176    
17177                                    qPos.add(threadId);
17178    
17179                                    qPos.add(parentMessageId);
17180    
17181                                    count = (Long)q.uniqueResult();
17182                            }
17183                            catch (Exception e) {
17184                                    throw processException(e);
17185                            }
17186                            finally {
17187                                    if (count == null) {
17188                                            count = Long.valueOf(0);
17189                                    }
17190    
17191                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
17192                                            count);
17193    
17194                                    closeSession(session);
17195                            }
17196                    }
17197    
17198                    return count.intValue();
17199            }
17200    
17201            /**
17202             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
17203             *
17204             * @param threadId the thread ID
17205             * @param answer the answer
17206             * @return the number of matching message-boards messages
17207             * @throws SystemException if a system exception occurred
17208             */
17209            public int countByT_A(long threadId, boolean answer)
17210                    throws SystemException {
17211                    Object[] finderArgs = new Object[] { threadId, answer };
17212    
17213                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_A,
17214                                    finderArgs, this);
17215    
17216                    if (count == null) {
17217                            StringBundler query = new StringBundler(3);
17218    
17219                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17220    
17221                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
17222    
17223                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
17224    
17225                            String sql = query.toString();
17226    
17227                            Session session = null;
17228    
17229                            try {
17230                                    session = openSession();
17231    
17232                                    Query q = session.createQuery(sql);
17233    
17234                                    QueryPos qPos = QueryPos.getInstance(q);
17235    
17236                                    qPos.add(threadId);
17237    
17238                                    qPos.add(answer);
17239    
17240                                    count = (Long)q.uniqueResult();
17241                            }
17242                            catch (Exception e) {
17243                                    throw processException(e);
17244                            }
17245                            finally {
17246                                    if (count == null) {
17247                                            count = Long.valueOf(0);
17248                                    }
17249    
17250                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_A, finderArgs,
17251                                            count);
17252    
17253                                    closeSession(session);
17254                            }
17255                    }
17256    
17257                    return count.intValue();
17258            }
17259    
17260            /**
17261             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
17262             *
17263             * @param threadId the thread ID
17264             * @param status the status
17265             * @return the number of matching message-boards messages
17266             * @throws SystemException if a system exception occurred
17267             */
17268            public int countByT_S(long threadId, int status) throws SystemException {
17269                    Object[] finderArgs = new Object[] { threadId, status };
17270    
17271                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
17272                                    finderArgs, this);
17273    
17274                    if (count == null) {
17275                            StringBundler query = new StringBundler(3);
17276    
17277                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17278    
17279                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
17280    
17281                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
17282    
17283                            String sql = query.toString();
17284    
17285                            Session session = null;
17286    
17287                            try {
17288                                    session = openSession();
17289    
17290                                    Query q = session.createQuery(sql);
17291    
17292                                    QueryPos qPos = QueryPos.getInstance(q);
17293    
17294                                    qPos.add(threadId);
17295    
17296                                    qPos.add(status);
17297    
17298                                    count = (Long)q.uniqueResult();
17299                            }
17300                            catch (Exception e) {
17301                                    throw processException(e);
17302                            }
17303                            finally {
17304                                    if (count == null) {
17305                                            count = Long.valueOf(0);
17306                                    }
17307    
17308                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
17309                                            count);
17310    
17311                                    closeSession(session);
17312                            }
17313                    }
17314    
17315                    return count.intValue();
17316            }
17317    
17318            /**
17319             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
17320             *
17321             * @param threadId the thread ID
17322             * @param status the status
17323             * @return the number of matching message-boards messages
17324             * @throws SystemException if a system exception occurred
17325             */
17326            public int countByTR_S(long threadId, int status) throws SystemException {
17327                    Object[] finderArgs = new Object[] { threadId, status };
17328    
17329                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
17330                                    finderArgs, this);
17331    
17332                    if (count == null) {
17333                            StringBundler query = new StringBundler(3);
17334    
17335                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17336    
17337                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
17338    
17339                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
17340    
17341                            String sql = query.toString();
17342    
17343                            Session session = null;
17344    
17345                            try {
17346                                    session = openSession();
17347    
17348                                    Query q = session.createQuery(sql);
17349    
17350                                    QueryPos qPos = QueryPos.getInstance(q);
17351    
17352                                    qPos.add(threadId);
17353    
17354                                    qPos.add(status);
17355    
17356                                    count = (Long)q.uniqueResult();
17357                            }
17358                            catch (Exception e) {
17359                                    throw processException(e);
17360                            }
17361                            finally {
17362                                    if (count == null) {
17363                                            count = Long.valueOf(0);
17364                                    }
17365    
17366                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
17367                                            finderArgs, count);
17368    
17369                                    closeSession(session);
17370                            }
17371                    }
17372    
17373                    return count.intValue();
17374            }
17375    
17376            /**
17377             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
17378             *
17379             * @param groupId the group ID
17380             * @param userId the user ID
17381             * @param status the status
17382             * @return the number of matching message-boards messages
17383             * @throws SystemException if a system exception occurred
17384             */
17385            public int countByG_U_S(long groupId, long userId, int status)
17386                    throws SystemException {
17387                    Object[] finderArgs = new Object[] { groupId, userId, status };
17388    
17389                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
17390                                    finderArgs, this);
17391    
17392                    if (count == null) {
17393                            StringBundler query = new StringBundler(4);
17394    
17395                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17396    
17397                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
17398    
17399                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
17400    
17401                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
17402    
17403                            String sql = query.toString();
17404    
17405                            Session session = null;
17406    
17407                            try {
17408                                    session = openSession();
17409    
17410                                    Query q = session.createQuery(sql);
17411    
17412                                    QueryPos qPos = QueryPos.getInstance(q);
17413    
17414                                    qPos.add(groupId);
17415    
17416                                    qPos.add(userId);
17417    
17418                                    qPos.add(status);
17419    
17420                                    count = (Long)q.uniqueResult();
17421                            }
17422                            catch (Exception e) {
17423                                    throw processException(e);
17424                            }
17425                            finally {
17426                                    if (count == null) {
17427                                            count = Long.valueOf(0);
17428                                    }
17429    
17430                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
17431                                            finderArgs, count);
17432    
17433                                    closeSession(session);
17434                            }
17435                    }
17436    
17437                    return count.intValue();
17438            }
17439    
17440            /**
17441             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
17442             *
17443             * @param groupId the group ID
17444             * @param userId the user ID
17445             * @param status the status
17446             * @return the number of matching message-boards messages that the user has permission to view
17447             * @throws SystemException if a system exception occurred
17448             */
17449            public int filterCountByG_U_S(long groupId, long userId, int status)
17450                    throws SystemException {
17451                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17452                            return countByG_U_S(groupId, userId, status);
17453                    }
17454    
17455                    StringBundler query = new StringBundler(4);
17456    
17457                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17458    
17459                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
17460    
17461                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
17462    
17463                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
17464    
17465                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17466                                    MBMessage.class.getName(),
17467                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17468    
17469                    Session session = null;
17470    
17471                    try {
17472                            session = openSession();
17473    
17474                            SQLQuery q = session.createSQLQuery(sql);
17475    
17476                            q.addScalar(COUNT_COLUMN_NAME,
17477                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17478    
17479                            QueryPos qPos = QueryPos.getInstance(q);
17480    
17481                            qPos.add(groupId);
17482    
17483                            qPos.add(userId);
17484    
17485                            qPos.add(status);
17486    
17487                            Long count = (Long)q.uniqueResult();
17488    
17489                            return count.intValue();
17490                    }
17491                    catch (Exception e) {
17492                            throw processException(e);
17493                    }
17494                    finally {
17495                            closeSession(session);
17496                    }
17497            }
17498    
17499            /**
17500             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
17501             *
17502             * @param groupId the group ID
17503             * @param categoryId the category ID
17504             * @param threadId the thread ID
17505             * @return the number of matching message-boards messages
17506             * @throws SystemException if a system exception occurred
17507             */
17508            public int countByG_C_T(long groupId, long categoryId, long threadId)
17509                    throws SystemException {
17510                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
17511    
17512                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
17513                                    finderArgs, this);
17514    
17515                    if (count == null) {
17516                            StringBundler query = new StringBundler(4);
17517    
17518                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17519    
17520                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
17521    
17522                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
17523    
17524                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
17525    
17526                            String sql = query.toString();
17527    
17528                            Session session = null;
17529    
17530                            try {
17531                                    session = openSession();
17532    
17533                                    Query q = session.createQuery(sql);
17534    
17535                                    QueryPos qPos = QueryPos.getInstance(q);
17536    
17537                                    qPos.add(groupId);
17538    
17539                                    qPos.add(categoryId);
17540    
17541                                    qPos.add(threadId);
17542    
17543                                    count = (Long)q.uniqueResult();
17544                            }
17545                            catch (Exception e) {
17546                                    throw processException(e);
17547                            }
17548                            finally {
17549                                    if (count == null) {
17550                                            count = Long.valueOf(0);
17551                                    }
17552    
17553                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
17554                                            finderArgs, count);
17555    
17556                                    closeSession(session);
17557                            }
17558                    }
17559    
17560                    return count.intValue();
17561            }
17562    
17563            /**
17564             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
17565             *
17566             * @param groupId the group ID
17567             * @param categoryId the category ID
17568             * @param threadId the thread ID
17569             * @return the number of matching message-boards messages that the user has permission to view
17570             * @throws SystemException if a system exception occurred
17571             */
17572            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
17573                    throws SystemException {
17574                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17575                            return countByG_C_T(groupId, categoryId, threadId);
17576                    }
17577    
17578                    StringBundler query = new StringBundler(4);
17579    
17580                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17581    
17582                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
17583    
17584                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
17585    
17586                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
17587    
17588                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17589                                    MBMessage.class.getName(),
17590                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17591    
17592                    Session session = null;
17593    
17594                    try {
17595                            session = openSession();
17596    
17597                            SQLQuery q = session.createSQLQuery(sql);
17598    
17599                            q.addScalar(COUNT_COLUMN_NAME,
17600                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17601    
17602                            QueryPos qPos = QueryPos.getInstance(q);
17603    
17604                            qPos.add(groupId);
17605    
17606                            qPos.add(categoryId);
17607    
17608                            qPos.add(threadId);
17609    
17610                            Long count = (Long)q.uniqueResult();
17611    
17612                            return count.intValue();
17613                    }
17614                    catch (Exception e) {
17615                            throw processException(e);
17616                    }
17617                    finally {
17618                            closeSession(session);
17619                    }
17620            }
17621    
17622            /**
17623             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
17624             *
17625             * @param groupId the group ID
17626             * @param categoryId the category ID
17627             * @param status the status
17628             * @return the number of matching message-boards messages
17629             * @throws SystemException if a system exception occurred
17630             */
17631            public int countByG_C_S(long groupId, long categoryId, int status)
17632                    throws SystemException {
17633                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
17634    
17635                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
17636                                    finderArgs, this);
17637    
17638                    if (count == null) {
17639                            StringBundler query = new StringBundler(4);
17640    
17641                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17642    
17643                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
17644    
17645                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
17646    
17647                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
17648    
17649                            String sql = query.toString();
17650    
17651                            Session session = null;
17652    
17653                            try {
17654                                    session = openSession();
17655    
17656                                    Query q = session.createQuery(sql);
17657    
17658                                    QueryPos qPos = QueryPos.getInstance(q);
17659    
17660                                    qPos.add(groupId);
17661    
17662                                    qPos.add(categoryId);
17663    
17664                                    qPos.add(status);
17665    
17666                                    count = (Long)q.uniqueResult();
17667                            }
17668                            catch (Exception e) {
17669                                    throw processException(e);
17670                            }
17671                            finally {
17672                                    if (count == null) {
17673                                            count = Long.valueOf(0);
17674                                    }
17675    
17676                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
17677                                            finderArgs, count);
17678    
17679                                    closeSession(session);
17680                            }
17681                    }
17682    
17683                    return count.intValue();
17684            }
17685    
17686            /**
17687             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
17688             *
17689             * @param groupId the group ID
17690             * @param categoryId the category ID
17691             * @param status the status
17692             * @return the number of matching message-boards messages that the user has permission to view
17693             * @throws SystemException if a system exception occurred
17694             */
17695            public int filterCountByG_C_S(long groupId, long categoryId, int status)
17696                    throws SystemException {
17697                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17698                            return countByG_C_S(groupId, categoryId, status);
17699                    }
17700    
17701                    StringBundler query = new StringBundler(4);
17702    
17703                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17704    
17705                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
17706    
17707                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
17708    
17709                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
17710    
17711                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17712                                    MBMessage.class.getName(),
17713                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17714    
17715                    Session session = null;
17716    
17717                    try {
17718                            session = openSession();
17719    
17720                            SQLQuery q = session.createSQLQuery(sql);
17721    
17722                            q.addScalar(COUNT_COLUMN_NAME,
17723                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17724    
17725                            QueryPos qPos = QueryPos.getInstance(q);
17726    
17727                            qPos.add(groupId);
17728    
17729                            qPos.add(categoryId);
17730    
17731                            qPos.add(status);
17732    
17733                            Long count = (Long)q.uniqueResult();
17734    
17735                            return count.intValue();
17736                    }
17737                    catch (Exception e) {
17738                            throw processException(e);
17739                    }
17740                    finally {
17741                            closeSession(session);
17742                    }
17743            }
17744    
17745            /**
17746             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
17747             *
17748             * @param userId the user ID
17749             * @param classNameId the class name ID
17750             * @param classPK the class p k
17751             * @return the number of matching message-boards messages
17752             * @throws SystemException if a system exception occurred
17753             */
17754            public int countByU_C_C(long userId, long classNameId, long classPK)
17755                    throws SystemException {
17756                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
17757    
17758                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
17759                                    finderArgs, this);
17760    
17761                    if (count == null) {
17762                            StringBundler query = new StringBundler(4);
17763    
17764                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17765    
17766                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
17767    
17768                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
17769    
17770                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
17771    
17772                            String sql = query.toString();
17773    
17774                            Session session = null;
17775    
17776                            try {
17777                                    session = openSession();
17778    
17779                                    Query q = session.createQuery(sql);
17780    
17781                                    QueryPos qPos = QueryPos.getInstance(q);
17782    
17783                                    qPos.add(userId);
17784    
17785                                    qPos.add(classNameId);
17786    
17787                                    qPos.add(classPK);
17788    
17789                                    count = (Long)q.uniqueResult();
17790                            }
17791                            catch (Exception e) {
17792                                    throw processException(e);
17793                            }
17794                            finally {
17795                                    if (count == null) {
17796                                            count = Long.valueOf(0);
17797                                    }
17798    
17799                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
17800                                            finderArgs, count);
17801    
17802                                    closeSession(session);
17803                            }
17804                    }
17805    
17806                    return count.intValue();
17807            }
17808    
17809            /**
17810             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
17811             *
17812             * @param userId the user ID
17813             * @param classNameId the class name ID
17814             * @param status the status
17815             * @return the number of matching message-boards messages
17816             * @throws SystemException if a system exception occurred
17817             */
17818            public int countByU_C_S(long userId, long classNameId, int status)
17819                    throws SystemException {
17820                    Object[] finderArgs = new Object[] { userId, classNameId, status };
17821    
17822                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_S,
17823                                    finderArgs, this);
17824    
17825                    if (count == null) {
17826                            StringBundler query = new StringBundler(4);
17827    
17828                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17829    
17830                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
17831    
17832                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
17833    
17834                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
17835    
17836                            String sql = query.toString();
17837    
17838                            Session session = null;
17839    
17840                            try {
17841                                    session = openSession();
17842    
17843                                    Query q = session.createQuery(sql);
17844    
17845                                    QueryPos qPos = QueryPos.getInstance(q);
17846    
17847                                    qPos.add(userId);
17848    
17849                                    qPos.add(classNameId);
17850    
17851                                    qPos.add(status);
17852    
17853                                    count = (Long)q.uniqueResult();
17854                            }
17855                            catch (Exception e) {
17856                                    throw processException(e);
17857                            }
17858                            finally {
17859                                    if (count == null) {
17860                                            count = Long.valueOf(0);
17861                                    }
17862    
17863                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_S,
17864                                            finderArgs, count);
17865    
17866                                    closeSession(session);
17867                            }
17868                    }
17869    
17870                    return count.intValue();
17871            }
17872    
17873            /**
17874             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
17875             *
17876             * @param userId the user ID
17877             * @param classNameIds the class name IDs
17878             * @param status the status
17879             * @return the number of matching message-boards messages
17880             * @throws SystemException if a system exception occurred
17881             */
17882            public int countByU_C_S(long userId, long[] classNameIds, int status)
17883                    throws SystemException {
17884                    Object[] finderArgs = new Object[] {
17885                                    userId, StringUtil.merge(classNameIds), status
17886                            };
17887    
17888                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
17889                                    finderArgs, this);
17890    
17891                    if (count == null) {
17892                            StringBundler query = new StringBundler();
17893    
17894                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17895    
17896                            boolean conjunctionable = false;
17897    
17898                            if (conjunctionable) {
17899                                    query.append(WHERE_AND);
17900                            }
17901    
17902                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
17903    
17904                            conjunctionable = true;
17905    
17906                            if ((classNameIds == null) || (classNameIds.length > 0)) {
17907                                    if (conjunctionable) {
17908                                            query.append(WHERE_AND);
17909                                    }
17910    
17911                                    query.append(StringPool.OPEN_PARENTHESIS);
17912    
17913                                    for (int i = 0; i < classNameIds.length; i++) {
17914                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
17915    
17916                                            if ((i + 1) < classNameIds.length) {
17917                                                    query.append(WHERE_OR);
17918                                            }
17919                                    }
17920    
17921                                    query.append(StringPool.CLOSE_PARENTHESIS);
17922    
17923                                    conjunctionable = true;
17924                            }
17925    
17926                            if (conjunctionable) {
17927                                    query.append(WHERE_AND);
17928                            }
17929    
17930                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
17931    
17932                            conjunctionable = true;
17933    
17934                            String sql = query.toString();
17935    
17936                            Session session = null;
17937    
17938                            try {
17939                                    session = openSession();
17940    
17941                                    Query q = session.createQuery(sql);
17942    
17943                                    QueryPos qPos = QueryPos.getInstance(q);
17944    
17945                                    qPos.add(userId);
17946    
17947                                    if (classNameIds != null) {
17948                                            qPos.add(classNameIds);
17949                                    }
17950    
17951                                    qPos.add(status);
17952    
17953                                    count = (Long)q.uniqueResult();
17954                            }
17955                            catch (Exception e) {
17956                                    throw processException(e);
17957                            }
17958                            finally {
17959                                    if (count == null) {
17960                                            count = Long.valueOf(0);
17961                                    }
17962    
17963                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
17964                                            finderArgs, count);
17965    
17966                                    closeSession(session);
17967                            }
17968                    }
17969    
17970                    return count.intValue();
17971            }
17972    
17973            /**
17974             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
17975             *
17976             * @param classNameId the class name ID
17977             * @param classPK the class p k
17978             * @param status the status
17979             * @return the number of matching message-boards messages
17980             * @throws SystemException if a system exception occurred
17981             */
17982            public int countByC_C_S(long classNameId, long classPK, int status)
17983                    throws SystemException {
17984                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
17985    
17986                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
17987                                    finderArgs, this);
17988    
17989                    if (count == null) {
17990                            StringBundler query = new StringBundler(4);
17991    
17992                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17993    
17994                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
17995    
17996                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
17997    
17998                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
17999    
18000                            String sql = query.toString();
18001    
18002                            Session session = null;
18003    
18004                            try {
18005                                    session = openSession();
18006    
18007                                    Query q = session.createQuery(sql);
18008    
18009                                    QueryPos qPos = QueryPos.getInstance(q);
18010    
18011                                    qPos.add(classNameId);
18012    
18013                                    qPos.add(classPK);
18014    
18015                                    qPos.add(status);
18016    
18017                                    count = (Long)q.uniqueResult();
18018                            }
18019                            catch (Exception e) {
18020                                    throw processException(e);
18021                            }
18022                            finally {
18023                                    if (count == null) {
18024                                            count = Long.valueOf(0);
18025                                    }
18026    
18027                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
18028                                            finderArgs, count);
18029    
18030                                    closeSession(session);
18031                            }
18032                    }
18033    
18034                    return count.intValue();
18035            }
18036    
18037            /**
18038             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
18039             *
18040             * @param groupId the group ID
18041             * @param categoryId the category ID
18042             * @param threadId the thread ID
18043             * @param answer the answer
18044             * @return the number of matching message-boards messages
18045             * @throws SystemException if a system exception occurred
18046             */
18047            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
18048                    boolean answer) throws SystemException {
18049                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
18050    
18051                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_A,
18052                                    finderArgs, this);
18053    
18054                    if (count == null) {
18055                            StringBundler query = new StringBundler(5);
18056    
18057                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18058    
18059                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18060    
18061                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18062    
18063                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18064    
18065                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18066    
18067                            String sql = query.toString();
18068    
18069                            Session session = null;
18070    
18071                            try {
18072                                    session = openSession();
18073    
18074                                    Query q = session.createQuery(sql);
18075    
18076                                    QueryPos qPos = QueryPos.getInstance(q);
18077    
18078                                    qPos.add(groupId);
18079    
18080                                    qPos.add(categoryId);
18081    
18082                                    qPos.add(threadId);
18083    
18084                                    qPos.add(answer);
18085    
18086                                    count = (Long)q.uniqueResult();
18087                            }
18088                            catch (Exception e) {
18089                                    throw processException(e);
18090                            }
18091                            finally {
18092                                    if (count == null) {
18093                                            count = Long.valueOf(0);
18094                                    }
18095    
18096                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_A,
18097                                            finderArgs, count);
18098    
18099                                    closeSession(session);
18100                            }
18101                    }
18102    
18103                    return count.intValue();
18104            }
18105    
18106            /**
18107             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
18108             *
18109             * @param groupId the group ID
18110             * @param categoryId the category ID
18111             * @param threadId the thread ID
18112             * @param answer the answer
18113             * @return the number of matching message-boards messages that the user has permission to view
18114             * @throws SystemException if a system exception occurred
18115             */
18116            public int filterCountByG_C_T_A(long groupId, long categoryId,
18117                    long threadId, boolean answer) throws SystemException {
18118                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18119                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
18120                    }
18121    
18122                    StringBundler query = new StringBundler(5);
18123    
18124                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18125    
18126                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18127    
18128                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18129    
18130                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18131    
18132                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18133    
18134                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18135                                    MBMessage.class.getName(),
18136                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18137    
18138                    Session session = null;
18139    
18140                    try {
18141                            session = openSession();
18142    
18143                            SQLQuery q = session.createSQLQuery(sql);
18144    
18145                            q.addScalar(COUNT_COLUMN_NAME,
18146                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18147    
18148                            QueryPos qPos = QueryPos.getInstance(q);
18149    
18150                            qPos.add(groupId);
18151    
18152                            qPos.add(categoryId);
18153    
18154                            qPos.add(threadId);
18155    
18156                            qPos.add(answer);
18157    
18158                            Long count = (Long)q.uniqueResult();
18159    
18160                            return count.intValue();
18161                    }
18162                    catch (Exception e) {
18163                            throw processException(e);
18164                    }
18165                    finally {
18166                            closeSession(session);
18167                    }
18168            }
18169    
18170            /**
18171             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18172             *
18173             * @param groupId the group ID
18174             * @param categoryId the category ID
18175             * @param threadId the thread ID
18176             * @param status the status
18177             * @return the number of matching message-boards messages
18178             * @throws SystemException if a system exception occurred
18179             */
18180            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18181                    int status) throws SystemException {
18182                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18183    
18184                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
18185                                    finderArgs, this);
18186    
18187                    if (count == null) {
18188                            StringBundler query = new StringBundler(5);
18189    
18190                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18191    
18192                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18193    
18194                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18195    
18196                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18197    
18198                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18199    
18200                            String sql = query.toString();
18201    
18202                            Session session = null;
18203    
18204                            try {
18205                                    session = openSession();
18206    
18207                                    Query q = session.createQuery(sql);
18208    
18209                                    QueryPos qPos = QueryPos.getInstance(q);
18210    
18211                                    qPos.add(groupId);
18212    
18213                                    qPos.add(categoryId);
18214    
18215                                    qPos.add(threadId);
18216    
18217                                    qPos.add(status);
18218    
18219                                    count = (Long)q.uniqueResult();
18220                            }
18221                            catch (Exception e) {
18222                                    throw processException(e);
18223                            }
18224                            finally {
18225                                    if (count == null) {
18226                                            count = Long.valueOf(0);
18227                                    }
18228    
18229                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
18230                                            finderArgs, count);
18231    
18232                                    closeSession(session);
18233                            }
18234                    }
18235    
18236                    return count.intValue();
18237            }
18238    
18239            /**
18240             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18241             *
18242             * @param groupId the group ID
18243             * @param categoryId the category ID
18244             * @param threadId the thread ID
18245             * @param status the status
18246             * @return the number of matching message-boards messages that the user has permission to view
18247             * @throws SystemException if a system exception occurred
18248             */
18249            public int filterCountByG_C_T_S(long groupId, long categoryId,
18250                    long threadId, int status) throws SystemException {
18251                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18252                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18253                    }
18254    
18255                    StringBundler query = new StringBundler(5);
18256    
18257                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18258    
18259                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18260    
18261                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18262    
18263                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18264    
18265                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18266    
18267                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18268                                    MBMessage.class.getName(),
18269                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18270    
18271                    Session session = null;
18272    
18273                    try {
18274                            session = openSession();
18275    
18276                            SQLQuery q = session.createSQLQuery(sql);
18277    
18278                            q.addScalar(COUNT_COLUMN_NAME,
18279                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18280    
18281                            QueryPos qPos = QueryPos.getInstance(q);
18282    
18283                            qPos.add(groupId);
18284    
18285                            qPos.add(categoryId);
18286    
18287                            qPos.add(threadId);
18288    
18289                            qPos.add(status);
18290    
18291                            Long count = (Long)q.uniqueResult();
18292    
18293                            return count.intValue();
18294                    }
18295                    catch (Exception e) {
18296                            throw processException(e);
18297                    }
18298                    finally {
18299                            closeSession(session);
18300                    }
18301            }
18302    
18303            /**
18304             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18305             *
18306             * @param userId the user ID
18307             * @param classNameId the class name ID
18308             * @param classPK the class p k
18309             * @param status the status
18310             * @return the number of matching message-boards messages
18311             * @throws SystemException if a system exception occurred
18312             */
18313            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18314                    int status) throws SystemException {
18315                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18316    
18317                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_S,
18318                                    finderArgs, this);
18319    
18320                    if (count == null) {
18321                            StringBundler query = new StringBundler(5);
18322    
18323                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18324    
18325                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18326    
18327                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18328    
18329                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18330    
18331                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18332    
18333                            String sql = query.toString();
18334    
18335                            Session session = null;
18336    
18337                            try {
18338                                    session = openSession();
18339    
18340                                    Query q = session.createQuery(sql);
18341    
18342                                    QueryPos qPos = QueryPos.getInstance(q);
18343    
18344                                    qPos.add(userId);
18345    
18346                                    qPos.add(classNameId);
18347    
18348                                    qPos.add(classPK);
18349    
18350                                    qPos.add(status);
18351    
18352                                    count = (Long)q.uniqueResult();
18353                            }
18354                            catch (Exception e) {
18355                                    throw processException(e);
18356                            }
18357                            finally {
18358                                    if (count == null) {
18359                                            count = Long.valueOf(0);
18360                                    }
18361    
18362                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_S,
18363                                            finderArgs, count);
18364    
18365                                    closeSession(session);
18366                            }
18367                    }
18368    
18369                    return count.intValue();
18370            }
18371    
18372            /**
18373             * Returns the number of message-boards messages.
18374             *
18375             * @return the number of message-boards messages
18376             * @throws SystemException if a system exception occurred
18377             */
18378            public int countAll() throws SystemException {
18379                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
18380                                    FINDER_ARGS_EMPTY, this);
18381    
18382                    if (count == null) {
18383                            Session session = null;
18384    
18385                            try {
18386                                    session = openSession();
18387    
18388                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
18389    
18390                                    count = (Long)q.uniqueResult();
18391                            }
18392                            catch (Exception e) {
18393                                    throw processException(e);
18394                            }
18395                            finally {
18396                                    if (count == null) {
18397                                            count = Long.valueOf(0);
18398                                    }
18399    
18400                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
18401                                            FINDER_ARGS_EMPTY, count);
18402    
18403                                    closeSession(session);
18404                            }
18405                    }
18406    
18407                    return count.intValue();
18408            }
18409    
18410            /**
18411             * Initializes the message-boards message persistence.
18412             */
18413            public void afterPropertiesSet() {
18414                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
18415                                            com.liferay.portal.util.PropsUtil.get(
18416                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
18417    
18418                    if (listenerClassNames.length > 0) {
18419                            try {
18420                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
18421    
18422                                    for (String listenerClassName : listenerClassNames) {
18423                                            Class<?> clazz = getClass();
18424    
18425                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
18426                                                            clazz.getClassLoader(), listenerClassName));
18427                                    }
18428    
18429                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
18430                            }
18431                            catch (Exception e) {
18432                                    _log.error(e);
18433                            }
18434                    }
18435            }
18436    
18437            public void destroy() {
18438                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
18439                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
18440                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18441            }
18442    
18443            @BeanReference(type = MBBanPersistence.class)
18444            protected MBBanPersistence mbBanPersistence;
18445            @BeanReference(type = MBCategoryPersistence.class)
18446            protected MBCategoryPersistence mbCategoryPersistence;
18447            @BeanReference(type = MBDiscussionPersistence.class)
18448            protected MBDiscussionPersistence mbDiscussionPersistence;
18449            @BeanReference(type = MBMailingListPersistence.class)
18450            protected MBMailingListPersistence mbMailingListPersistence;
18451            @BeanReference(type = MBMessagePersistence.class)
18452            protected MBMessagePersistence mbMessagePersistence;
18453            @BeanReference(type = MBStatsUserPersistence.class)
18454            protected MBStatsUserPersistence mbStatsUserPersistence;
18455            @BeanReference(type = MBThreadPersistence.class)
18456            protected MBThreadPersistence mbThreadPersistence;
18457            @BeanReference(type = MBThreadFlagPersistence.class)
18458            protected MBThreadFlagPersistence mbThreadFlagPersistence;
18459            @BeanReference(type = CompanyPersistence.class)
18460            protected CompanyPersistence companyPersistence;
18461            @BeanReference(type = GroupPersistence.class)
18462            protected GroupPersistence groupPersistence;
18463            @BeanReference(type = LockPersistence.class)
18464            protected LockPersistence lockPersistence;
18465            @BeanReference(type = PortletPreferencesPersistence.class)
18466            protected PortletPreferencesPersistence portletPreferencesPersistence;
18467            @BeanReference(type = ResourcePersistence.class)
18468            protected ResourcePersistence resourcePersistence;
18469            @BeanReference(type = SubscriptionPersistence.class)
18470            protected SubscriptionPersistence subscriptionPersistence;
18471            @BeanReference(type = UserPersistence.class)
18472            protected UserPersistence userPersistence;
18473            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
18474            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
18475            @BeanReference(type = AssetEntryPersistence.class)
18476            protected AssetEntryPersistence assetEntryPersistence;
18477            @BeanReference(type = AssetLinkPersistence.class)
18478            protected AssetLinkPersistence assetLinkPersistence;
18479            @BeanReference(type = AssetTagPersistence.class)
18480            protected AssetTagPersistence assetTagPersistence;
18481            @BeanReference(type = BlogsEntryPersistence.class)
18482            protected BlogsEntryPersistence blogsEntryPersistence;
18483            @BeanReference(type = ExpandoValuePersistence.class)
18484            protected ExpandoValuePersistence expandoValuePersistence;
18485            @BeanReference(type = RatingsStatsPersistence.class)
18486            protected RatingsStatsPersistence ratingsStatsPersistence;
18487            @BeanReference(type = SocialActivityPersistence.class)
18488            protected SocialActivityPersistence socialActivityPersistence;
18489            @BeanReference(type = WikiPagePersistence.class)
18490            protected WikiPagePersistence wikiPagePersistence;
18491            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
18492            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
18493            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
18494            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
18495            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
18496            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
18497            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
18498            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
18499            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
18500            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
18501            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
18502            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
18503            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
18504            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
18505            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
18506            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
18507            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
18508            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
18509            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
18510            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
18511            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18512            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
18513            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
18514            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
18515            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
18516            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
18517                    _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
18518            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
18519            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
18520                    _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
18521            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18522            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
18523            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
18524            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
18525            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
18526            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
18527            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18528            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
18529            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18530            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
18531            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18532            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
18533            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
18534            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
18535            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18536            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
18537            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18538            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18539            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
18540            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
18541            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18542            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
18543            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18544            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
18545                    _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
18546            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18547            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
18548                    _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
18549            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
18550            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
18551                    _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
18552            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18553            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18554            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
18555            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
18556            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18557            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
18558            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
18559            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18560            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18561            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18562            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18563            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18564            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18565            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18566            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18567    
18568            private static String _removeConjunction(String sql) {
18569                    int pos = sql.indexOf(" AND ");
18570    
18571                    if (pos != -1) {
18572                            sql = sql.substring(0, pos);
18573                    }
18574    
18575                    return sql;
18576            }
18577    
18578            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
18579            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
18580            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
18581                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
18582            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
18583                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
18584            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
18585            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
18586            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
18587            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
18588            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
18589            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
18590            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
18591            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
18592            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
18593            private static MBMessage _nullMBMessage = new MBMessageImpl() {
18594                            @Override
18595                            public Object clone() {
18596                                    return this;
18597                            }
18598    
18599                            @Override
18600                            public CacheModel<MBMessage> toCacheModel() {
18601                                    return _nullMBMessageCacheModel;
18602                            }
18603                    };
18604    
18605            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
18606                            public MBMessage toEntityModel() {
18607                                    return _nullMBMessage;
18608                            }
18609                    };
18610    }