001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.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 clearUniqueFindersCache(MBMessage mbMessage) {
768                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
769                            new Object[] {
770                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
771                            });
772            }
773    
774            /**
775             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
776             *
777             * @param messageId the primary key for the new message-boards message
778             * @return the new message-boards message
779             */
780            public MBMessage create(long messageId) {
781                    MBMessage mbMessage = new MBMessageImpl();
782    
783                    mbMessage.setNew(true);
784                    mbMessage.setPrimaryKey(messageId);
785    
786                    String uuid = PortalUUIDUtil.generate();
787    
788                    mbMessage.setUuid(uuid);
789    
790                    return mbMessage;
791            }
792    
793            /**
794             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
795             *
796             * @param messageId the primary key of the message-boards message
797             * @return the message-boards message that was removed
798             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
799             * @throws SystemException if a system exception occurred
800             */
801            public MBMessage remove(long messageId)
802                    throws NoSuchMessageException, SystemException {
803                    return remove(Long.valueOf(messageId));
804            }
805    
806            /**
807             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
808             *
809             * @param primaryKey the primary key of the message-boards message
810             * @return the message-boards message that was removed
811             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
812             * @throws SystemException if a system exception occurred
813             */
814            @Override
815            public MBMessage remove(Serializable primaryKey)
816                    throws NoSuchMessageException, SystemException {
817                    Session session = null;
818    
819                    try {
820                            session = openSession();
821    
822                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
823                                            primaryKey);
824    
825                            if (mbMessage == null) {
826                                    if (_log.isWarnEnabled()) {
827                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
828                                    }
829    
830                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
831                                            primaryKey);
832                            }
833    
834                            return remove(mbMessage);
835                    }
836                    catch (NoSuchMessageException nsee) {
837                            throw nsee;
838                    }
839                    catch (Exception e) {
840                            throw processException(e);
841                    }
842                    finally {
843                            closeSession(session);
844                    }
845            }
846    
847            @Override
848            protected MBMessage removeImpl(MBMessage mbMessage)
849                    throws SystemException {
850                    mbMessage = toUnwrappedModel(mbMessage);
851    
852                    Session session = null;
853    
854                    try {
855                            session = openSession();
856    
857                            BatchSessionUtil.delete(session, mbMessage);
858                    }
859                    catch (Exception e) {
860                            throw processException(e);
861                    }
862                    finally {
863                            closeSession(session);
864                    }
865    
866                    clearCache(mbMessage);
867    
868                    return mbMessage;
869            }
870    
871            @Override
872            public MBMessage updateImpl(
873                    com.liferay.portlet.messageboards.model.MBMessage mbMessage,
874                    boolean merge) throws SystemException {
875                    mbMessage = toUnwrappedModel(mbMessage);
876    
877                    boolean isNew = mbMessage.isNew();
878    
879                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
880    
881                    if (Validator.isNull(mbMessage.getUuid())) {
882                            String uuid = PortalUUIDUtil.generate();
883    
884                            mbMessage.setUuid(uuid);
885                    }
886    
887                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
888    
889                    if (userId > 0) {
890                            long companyId = mbMessage.getCompanyId();
891    
892                            long groupId = mbMessage.getGroupId();
893    
894                            long messageId = 0;
895    
896                            if (!isNew) {
897                                    messageId = mbMessage.getPrimaryKey();
898                            }
899    
900                            try {
901                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
902                                                    userId,
903                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
904                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
905                                                    mbMessage.getSubject(), null));
906                            }
907                            catch (SanitizerException se) {
908                                    throw new SystemException(se);
909                            }
910                    }
911    
912                    Session session = null;
913    
914                    try {
915                            session = openSession();
916    
917                            BatchSessionUtil.update(session, mbMessage, merge);
918    
919                            mbMessage.setNew(false);
920                    }
921                    catch (Exception e) {
922                            throw processException(e);
923                    }
924                    finally {
925                            closeSession(session);
926                    }
927    
928                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
929    
930                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
931                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
932                    }
933    
934                    else {
935                            if ((mbMessageModelImpl.getColumnBitmask() &
936                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
937                                    Object[] args = new Object[] {
938                                                    mbMessageModelImpl.getOriginalUuid()
939                                            };
940    
941                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
942                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
943                                            args);
944    
945                                    args = new Object[] { mbMessageModelImpl.getUuid() };
946    
947                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
948                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
949                                            args);
950                            }
951    
952                            if ((mbMessageModelImpl.getColumnBitmask() &
953                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
954                                    Object[] args = new Object[] {
955                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
956                                            };
957    
958                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
959                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
960                                            args);
961    
962                                    args = new Object[] {
963                                                    Long.valueOf(mbMessageModelImpl.getGroupId())
964                                            };
965    
966                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
967                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
968                                            args);
969                            }
970    
971                            if ((mbMessageModelImpl.getColumnBitmask() &
972                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
973                                    Object[] args = new Object[] {
974                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
975                                            };
976    
977                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
978                                            args);
979                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
980                                            args);
981    
982                                    args = new Object[] {
983                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
984                                            };
985    
986                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
987                                            args);
988                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
989                                            args);
990                            }
991    
992                            if ((mbMessageModelImpl.getColumnBitmask() &
993                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
994                                    Object[] args = new Object[] {
995                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
996                                            };
997    
998                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
999                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1000                                            args);
1001    
1002                                    args = new Object[] {
1003                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1004                                            };
1005    
1006                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1007                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1008                                            args);
1009                            }
1010    
1011                            if ((mbMessageModelImpl.getColumnBitmask() &
1012                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
1013                                    Object[] args = new Object[] {
1014                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1015                                            };
1016    
1017                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1018                                            args);
1019                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1020                                            args);
1021    
1022                                    args = new Object[] {
1023                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1024                                            };
1025    
1026                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1027                                            args);
1028                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1029                                            args);
1030                            }
1031    
1032                            if ((mbMessageModelImpl.getColumnBitmask() &
1033                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1034                                    Object[] args = new Object[] {
1035                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1036                                            };
1037    
1038                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1039                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1040                                            args);
1041    
1042                                    args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
1043    
1044                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1045                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1046                                            args);
1047                            }
1048    
1049                            if ((mbMessageModelImpl.getColumnBitmask() &
1050                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
1051                                    Object[] args = new Object[] {
1052                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1053                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1054                                            };
1055    
1056                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1057                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1058                                            args);
1059    
1060                                    args = new Object[] {
1061                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1062                                                    Long.valueOf(mbMessageModelImpl.getUserId())
1063                                            };
1064    
1065                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1066                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1067                                            args);
1068                            }
1069    
1070                            if ((mbMessageModelImpl.getColumnBitmask() &
1071                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1072                                    Object[] args = new Object[] {
1073                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1074                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
1075                                            };
1076    
1077                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1078                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1079                                            args);
1080    
1081                                    args = new Object[] {
1082                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1083                                                    Long.valueOf(mbMessageModelImpl.getCategoryId())
1084                                            };
1085    
1086                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1087                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1088                                            args);
1089                            }
1090    
1091                            if ((mbMessageModelImpl.getColumnBitmask() &
1092                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
1093                                    Object[] args = new Object[] {
1094                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1095                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1096                                            };
1097    
1098                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1099                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1100                                            args);
1101    
1102                                    args = new Object[] {
1103                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1104                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1105                                            };
1106    
1107                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1108                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1109                                            args);
1110                            }
1111    
1112                            if ((mbMessageModelImpl.getColumnBitmask() &
1113                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
1114                                    Object[] args = new Object[] {
1115                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
1116                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1117                                            };
1118    
1119                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1120                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1121                                            args);
1122    
1123                                    args = new Object[] {
1124                                                    Long.valueOf(mbMessageModelImpl.getCompanyId()),
1125                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1126                                            };
1127    
1128                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1129                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1130                                            args);
1131                            }
1132    
1133                            if ((mbMessageModelImpl.getColumnBitmask() &
1134                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
1135                                    Object[] args = new Object[] {
1136                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1137                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
1138                                            };
1139    
1140                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1141                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1142                                            args);
1143    
1144                                    args = new Object[] {
1145                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1146                                                    Long.valueOf(mbMessageModelImpl.getClassNameId())
1147                                            };
1148    
1149                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1150                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1151                                            args);
1152                            }
1153    
1154                            if ((mbMessageModelImpl.getColumnBitmask() &
1155                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1156                                    Object[] args = new Object[] {
1157                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1158                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1159                                            };
1160    
1161                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1162                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1163                                            args);
1164    
1165                                    args = new Object[] {
1166                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1167                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1168                                            };
1169    
1170                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1171                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1172                                            args);
1173                            }
1174    
1175                            if ((mbMessageModelImpl.getColumnBitmask() &
1176                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
1177                                    Object[] args = new Object[] {
1178                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1179                                                    Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
1180                                            };
1181    
1182                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1183                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1184                                            args);
1185    
1186                                    args = new Object[] {
1187                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1188                                                    Long.valueOf(mbMessageModelImpl.getParentMessageId())
1189                                            };
1190    
1191                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1192                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1193                                            args);
1194                            }
1195    
1196                            if ((mbMessageModelImpl.getColumnBitmask() &
1197                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
1198                                    Object[] args = new Object[] {
1199                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1200                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1201                                            };
1202    
1203                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1204                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1205                                            args);
1206    
1207                                    args = new Object[] {
1208                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1209                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1210                                            };
1211    
1212                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1213                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1214                                            args);
1215                            }
1216    
1217                            if ((mbMessageModelImpl.getColumnBitmask() &
1218                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
1219                                    Object[] args = new Object[] {
1220                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1221                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1222                                            };
1223    
1224                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1225                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1226                                            args);
1227    
1228                                    args = new Object[] {
1229                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1230                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1231                                            };
1232    
1233                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1234                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1235                                            args);
1236                            }
1237    
1238                            if ((mbMessageModelImpl.getColumnBitmask() &
1239                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
1240                                    Object[] args = new Object[] {
1241                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1242                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1243                                            };
1244    
1245                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1246                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1247                                            args);
1248    
1249                                    args = new Object[] {
1250                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1251                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1252                                            };
1253    
1254                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1255                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1256                                            args);
1257                            }
1258    
1259                            if ((mbMessageModelImpl.getColumnBitmask() &
1260                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
1261                                    Object[] args = new Object[] {
1262                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1263                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1264                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1265                                            };
1266    
1267                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1268                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1269                                            args);
1270    
1271                                    args = new Object[] {
1272                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1273                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1274                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1275                                            };
1276    
1277                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1279                                            args);
1280                            }
1281    
1282                            if ((mbMessageModelImpl.getColumnBitmask() &
1283                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
1284                                    Object[] args = new Object[] {
1285                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1286                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1287                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1288                                            };
1289    
1290                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1291                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1292                                            args);
1293    
1294                                    args = new Object[] {
1295                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1296                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1297                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1298                                            };
1299    
1300                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1301                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1302                                            args);
1303                            }
1304    
1305                            if ((mbMessageModelImpl.getColumnBitmask() &
1306                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
1307                                    Object[] args = new Object[] {
1308                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1309                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1310                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1311                                            };
1312    
1313                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1314                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1315                                            args);
1316    
1317                                    args = new Object[] {
1318                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1319                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1320                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1321                                            };
1322    
1323                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1324                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1325                                            args);
1326                            }
1327    
1328                            if ((mbMessageModelImpl.getColumnBitmask() &
1329                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
1330                                    Object[] args = new Object[] {
1331                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1332                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1333                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1334                                            };
1335    
1336                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1337                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1338                                            args);
1339    
1340                                    args = new Object[] {
1341                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1342                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1343                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1344                                            };
1345    
1346                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1347                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1348                                            args);
1349                            }
1350    
1351                            if ((mbMessageModelImpl.getColumnBitmask() &
1352                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
1353                                    Object[] args = new Object[] {
1354                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1355                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1356                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1357                                            };
1358    
1359                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1360                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1361                                            args);
1362    
1363                                    args = new Object[] {
1364                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1365                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1366                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1367                                            };
1368    
1369                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1370                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1371                                            args);
1372                            }
1373    
1374                            if ((mbMessageModelImpl.getColumnBitmask() &
1375                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1376                                    Object[] args = new Object[] {
1377                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1378                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1379                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1380                                            };
1381    
1382                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1383                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1384                                            args);
1385    
1386                                    args = new Object[] {
1387                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1388                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1389                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1390                                            };
1391    
1392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1393                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1394                                            args);
1395                            }
1396    
1397                            if ((mbMessageModelImpl.getColumnBitmask() &
1398                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
1399                                    Object[] args = new Object[] {
1400                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1401                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1402                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1403                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1404                                            };
1405    
1406                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1407                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1408                                            args);
1409    
1410                                    args = new Object[] {
1411                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1412                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1413                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1414                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1415                                            };
1416    
1417                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1418                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1419                                            args);
1420                            }
1421    
1422                            if ((mbMessageModelImpl.getColumnBitmask() &
1423                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
1424                                    Object[] args = new Object[] {
1425                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1426                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1427                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1428                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1429                                            };
1430    
1431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1433                                            args);
1434    
1435                                    args = new Object[] {
1436                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1437                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1438                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1439                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1440                                            };
1441    
1442                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1443                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1444                                            args);
1445                            }
1446    
1447                            if ((mbMessageModelImpl.getColumnBitmask() &
1448                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
1449                                    Object[] args = new Object[] {
1450                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1451                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1452                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1453                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1454                                            };
1455    
1456                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1457                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1458                                            args);
1459    
1460                                    args = new Object[] {
1461                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1462                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1463                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1464                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1465                                            };
1466    
1467                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1468                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1469                                            args);
1470                            }
1471                    }
1472    
1473                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1474                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
1475    
1476                    if (isNew) {
1477                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1478                                    new Object[] {
1479                                            mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
1480                                    }, mbMessage);
1481                    }
1482                    else {
1483                            if ((mbMessageModelImpl.getColumnBitmask() &
1484                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1485                                    Object[] args = new Object[] {
1486                                                    mbMessageModelImpl.getOriginalUuid(),
1487                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
1488                                            };
1489    
1490                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1491    
1492                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1493    
1494                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1495                                            new Object[] {
1496                                                    mbMessage.getUuid(),
1497                                                    Long.valueOf(mbMessage.getGroupId())
1498                                            }, mbMessage);
1499                            }
1500                    }
1501    
1502                    return mbMessage;
1503            }
1504    
1505            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
1506                    if (mbMessage instanceof MBMessageImpl) {
1507                            return mbMessage;
1508                    }
1509    
1510                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
1511    
1512                    mbMessageImpl.setNew(mbMessage.isNew());
1513                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
1514    
1515                    mbMessageImpl.setUuid(mbMessage.getUuid());
1516                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
1517                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
1518                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
1519                    mbMessageImpl.setUserId(mbMessage.getUserId());
1520                    mbMessageImpl.setUserName(mbMessage.getUserName());
1521                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
1522                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
1523                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
1524                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
1525                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
1526                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
1527                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
1528                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
1529                    mbMessageImpl.setSubject(mbMessage.getSubject());
1530                    mbMessageImpl.setBody(mbMessage.getBody());
1531                    mbMessageImpl.setFormat(mbMessage.getFormat());
1532                    mbMessageImpl.setAttachments(mbMessage.isAttachments());
1533                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
1534                    mbMessageImpl.setPriority(mbMessage.getPriority());
1535                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
1536                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
1537                    mbMessageImpl.setStatus(mbMessage.getStatus());
1538                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
1539                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
1540                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
1541    
1542                    return mbMessageImpl;
1543            }
1544    
1545            /**
1546             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1547             *
1548             * @param primaryKey the primary key of the message-boards message
1549             * @return the message-boards message
1550             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
1551             * @throws SystemException if a system exception occurred
1552             */
1553            @Override
1554            public MBMessage findByPrimaryKey(Serializable primaryKey)
1555                    throws NoSuchModelException, SystemException {
1556                    return findByPrimaryKey(((Long)primaryKey).longValue());
1557            }
1558    
1559            /**
1560             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
1561             *
1562             * @param messageId the primary key of the message-boards message
1563             * @return the message-boards message
1564             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1565             * @throws SystemException if a system exception occurred
1566             */
1567            public MBMessage findByPrimaryKey(long messageId)
1568                    throws NoSuchMessageException, SystemException {
1569                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
1570    
1571                    if (mbMessage == null) {
1572                            if (_log.isWarnEnabled()) {
1573                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
1574                            }
1575    
1576                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1577                                    messageId);
1578                    }
1579    
1580                    return mbMessage;
1581            }
1582    
1583            /**
1584             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1585             *
1586             * @param primaryKey the primary key of the message-boards message
1587             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1588             * @throws SystemException if a system exception occurred
1589             */
1590            @Override
1591            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
1592                    throws SystemException {
1593                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1594            }
1595    
1596            /**
1597             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1598             *
1599             * @param messageId the primary key of the message-boards message
1600             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1601             * @throws SystemException if a system exception occurred
1602             */
1603            public MBMessage fetchByPrimaryKey(long messageId)
1604                    throws SystemException {
1605                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1606                                    MBMessageImpl.class, messageId);
1607    
1608                    if (mbMessage == _nullMBMessage) {
1609                            return null;
1610                    }
1611    
1612                    if (mbMessage == null) {
1613                            Session session = null;
1614    
1615                            boolean hasException = false;
1616    
1617                            try {
1618                                    session = openSession();
1619    
1620                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
1621                                                    Long.valueOf(messageId));
1622                            }
1623                            catch (Exception e) {
1624                                    hasException = true;
1625    
1626                                    throw processException(e);
1627                            }
1628                            finally {
1629                                    if (mbMessage != null) {
1630                                            cacheResult(mbMessage);
1631                                    }
1632                                    else if (!hasException) {
1633                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1634                                                    MBMessageImpl.class, messageId, _nullMBMessage);
1635                                    }
1636    
1637                                    closeSession(session);
1638                            }
1639                    }
1640    
1641                    return mbMessage;
1642            }
1643    
1644            /**
1645             * Returns all the message-boards messages where uuid = &#63;.
1646             *
1647             * @param uuid the uuid
1648             * @return the matching message-boards messages
1649             * @throws SystemException if a system exception occurred
1650             */
1651            public List<MBMessage> findByUuid(String uuid) throws SystemException {
1652                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1653            }
1654    
1655            /**
1656             * Returns a range of all the message-boards messages where uuid = &#63;.
1657             *
1658             * <p>
1659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1660             * </p>
1661             *
1662             * @param uuid the uuid
1663             * @param start the lower bound of the range of message-boards messages
1664             * @param end the upper bound of the range of message-boards messages (not inclusive)
1665             * @return the range of matching message-boards messages
1666             * @throws SystemException if a system exception occurred
1667             */
1668            public List<MBMessage> findByUuid(String uuid, int start, int end)
1669                    throws SystemException {
1670                    return findByUuid(uuid, start, end, null);
1671            }
1672    
1673            /**
1674             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
1675             *
1676             * <p>
1677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1678             * </p>
1679             *
1680             * @param uuid the uuid
1681             * @param start the lower bound of the range of message-boards messages
1682             * @param end the upper bound of the range of message-boards messages (not inclusive)
1683             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1684             * @return the ordered range of matching message-boards messages
1685             * @throws SystemException if a system exception occurred
1686             */
1687            public List<MBMessage> findByUuid(String uuid, int start, int end,
1688                    OrderByComparator orderByComparator) throws SystemException {
1689                    FinderPath finderPath = null;
1690                    Object[] finderArgs = null;
1691    
1692                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1693                                    (orderByComparator == null)) {
1694                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1695                            finderArgs = new Object[] { uuid };
1696                    }
1697                    else {
1698                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1699                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1700                    }
1701    
1702                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1703                                    finderArgs, this);
1704    
1705                    if ((list != null) && !list.isEmpty()) {
1706                            for (MBMessage mbMessage : list) {
1707                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
1708                                            list = null;
1709    
1710                                            break;
1711                                    }
1712                            }
1713                    }
1714    
1715                    if (list == null) {
1716                            StringBundler query = null;
1717    
1718                            if (orderByComparator != null) {
1719                                    query = new StringBundler(3 +
1720                                                    (orderByComparator.getOrderByFields().length * 3));
1721                            }
1722                            else {
1723                                    query = new StringBundler(3);
1724                            }
1725    
1726                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1727    
1728                            if (uuid == null) {
1729                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1730                            }
1731                            else {
1732                                    if (uuid.equals(StringPool.BLANK)) {
1733                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1734                                    }
1735                                    else {
1736                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1737                                    }
1738                            }
1739    
1740                            if (orderByComparator != null) {
1741                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1742                                            orderByComparator);
1743                            }
1744    
1745                            else {
1746                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1747                            }
1748    
1749                            String sql = query.toString();
1750    
1751                            Session session = null;
1752    
1753                            try {
1754                                    session = openSession();
1755    
1756                                    Query q = session.createQuery(sql);
1757    
1758                                    QueryPos qPos = QueryPos.getInstance(q);
1759    
1760                                    if (uuid != null) {
1761                                            qPos.add(uuid);
1762                                    }
1763    
1764                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1765                                                    end);
1766                            }
1767                            catch (Exception e) {
1768                                    throw processException(e);
1769                            }
1770                            finally {
1771                                    if (list == null) {
1772                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1773                                    }
1774                                    else {
1775                                            cacheResult(list);
1776    
1777                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1778                                    }
1779    
1780                                    closeSession(session);
1781                            }
1782                    }
1783    
1784                    return list;
1785            }
1786    
1787            /**
1788             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1789             *
1790             * @param uuid the uuid
1791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1792             * @return the first matching message-boards message
1793             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1794             * @throws SystemException if a system exception occurred
1795             */
1796            public MBMessage findByUuid_First(String uuid,
1797                    OrderByComparator orderByComparator)
1798                    throws NoSuchMessageException, SystemException {
1799                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
1800    
1801                    if (mbMessage != null) {
1802                            return mbMessage;
1803                    }
1804    
1805                    StringBundler msg = new StringBundler(4);
1806    
1807                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1808    
1809                    msg.append("uuid=");
1810                    msg.append(uuid);
1811    
1812                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1813    
1814                    throw new NoSuchMessageException(msg.toString());
1815            }
1816    
1817            /**
1818             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1819             *
1820             * @param uuid the uuid
1821             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1822             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1823             * @throws SystemException if a system exception occurred
1824             */
1825            public MBMessage fetchByUuid_First(String uuid,
1826                    OrderByComparator orderByComparator) throws SystemException {
1827                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
1828    
1829                    if (!list.isEmpty()) {
1830                            return list.get(0);
1831                    }
1832    
1833                    return null;
1834            }
1835    
1836            /**
1837             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1838             *
1839             * @param uuid the uuid
1840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1841             * @return the last matching message-boards message
1842             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public MBMessage findByUuid_Last(String uuid,
1846                    OrderByComparator orderByComparator)
1847                    throws NoSuchMessageException, SystemException {
1848                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
1849    
1850                    if (mbMessage != null) {
1851                            return mbMessage;
1852                    }
1853    
1854                    StringBundler msg = new StringBundler(4);
1855    
1856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1857    
1858                    msg.append("uuid=");
1859                    msg.append(uuid);
1860    
1861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1862    
1863                    throw new NoSuchMessageException(msg.toString());
1864            }
1865    
1866            /**
1867             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1868             *
1869             * @param uuid the uuid
1870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1871             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1872             * @throws SystemException if a system exception occurred
1873             */
1874            public MBMessage fetchByUuid_Last(String uuid,
1875                    OrderByComparator orderByComparator) throws SystemException {
1876                    int count = countByUuid(uuid);
1877    
1878                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
1879                                    orderByComparator);
1880    
1881                    if (!list.isEmpty()) {
1882                            return list.get(0);
1883                    }
1884    
1885                    return null;
1886            }
1887    
1888            /**
1889             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
1890             *
1891             * @param messageId the primary key of the current message-boards message
1892             * @param uuid the uuid
1893             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1894             * @return the previous, current, and next message-boards message
1895             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1896             * @throws SystemException if a system exception occurred
1897             */
1898            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
1899                    OrderByComparator orderByComparator)
1900                    throws NoSuchMessageException, SystemException {
1901                    MBMessage mbMessage = findByPrimaryKey(messageId);
1902    
1903                    Session session = null;
1904    
1905                    try {
1906                            session = openSession();
1907    
1908                            MBMessage[] array = new MBMessageImpl[3];
1909    
1910                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1911                                            orderByComparator, true);
1912    
1913                            array[1] = mbMessage;
1914    
1915                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1916                                            orderByComparator, false);
1917    
1918                            return array;
1919                    }
1920                    catch (Exception e) {
1921                            throw processException(e);
1922                    }
1923                    finally {
1924                            closeSession(session);
1925                    }
1926            }
1927    
1928            protected MBMessage getByUuid_PrevAndNext(Session session,
1929                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
1930                    boolean previous) {
1931                    StringBundler query = null;
1932    
1933                    if (orderByComparator != null) {
1934                            query = new StringBundler(6 +
1935                                            (orderByComparator.getOrderByFields().length * 6));
1936                    }
1937                    else {
1938                            query = new StringBundler(3);
1939                    }
1940    
1941                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1942    
1943                    if (uuid == null) {
1944                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1945                    }
1946                    else {
1947                            if (uuid.equals(StringPool.BLANK)) {
1948                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1949                            }
1950                            else {
1951                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1952                            }
1953                    }
1954    
1955                    if (orderByComparator != null) {
1956                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1957    
1958                            if (orderByConditionFields.length > 0) {
1959                                    query.append(WHERE_AND);
1960                            }
1961    
1962                            for (int i = 0; i < orderByConditionFields.length; i++) {
1963                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1964                                    query.append(orderByConditionFields[i]);
1965    
1966                                    if ((i + 1) < orderByConditionFields.length) {
1967                                            if (orderByComparator.isAscending() ^ previous) {
1968                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1969                                            }
1970                                            else {
1971                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1972                                            }
1973                                    }
1974                                    else {
1975                                            if (orderByComparator.isAscending() ^ previous) {
1976                                                    query.append(WHERE_GREATER_THAN);
1977                                            }
1978                                            else {
1979                                                    query.append(WHERE_LESSER_THAN);
1980                                            }
1981                                    }
1982                            }
1983    
1984                            query.append(ORDER_BY_CLAUSE);
1985    
1986                            String[] orderByFields = orderByComparator.getOrderByFields();
1987    
1988                            for (int i = 0; i < orderByFields.length; i++) {
1989                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1990                                    query.append(orderByFields[i]);
1991    
1992                                    if ((i + 1) < orderByFields.length) {
1993                                            if (orderByComparator.isAscending() ^ previous) {
1994                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1995                                            }
1996                                            else {
1997                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1998                                            }
1999                                    }
2000                                    else {
2001                                            if (orderByComparator.isAscending() ^ previous) {
2002                                                    query.append(ORDER_BY_ASC);
2003                                            }
2004                                            else {
2005                                                    query.append(ORDER_BY_DESC);
2006                                            }
2007                                    }
2008                            }
2009                    }
2010    
2011                    else {
2012                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2013                    }
2014    
2015                    String sql = query.toString();
2016    
2017                    Query q = session.createQuery(sql);
2018    
2019                    q.setFirstResult(0);
2020                    q.setMaxResults(2);
2021    
2022                    QueryPos qPos = QueryPos.getInstance(q);
2023    
2024                    if (uuid != null) {
2025                            qPos.add(uuid);
2026                    }
2027    
2028                    if (orderByComparator != null) {
2029                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2030    
2031                            for (Object value : values) {
2032                                    qPos.add(value);
2033                            }
2034                    }
2035    
2036                    List<MBMessage> list = q.list();
2037    
2038                    if (list.size() == 2) {
2039                            return list.get(1);
2040                    }
2041                    else {
2042                            return null;
2043                    }
2044            }
2045    
2046            /**
2047             * 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.
2048             *
2049             * @param uuid the uuid
2050             * @param groupId the group ID
2051             * @return the matching message-boards message
2052             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2053             * @throws SystemException if a system exception occurred
2054             */
2055            public MBMessage findByUUID_G(String uuid, long groupId)
2056                    throws NoSuchMessageException, SystemException {
2057                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
2058    
2059                    if (mbMessage == null) {
2060                            StringBundler msg = new StringBundler(6);
2061    
2062                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2063    
2064                            msg.append("uuid=");
2065                            msg.append(uuid);
2066    
2067                            msg.append(", groupId=");
2068                            msg.append(groupId);
2069    
2070                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2071    
2072                            if (_log.isWarnEnabled()) {
2073                                    _log.warn(msg.toString());
2074                            }
2075    
2076                            throw new NoSuchMessageException(msg.toString());
2077                    }
2078    
2079                    return mbMessage;
2080            }
2081    
2082            /**
2083             * 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.
2084             *
2085             * @param uuid the uuid
2086             * @param groupId the group ID
2087             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2088             * @throws SystemException if a system exception occurred
2089             */
2090            public MBMessage fetchByUUID_G(String uuid, long groupId)
2091                    throws SystemException {
2092                    return fetchByUUID_G(uuid, groupId, true);
2093            }
2094    
2095            /**
2096             * 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.
2097             *
2098             * @param uuid the uuid
2099             * @param groupId the group ID
2100             * @param retrieveFromCache whether to use the finder cache
2101             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2102             * @throws SystemException if a system exception occurred
2103             */
2104            public MBMessage fetchByUUID_G(String uuid, long groupId,
2105                    boolean retrieveFromCache) throws SystemException {
2106                    Object[] finderArgs = new Object[] { uuid, groupId };
2107    
2108                    Object result = null;
2109    
2110                    if (retrieveFromCache) {
2111                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
2112                                            finderArgs, this);
2113                    }
2114    
2115                    if (result instanceof MBMessage) {
2116                            MBMessage mbMessage = (MBMessage)result;
2117    
2118                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
2119                                            (groupId != mbMessage.getGroupId())) {
2120                                    result = null;
2121                            }
2122                    }
2123    
2124                    if (result == null) {
2125                            StringBundler query = new StringBundler(4);
2126    
2127                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2128    
2129                            if (uuid == null) {
2130                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2131                            }
2132                            else {
2133                                    if (uuid.equals(StringPool.BLANK)) {
2134                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2135                                    }
2136                                    else {
2137                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2138                                    }
2139                            }
2140    
2141                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2142    
2143                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2144    
2145                            String sql = query.toString();
2146    
2147                            Session session = null;
2148    
2149                            try {
2150                                    session = openSession();
2151    
2152                                    Query q = session.createQuery(sql);
2153    
2154                                    QueryPos qPos = QueryPos.getInstance(q);
2155    
2156                                    if (uuid != null) {
2157                                            qPos.add(uuid);
2158                                    }
2159    
2160                                    qPos.add(groupId);
2161    
2162                                    List<MBMessage> list = q.list();
2163    
2164                                    result = list;
2165    
2166                                    MBMessage mbMessage = null;
2167    
2168                                    if (list.isEmpty()) {
2169                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2170                                                    finderArgs, list);
2171                                    }
2172                                    else {
2173                                            mbMessage = list.get(0);
2174    
2175                                            cacheResult(mbMessage);
2176    
2177                                            if ((mbMessage.getUuid() == null) ||
2178                                                            !mbMessage.getUuid().equals(uuid) ||
2179                                                            (mbMessage.getGroupId() != groupId)) {
2180                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2181                                                            finderArgs, mbMessage);
2182                                            }
2183                                    }
2184    
2185                                    return mbMessage;
2186                            }
2187                            catch (Exception e) {
2188                                    throw processException(e);
2189                            }
2190                            finally {
2191                                    if (result == null) {
2192                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
2193                                                    finderArgs);
2194                                    }
2195    
2196                                    closeSession(session);
2197                            }
2198                    }
2199                    else {
2200                            if (result instanceof List<?>) {
2201                                    return null;
2202                            }
2203                            else {
2204                                    return (MBMessage)result;
2205                            }
2206                    }
2207            }
2208    
2209            /**
2210             * Returns all the message-boards messages where groupId = &#63;.
2211             *
2212             * @param groupId the group ID
2213             * @return the matching message-boards messages
2214             * @throws SystemException if a system exception occurred
2215             */
2216            public List<MBMessage> findByGroupId(long groupId)
2217                    throws SystemException {
2218                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2219            }
2220    
2221            /**
2222             * Returns a range of all the message-boards messages where groupId = &#63;.
2223             *
2224             * <p>
2225             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2226             * </p>
2227             *
2228             * @param groupId the group ID
2229             * @param start the lower bound of the range of message-boards messages
2230             * @param end the upper bound of the range of message-boards messages (not inclusive)
2231             * @return the range of matching message-boards messages
2232             * @throws SystemException if a system exception occurred
2233             */
2234            public List<MBMessage> findByGroupId(long groupId, int start, int end)
2235                    throws SystemException {
2236                    return findByGroupId(groupId, start, end, null);
2237            }
2238    
2239            /**
2240             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
2241             *
2242             * <p>
2243             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2244             * </p>
2245             *
2246             * @param groupId the group ID
2247             * @param start the lower bound of the range of message-boards messages
2248             * @param end the upper bound of the range of message-boards messages (not inclusive)
2249             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2250             * @return the ordered range of matching message-boards messages
2251             * @throws SystemException if a system exception occurred
2252             */
2253            public List<MBMessage> findByGroupId(long groupId, int start, int end,
2254                    OrderByComparator orderByComparator) throws SystemException {
2255                    FinderPath finderPath = null;
2256                    Object[] finderArgs = null;
2257    
2258                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2259                                    (orderByComparator == null)) {
2260                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2261                            finderArgs = new Object[] { groupId };
2262                    }
2263                    else {
2264                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2265                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2266                    }
2267    
2268                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2269                                    finderArgs, this);
2270    
2271                    if ((list != null) && !list.isEmpty()) {
2272                            for (MBMessage mbMessage : list) {
2273                                    if ((groupId != mbMessage.getGroupId())) {
2274                                            list = null;
2275    
2276                                            break;
2277                                    }
2278                            }
2279                    }
2280    
2281                    if (list == null) {
2282                            StringBundler query = null;
2283    
2284                            if (orderByComparator != null) {
2285                                    query = new StringBundler(3 +
2286                                                    (orderByComparator.getOrderByFields().length * 3));
2287                            }
2288                            else {
2289                                    query = new StringBundler(3);
2290                            }
2291    
2292                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2293    
2294                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2295    
2296                            if (orderByComparator != null) {
2297                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2298                                            orderByComparator);
2299                            }
2300    
2301                            else {
2302                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2303                            }
2304    
2305                            String sql = query.toString();
2306    
2307                            Session session = null;
2308    
2309                            try {
2310                                    session = openSession();
2311    
2312                                    Query q = session.createQuery(sql);
2313    
2314                                    QueryPos qPos = QueryPos.getInstance(q);
2315    
2316                                    qPos.add(groupId);
2317    
2318                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2319                                                    end);
2320                            }
2321                            catch (Exception e) {
2322                                    throw processException(e);
2323                            }
2324                            finally {
2325                                    if (list == null) {
2326                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2327                                    }
2328                                    else {
2329                                            cacheResult(list);
2330    
2331                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2332                                    }
2333    
2334                                    closeSession(session);
2335                            }
2336                    }
2337    
2338                    return list;
2339            }
2340    
2341            /**
2342             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2343             *
2344             * @param groupId the group ID
2345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2346             * @return the first matching message-boards message
2347             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2348             * @throws SystemException if a system exception occurred
2349             */
2350            public MBMessage findByGroupId_First(long groupId,
2351                    OrderByComparator orderByComparator)
2352                    throws NoSuchMessageException, SystemException {
2353                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
2354    
2355                    if (mbMessage != null) {
2356                            return mbMessage;
2357                    }
2358    
2359                    StringBundler msg = new StringBundler(4);
2360    
2361                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2362    
2363                    msg.append("groupId=");
2364                    msg.append(groupId);
2365    
2366                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2367    
2368                    throw new NoSuchMessageException(msg.toString());
2369            }
2370    
2371            /**
2372             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2373             *
2374             * @param groupId the group ID
2375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2376             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2377             * @throws SystemException if a system exception occurred
2378             */
2379            public MBMessage fetchByGroupId_First(long groupId,
2380                    OrderByComparator orderByComparator) throws SystemException {
2381                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
2382    
2383                    if (!list.isEmpty()) {
2384                            return list.get(0);
2385                    }
2386    
2387                    return null;
2388            }
2389    
2390            /**
2391             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2392             *
2393             * @param groupId the group ID
2394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2395             * @return the last matching message-boards message
2396             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2397             * @throws SystemException if a system exception occurred
2398             */
2399            public MBMessage findByGroupId_Last(long groupId,
2400                    OrderByComparator orderByComparator)
2401                    throws NoSuchMessageException, SystemException {
2402                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
2403    
2404                    if (mbMessage != null) {
2405                            return mbMessage;
2406                    }
2407    
2408                    StringBundler msg = new StringBundler(4);
2409    
2410                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2411    
2412                    msg.append("groupId=");
2413                    msg.append(groupId);
2414    
2415                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2416    
2417                    throw new NoSuchMessageException(msg.toString());
2418            }
2419    
2420            /**
2421             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2422             *
2423             * @param groupId the group ID
2424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2425             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2426             * @throws SystemException if a system exception occurred
2427             */
2428            public MBMessage fetchByGroupId_Last(long groupId,
2429                    OrderByComparator orderByComparator) throws SystemException {
2430                    int count = countByGroupId(groupId);
2431    
2432                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
2433                                    orderByComparator);
2434    
2435                    if (!list.isEmpty()) {
2436                            return list.get(0);
2437                    }
2438    
2439                    return null;
2440            }
2441    
2442            /**
2443             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
2444             *
2445             * @param messageId the primary key of the current message-boards message
2446             * @param groupId the group ID
2447             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2448             * @return the previous, current, and next message-boards message
2449             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2450             * @throws SystemException if a system exception occurred
2451             */
2452            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
2453                    OrderByComparator orderByComparator)
2454                    throws NoSuchMessageException, SystemException {
2455                    MBMessage mbMessage = findByPrimaryKey(messageId);
2456    
2457                    Session session = null;
2458    
2459                    try {
2460                            session = openSession();
2461    
2462                            MBMessage[] array = new MBMessageImpl[3];
2463    
2464                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2465                                            orderByComparator, true);
2466    
2467                            array[1] = mbMessage;
2468    
2469                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2470                                            orderByComparator, false);
2471    
2472                            return array;
2473                    }
2474                    catch (Exception e) {
2475                            throw processException(e);
2476                    }
2477                    finally {
2478                            closeSession(session);
2479                    }
2480            }
2481    
2482            protected MBMessage getByGroupId_PrevAndNext(Session session,
2483                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2484                    boolean previous) {
2485                    StringBundler query = null;
2486    
2487                    if (orderByComparator != null) {
2488                            query = new StringBundler(6 +
2489                                            (orderByComparator.getOrderByFields().length * 6));
2490                    }
2491                    else {
2492                            query = new StringBundler(3);
2493                    }
2494    
2495                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2496    
2497                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2498    
2499                    if (orderByComparator != null) {
2500                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2501    
2502                            if (orderByConditionFields.length > 0) {
2503                                    query.append(WHERE_AND);
2504                            }
2505    
2506                            for (int i = 0; i < orderByConditionFields.length; i++) {
2507                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2508                                    query.append(orderByConditionFields[i]);
2509    
2510                                    if ((i + 1) < orderByConditionFields.length) {
2511                                            if (orderByComparator.isAscending() ^ previous) {
2512                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2513                                            }
2514                                            else {
2515                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2516                                            }
2517                                    }
2518                                    else {
2519                                            if (orderByComparator.isAscending() ^ previous) {
2520                                                    query.append(WHERE_GREATER_THAN);
2521                                            }
2522                                            else {
2523                                                    query.append(WHERE_LESSER_THAN);
2524                                            }
2525                                    }
2526                            }
2527    
2528                            query.append(ORDER_BY_CLAUSE);
2529    
2530                            String[] orderByFields = orderByComparator.getOrderByFields();
2531    
2532                            for (int i = 0; i < orderByFields.length; i++) {
2533                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2534                                    query.append(orderByFields[i]);
2535    
2536                                    if ((i + 1) < orderByFields.length) {
2537                                            if (orderByComparator.isAscending() ^ previous) {
2538                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2539                                            }
2540                                            else {
2541                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2542                                            }
2543                                    }
2544                                    else {
2545                                            if (orderByComparator.isAscending() ^ previous) {
2546                                                    query.append(ORDER_BY_ASC);
2547                                            }
2548                                            else {
2549                                                    query.append(ORDER_BY_DESC);
2550                                            }
2551                                    }
2552                            }
2553                    }
2554    
2555                    else {
2556                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2557                    }
2558    
2559                    String sql = query.toString();
2560    
2561                    Query q = session.createQuery(sql);
2562    
2563                    q.setFirstResult(0);
2564                    q.setMaxResults(2);
2565    
2566                    QueryPos qPos = QueryPos.getInstance(q);
2567    
2568                    qPos.add(groupId);
2569    
2570                    if (orderByComparator != null) {
2571                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2572    
2573                            for (Object value : values) {
2574                                    qPos.add(value);
2575                            }
2576                    }
2577    
2578                    List<MBMessage> list = q.list();
2579    
2580                    if (list.size() == 2) {
2581                            return list.get(1);
2582                    }
2583                    else {
2584                            return null;
2585                    }
2586            }
2587    
2588            /**
2589             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
2590             *
2591             * @param groupId the group ID
2592             * @return the matching message-boards messages that the user has permission to view
2593             * @throws SystemException if a system exception occurred
2594             */
2595            public List<MBMessage> filterFindByGroupId(long groupId)
2596                    throws SystemException {
2597                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2598                            QueryUtil.ALL_POS, null);
2599            }
2600    
2601            /**
2602             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
2603             *
2604             * <p>
2605             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2606             * </p>
2607             *
2608             * @param groupId the group ID
2609             * @param start the lower bound of the range of message-boards messages
2610             * @param end the upper bound of the range of message-boards messages (not inclusive)
2611             * @return the range of matching message-boards messages that the user has permission to view
2612             * @throws SystemException if a system exception occurred
2613             */
2614            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
2615                    throws SystemException {
2616                    return filterFindByGroupId(groupId, start, end, null);
2617            }
2618    
2619            /**
2620             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
2621             *
2622             * <p>
2623             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2624             * </p>
2625             *
2626             * @param groupId the group ID
2627             * @param start the lower bound of the range of message-boards messages
2628             * @param end the upper bound of the range of message-boards messages (not inclusive)
2629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2630             * @return the ordered range of matching message-boards messages that the user has permission to view
2631             * @throws SystemException if a system exception occurred
2632             */
2633            public List<MBMessage> filterFindByGroupId(long groupId, int start,
2634                    int end, OrderByComparator orderByComparator) throws SystemException {
2635                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2636                            return findByGroupId(groupId, start, end, orderByComparator);
2637                    }
2638    
2639                    StringBundler query = null;
2640    
2641                    if (orderByComparator != null) {
2642                            query = new StringBundler(3 +
2643                                            (orderByComparator.getOrderByFields().length * 3));
2644                    }
2645                    else {
2646                            query = new StringBundler(3);
2647                    }
2648    
2649                    if (getDB().isSupportsInlineDistinct()) {
2650                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2651                    }
2652                    else {
2653                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2654                    }
2655    
2656                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2657    
2658                    if (!getDB().isSupportsInlineDistinct()) {
2659                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2660                    }
2661    
2662                    if (orderByComparator != null) {
2663                            if (getDB().isSupportsInlineDistinct()) {
2664                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2665                                            orderByComparator);
2666                            }
2667                            else {
2668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2669                                            orderByComparator);
2670                            }
2671                    }
2672    
2673                    else {
2674                            if (getDB().isSupportsInlineDistinct()) {
2675                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2676                            }
2677                            else {
2678                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2679                            }
2680                    }
2681    
2682                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2683                                    MBMessage.class.getName(),
2684                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2685    
2686                    Session session = null;
2687    
2688                    try {
2689                            session = openSession();
2690    
2691                            SQLQuery q = session.createSQLQuery(sql);
2692    
2693                            if (getDB().isSupportsInlineDistinct()) {
2694                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2695                            }
2696                            else {
2697                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2698                            }
2699    
2700                            QueryPos qPos = QueryPos.getInstance(q);
2701    
2702                            qPos.add(groupId);
2703    
2704                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2705                    }
2706                    catch (Exception e) {
2707                            throw processException(e);
2708                    }
2709                    finally {
2710                            closeSession(session);
2711                    }
2712            }
2713    
2714            /**
2715             * 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;.
2716             *
2717             * @param messageId the primary key of the current message-boards message
2718             * @param groupId the group ID
2719             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2720             * @return the previous, current, and next message-boards message
2721             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2722             * @throws SystemException if a system exception occurred
2723             */
2724            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2725                    long groupId, OrderByComparator orderByComparator)
2726                    throws NoSuchMessageException, SystemException {
2727                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2728                            return findByGroupId_PrevAndNext(messageId, groupId,
2729                                    orderByComparator);
2730                    }
2731    
2732                    MBMessage mbMessage = findByPrimaryKey(messageId);
2733    
2734                    Session session = null;
2735    
2736                    try {
2737                            session = openSession();
2738    
2739                            MBMessage[] array = new MBMessageImpl[3];
2740    
2741                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2742                                            groupId, orderByComparator, true);
2743    
2744                            array[1] = mbMessage;
2745    
2746                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2747                                            groupId, orderByComparator, false);
2748    
2749                            return array;
2750                    }
2751                    catch (Exception e) {
2752                            throw processException(e);
2753                    }
2754                    finally {
2755                            closeSession(session);
2756                    }
2757            }
2758    
2759            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2760                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2761                    boolean previous) {
2762                    StringBundler query = null;
2763    
2764                    if (orderByComparator != null) {
2765                            query = new StringBundler(6 +
2766                                            (orderByComparator.getOrderByFields().length * 6));
2767                    }
2768                    else {
2769                            query = new StringBundler(3);
2770                    }
2771    
2772                    if (getDB().isSupportsInlineDistinct()) {
2773                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2774                    }
2775                    else {
2776                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2777                    }
2778    
2779                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2780    
2781                    if (!getDB().isSupportsInlineDistinct()) {
2782                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2783                    }
2784    
2785                    if (orderByComparator != null) {
2786                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2787    
2788                            if (orderByConditionFields.length > 0) {
2789                                    query.append(WHERE_AND);
2790                            }
2791    
2792                            for (int i = 0; i < orderByConditionFields.length; i++) {
2793                                    if (getDB().isSupportsInlineDistinct()) {
2794                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2795                                    }
2796                                    else {
2797                                            query.append(_ORDER_BY_ENTITY_TABLE);
2798                                    }
2799    
2800                                    query.append(orderByConditionFields[i]);
2801    
2802                                    if ((i + 1) < orderByConditionFields.length) {
2803                                            if (orderByComparator.isAscending() ^ previous) {
2804                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2805                                            }
2806                                            else {
2807                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2808                                            }
2809                                    }
2810                                    else {
2811                                            if (orderByComparator.isAscending() ^ previous) {
2812                                                    query.append(WHERE_GREATER_THAN);
2813                                            }
2814                                            else {
2815                                                    query.append(WHERE_LESSER_THAN);
2816                                            }
2817                                    }
2818                            }
2819    
2820                            query.append(ORDER_BY_CLAUSE);
2821    
2822                            String[] orderByFields = orderByComparator.getOrderByFields();
2823    
2824                            for (int i = 0; i < orderByFields.length; i++) {
2825                                    if (getDB().isSupportsInlineDistinct()) {
2826                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2827                                    }
2828                                    else {
2829                                            query.append(_ORDER_BY_ENTITY_TABLE);
2830                                    }
2831    
2832                                    query.append(orderByFields[i]);
2833    
2834                                    if ((i + 1) < orderByFields.length) {
2835                                            if (orderByComparator.isAscending() ^ previous) {
2836                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2837                                            }
2838                                            else {
2839                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2840                                            }
2841                                    }
2842                                    else {
2843                                            if (orderByComparator.isAscending() ^ previous) {
2844                                                    query.append(ORDER_BY_ASC);
2845                                            }
2846                                            else {
2847                                                    query.append(ORDER_BY_DESC);
2848                                            }
2849                                    }
2850                            }
2851                    }
2852    
2853                    else {
2854                            if (getDB().isSupportsInlineDistinct()) {
2855                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2856                            }
2857                            else {
2858                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2859                            }
2860                    }
2861    
2862                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2863                                    MBMessage.class.getName(),
2864                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2865    
2866                    SQLQuery q = session.createSQLQuery(sql);
2867    
2868                    q.setFirstResult(0);
2869                    q.setMaxResults(2);
2870    
2871                    if (getDB().isSupportsInlineDistinct()) {
2872                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2873                    }
2874                    else {
2875                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2876                    }
2877    
2878                    QueryPos qPos = QueryPos.getInstance(q);
2879    
2880                    qPos.add(groupId);
2881    
2882                    if (orderByComparator != null) {
2883                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2884    
2885                            for (Object value : values) {
2886                                    qPos.add(value);
2887                            }
2888                    }
2889    
2890                    List<MBMessage> list = q.list();
2891    
2892                    if (list.size() == 2) {
2893                            return list.get(1);
2894                    }
2895                    else {
2896                            return null;
2897                    }
2898            }
2899    
2900            /**
2901             * Returns all the message-boards messages where companyId = &#63;.
2902             *
2903             * @param companyId the company ID
2904             * @return the matching message-boards messages
2905             * @throws SystemException if a system exception occurred
2906             */
2907            public List<MBMessage> findByCompanyId(long companyId)
2908                    throws SystemException {
2909                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2910                            null);
2911            }
2912    
2913            /**
2914             * Returns a range of all the message-boards messages where companyId = &#63;.
2915             *
2916             * <p>
2917             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2918             * </p>
2919             *
2920             * @param companyId the company ID
2921             * @param start the lower bound of the range of message-boards messages
2922             * @param end the upper bound of the range of message-boards messages (not inclusive)
2923             * @return the range of matching message-boards messages
2924             * @throws SystemException if a system exception occurred
2925             */
2926            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2927                    throws SystemException {
2928                    return findByCompanyId(companyId, start, end, null);
2929            }
2930    
2931            /**
2932             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2933             *
2934             * <p>
2935             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2936             * </p>
2937             *
2938             * @param companyId the company ID
2939             * @param start the lower bound of the range of message-boards messages
2940             * @param end the upper bound of the range of message-boards messages (not inclusive)
2941             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2942             * @return the ordered range of matching message-boards messages
2943             * @throws SystemException if a system exception occurred
2944             */
2945            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2946                    OrderByComparator orderByComparator) throws SystemException {
2947                    FinderPath finderPath = null;
2948                    Object[] finderArgs = null;
2949    
2950                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2951                                    (orderByComparator == null)) {
2952                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2953                            finderArgs = new Object[] { companyId };
2954                    }
2955                    else {
2956                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2957                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2958                    }
2959    
2960                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2961                                    finderArgs, this);
2962    
2963                    if ((list != null) && !list.isEmpty()) {
2964                            for (MBMessage mbMessage : list) {
2965                                    if ((companyId != mbMessage.getCompanyId())) {
2966                                            list = null;
2967    
2968                                            break;
2969                                    }
2970                            }
2971                    }
2972    
2973                    if (list == null) {
2974                            StringBundler query = null;
2975    
2976                            if (orderByComparator != null) {
2977                                    query = new StringBundler(3 +
2978                                                    (orderByComparator.getOrderByFields().length * 3));
2979                            }
2980                            else {
2981                                    query = new StringBundler(3);
2982                            }
2983    
2984                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2985    
2986                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2987    
2988                            if (orderByComparator != null) {
2989                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2990                                            orderByComparator);
2991                            }
2992    
2993                            else {
2994                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2995                            }
2996    
2997                            String sql = query.toString();
2998    
2999                            Session session = null;
3000    
3001                            try {
3002                                    session = openSession();
3003    
3004                                    Query q = session.createQuery(sql);
3005    
3006                                    QueryPos qPos = QueryPos.getInstance(q);
3007    
3008                                    qPos.add(companyId);
3009    
3010                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3011                                                    end);
3012                            }
3013                            catch (Exception e) {
3014                                    throw processException(e);
3015                            }
3016                            finally {
3017                                    if (list == null) {
3018                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3019                                    }
3020                                    else {
3021                                            cacheResult(list);
3022    
3023                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3024                                    }
3025    
3026                                    closeSession(session);
3027                            }
3028                    }
3029    
3030                    return list;
3031            }
3032    
3033            /**
3034             * Returns the first message-boards message in the ordered set where companyId = &#63;.
3035             *
3036             * @param companyId the company ID
3037             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3038             * @return the first matching message-boards message
3039             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3040             * @throws SystemException if a system exception occurred
3041             */
3042            public MBMessage findByCompanyId_First(long companyId,
3043                    OrderByComparator orderByComparator)
3044                    throws NoSuchMessageException, SystemException {
3045                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
3046                                    orderByComparator);
3047    
3048                    if (mbMessage != null) {
3049                            return mbMessage;
3050                    }
3051    
3052                    StringBundler msg = new StringBundler(4);
3053    
3054                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3055    
3056                    msg.append("companyId=");
3057                    msg.append(companyId);
3058    
3059                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3060    
3061                    throw new NoSuchMessageException(msg.toString());
3062            }
3063    
3064            /**
3065             * Returns the first message-boards message in the ordered set where companyId = &#63;.
3066             *
3067             * @param companyId the company ID
3068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3069             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3070             * @throws SystemException if a system exception occurred
3071             */
3072            public MBMessage fetchByCompanyId_First(long companyId,
3073                    OrderByComparator orderByComparator) throws SystemException {
3074                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
3075                                    orderByComparator);
3076    
3077                    if (!list.isEmpty()) {
3078                            return list.get(0);
3079                    }
3080    
3081                    return null;
3082            }
3083    
3084            /**
3085             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3086             *
3087             * @param companyId the company ID
3088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3089             * @return the last matching message-boards message
3090             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3091             * @throws SystemException if a system exception occurred
3092             */
3093            public MBMessage findByCompanyId_Last(long companyId,
3094                    OrderByComparator orderByComparator)
3095                    throws NoSuchMessageException, SystemException {
3096                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
3097    
3098                    if (mbMessage != null) {
3099                            return mbMessage;
3100                    }
3101    
3102                    StringBundler msg = new StringBundler(4);
3103    
3104                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3105    
3106                    msg.append("companyId=");
3107                    msg.append(companyId);
3108    
3109                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3110    
3111                    throw new NoSuchMessageException(msg.toString());
3112            }
3113    
3114            /**
3115             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3116             *
3117             * @param companyId the company ID
3118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3119             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3120             * @throws SystemException if a system exception occurred
3121             */
3122            public MBMessage fetchByCompanyId_Last(long companyId,
3123                    OrderByComparator orderByComparator) throws SystemException {
3124                    int count = countByCompanyId(companyId);
3125    
3126                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
3127                                    orderByComparator);
3128    
3129                    if (!list.isEmpty()) {
3130                            return list.get(0);
3131                    }
3132    
3133                    return null;
3134            }
3135    
3136            /**
3137             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
3138             *
3139             * @param messageId the primary key of the current message-boards message
3140             * @param companyId the company ID
3141             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3142             * @return the previous, current, and next message-boards message
3143             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3144             * @throws SystemException if a system exception occurred
3145             */
3146            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
3147                    long companyId, OrderByComparator orderByComparator)
3148                    throws NoSuchMessageException, SystemException {
3149                    MBMessage mbMessage = findByPrimaryKey(messageId);
3150    
3151                    Session session = null;
3152    
3153                    try {
3154                            session = openSession();
3155    
3156                            MBMessage[] array = new MBMessageImpl[3];
3157    
3158                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
3159                                            companyId, orderByComparator, true);
3160    
3161                            array[1] = mbMessage;
3162    
3163                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
3164                                            companyId, orderByComparator, false);
3165    
3166                            return array;
3167                    }
3168                    catch (Exception e) {
3169                            throw processException(e);
3170                    }
3171                    finally {
3172                            closeSession(session);
3173                    }
3174            }
3175    
3176            protected MBMessage getByCompanyId_PrevAndNext(Session session,
3177                    MBMessage mbMessage, long companyId,
3178                    OrderByComparator orderByComparator, boolean previous) {
3179                    StringBundler query = null;
3180    
3181                    if (orderByComparator != null) {
3182                            query = new StringBundler(6 +
3183                                            (orderByComparator.getOrderByFields().length * 6));
3184                    }
3185                    else {
3186                            query = new StringBundler(3);
3187                    }
3188    
3189                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3190    
3191                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3192    
3193                    if (orderByComparator != null) {
3194                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3195    
3196                            if (orderByConditionFields.length > 0) {
3197                                    query.append(WHERE_AND);
3198                            }
3199    
3200                            for (int i = 0; i < orderByConditionFields.length; i++) {
3201                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3202                                    query.append(orderByConditionFields[i]);
3203    
3204                                    if ((i + 1) < orderByConditionFields.length) {
3205                                            if (orderByComparator.isAscending() ^ previous) {
3206                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3207                                            }
3208                                            else {
3209                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3210                                            }
3211                                    }
3212                                    else {
3213                                            if (orderByComparator.isAscending() ^ previous) {
3214                                                    query.append(WHERE_GREATER_THAN);
3215                                            }
3216                                            else {
3217                                                    query.append(WHERE_LESSER_THAN);
3218                                            }
3219                                    }
3220                            }
3221    
3222                            query.append(ORDER_BY_CLAUSE);
3223    
3224                            String[] orderByFields = orderByComparator.getOrderByFields();
3225    
3226                            for (int i = 0; i < orderByFields.length; i++) {
3227                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3228                                    query.append(orderByFields[i]);
3229    
3230                                    if ((i + 1) < orderByFields.length) {
3231                                            if (orderByComparator.isAscending() ^ previous) {
3232                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3233                                            }
3234                                            else {
3235                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3236                                            }
3237                                    }
3238                                    else {
3239                                            if (orderByComparator.isAscending() ^ previous) {
3240                                                    query.append(ORDER_BY_ASC);
3241                                            }
3242                                            else {
3243                                                    query.append(ORDER_BY_DESC);
3244                                            }
3245                                    }
3246                            }
3247                    }
3248    
3249                    else {
3250                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3251                    }
3252    
3253                    String sql = query.toString();
3254    
3255                    Query q = session.createQuery(sql);
3256    
3257                    q.setFirstResult(0);
3258                    q.setMaxResults(2);
3259    
3260                    QueryPos qPos = QueryPos.getInstance(q);
3261    
3262                    qPos.add(companyId);
3263    
3264                    if (orderByComparator != null) {
3265                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3266    
3267                            for (Object value : values) {
3268                                    qPos.add(value);
3269                            }
3270                    }
3271    
3272                    List<MBMessage> list = q.list();
3273    
3274                    if (list.size() == 2) {
3275                            return list.get(1);
3276                    }
3277                    else {
3278                            return null;
3279                    }
3280            }
3281    
3282            /**
3283             * Returns all the message-boards messages where threadId = &#63;.
3284             *
3285             * @param threadId the thread ID
3286             * @return the matching message-boards messages
3287             * @throws SystemException if a system exception occurred
3288             */
3289            public List<MBMessage> findByThreadId(long threadId)
3290                    throws SystemException {
3291                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3292                            null);
3293            }
3294    
3295            /**
3296             * Returns a range of all the message-boards messages where threadId = &#63;.
3297             *
3298             * <p>
3299             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3300             * </p>
3301             *
3302             * @param threadId the thread ID
3303             * @param start the lower bound of the range of message-boards messages
3304             * @param end the upper bound of the range of message-boards messages (not inclusive)
3305             * @return the range of matching message-boards messages
3306             * @throws SystemException if a system exception occurred
3307             */
3308            public List<MBMessage> findByThreadId(long threadId, int start, int end)
3309                    throws SystemException {
3310                    return findByThreadId(threadId, start, end, null);
3311            }
3312    
3313            /**
3314             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3315             *
3316             * <p>
3317             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3318             * </p>
3319             *
3320             * @param threadId the thread ID
3321             * @param start the lower bound of the range of message-boards messages
3322             * @param end the upper bound of the range of message-boards messages (not inclusive)
3323             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3324             * @return the ordered range of matching message-boards messages
3325             * @throws SystemException if a system exception occurred
3326             */
3327            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3328                    OrderByComparator orderByComparator) throws SystemException {
3329                    FinderPath finderPath = null;
3330                    Object[] finderArgs = null;
3331    
3332                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3333                                    (orderByComparator == null)) {
3334                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3335                            finderArgs = new Object[] { threadId };
3336                    }
3337                    else {
3338                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3339                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3340                    }
3341    
3342                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3343                                    finderArgs, this);
3344    
3345                    if ((list != null) && !list.isEmpty()) {
3346                            for (MBMessage mbMessage : list) {
3347                                    if ((threadId != mbMessage.getThreadId())) {
3348                                            list = null;
3349    
3350                                            break;
3351                                    }
3352                            }
3353                    }
3354    
3355                    if (list == null) {
3356                            StringBundler query = null;
3357    
3358                            if (orderByComparator != null) {
3359                                    query = new StringBundler(3 +
3360                                                    (orderByComparator.getOrderByFields().length * 3));
3361                            }
3362                            else {
3363                                    query = new StringBundler(3);
3364                            }
3365    
3366                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3367    
3368                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3369    
3370                            if (orderByComparator != null) {
3371                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3372                                            orderByComparator);
3373                            }
3374    
3375                            else {
3376                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3377                            }
3378    
3379                            String sql = query.toString();
3380    
3381                            Session session = null;
3382    
3383                            try {
3384                                    session = openSession();
3385    
3386                                    Query q = session.createQuery(sql);
3387    
3388                                    QueryPos qPos = QueryPos.getInstance(q);
3389    
3390                                    qPos.add(threadId);
3391    
3392                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3393                                                    end);
3394                            }
3395                            catch (Exception e) {
3396                                    throw processException(e);
3397                            }
3398                            finally {
3399                                    if (list == null) {
3400                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3401                                    }
3402                                    else {
3403                                            cacheResult(list);
3404    
3405                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3406                                    }
3407    
3408                                    closeSession(session);
3409                            }
3410                    }
3411    
3412                    return list;
3413            }
3414    
3415            /**
3416             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3417             *
3418             * @param threadId the thread ID
3419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3420             * @return the first matching message-boards message
3421             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3422             * @throws SystemException if a system exception occurred
3423             */
3424            public MBMessage findByThreadId_First(long threadId,
3425                    OrderByComparator orderByComparator)
3426                    throws NoSuchMessageException, SystemException {
3427                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3428    
3429                    if (mbMessage != null) {
3430                            return mbMessage;
3431                    }
3432    
3433                    StringBundler msg = new StringBundler(4);
3434    
3435                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3436    
3437                    msg.append("threadId=");
3438                    msg.append(threadId);
3439    
3440                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3441    
3442                    throw new NoSuchMessageException(msg.toString());
3443            }
3444    
3445            /**
3446             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3447             *
3448             * @param threadId the thread ID
3449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3450             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3451             * @throws SystemException if a system exception occurred
3452             */
3453            public MBMessage fetchByThreadId_First(long threadId,
3454                    OrderByComparator orderByComparator) throws SystemException {
3455                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3456    
3457                    if (!list.isEmpty()) {
3458                            return list.get(0);
3459                    }
3460    
3461                    return null;
3462            }
3463    
3464            /**
3465             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3466             *
3467             * @param threadId the thread ID
3468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3469             * @return the last matching message-boards message
3470             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3471             * @throws SystemException if a system exception occurred
3472             */
3473            public MBMessage findByThreadId_Last(long threadId,
3474                    OrderByComparator orderByComparator)
3475                    throws NoSuchMessageException, SystemException {
3476                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3477    
3478                    if (mbMessage != null) {
3479                            return mbMessage;
3480                    }
3481    
3482                    StringBundler msg = new StringBundler(4);
3483    
3484                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3485    
3486                    msg.append("threadId=");
3487                    msg.append(threadId);
3488    
3489                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3490    
3491                    throw new NoSuchMessageException(msg.toString());
3492            }
3493    
3494            /**
3495             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3496             *
3497             * @param threadId the thread ID
3498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3499             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3500             * @throws SystemException if a system exception occurred
3501             */
3502            public MBMessage fetchByThreadId_Last(long threadId,
3503                    OrderByComparator orderByComparator) throws SystemException {
3504                    int count = countByThreadId(threadId);
3505    
3506                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3507                                    orderByComparator);
3508    
3509                    if (!list.isEmpty()) {
3510                            return list.get(0);
3511                    }
3512    
3513                    return null;
3514            }
3515    
3516            /**
3517             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3518             *
3519             * @param messageId the primary key of the current message-boards message
3520             * @param threadId the thread ID
3521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3522             * @return the previous, current, and next message-boards message
3523             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3524             * @throws SystemException if a system exception occurred
3525             */
3526            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3527                    long threadId, OrderByComparator orderByComparator)
3528                    throws NoSuchMessageException, SystemException {
3529                    MBMessage mbMessage = findByPrimaryKey(messageId);
3530    
3531                    Session session = null;
3532    
3533                    try {
3534                            session = openSession();
3535    
3536                            MBMessage[] array = new MBMessageImpl[3];
3537    
3538                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3539                                            orderByComparator, true);
3540    
3541                            array[1] = mbMessage;
3542    
3543                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3544                                            orderByComparator, false);
3545    
3546                            return array;
3547                    }
3548                    catch (Exception e) {
3549                            throw processException(e);
3550                    }
3551                    finally {
3552                            closeSession(session);
3553                    }
3554            }
3555    
3556            protected MBMessage getByThreadId_PrevAndNext(Session session,
3557                    MBMessage mbMessage, long threadId,
3558                    OrderByComparator orderByComparator, boolean previous) {
3559                    StringBundler query = null;
3560    
3561                    if (orderByComparator != null) {
3562                            query = new StringBundler(6 +
3563                                            (orderByComparator.getOrderByFields().length * 6));
3564                    }
3565                    else {
3566                            query = new StringBundler(3);
3567                    }
3568    
3569                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3570    
3571                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3572    
3573                    if (orderByComparator != null) {
3574                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3575    
3576                            if (orderByConditionFields.length > 0) {
3577                                    query.append(WHERE_AND);
3578                            }
3579    
3580                            for (int i = 0; i < orderByConditionFields.length; i++) {
3581                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3582                                    query.append(orderByConditionFields[i]);
3583    
3584                                    if ((i + 1) < orderByConditionFields.length) {
3585                                            if (orderByComparator.isAscending() ^ previous) {
3586                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3587                                            }
3588                                            else {
3589                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3590                                            }
3591                                    }
3592                                    else {
3593                                            if (orderByComparator.isAscending() ^ previous) {
3594                                                    query.append(WHERE_GREATER_THAN);
3595                                            }
3596                                            else {
3597                                                    query.append(WHERE_LESSER_THAN);
3598                                            }
3599                                    }
3600                            }
3601    
3602                            query.append(ORDER_BY_CLAUSE);
3603    
3604                            String[] orderByFields = orderByComparator.getOrderByFields();
3605    
3606                            for (int i = 0; i < orderByFields.length; i++) {
3607                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3608                                    query.append(orderByFields[i]);
3609    
3610                                    if ((i + 1) < orderByFields.length) {
3611                                            if (orderByComparator.isAscending() ^ previous) {
3612                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3613                                            }
3614                                            else {
3615                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3616                                            }
3617                                    }
3618                                    else {
3619                                            if (orderByComparator.isAscending() ^ previous) {
3620                                                    query.append(ORDER_BY_ASC);
3621                                            }
3622                                            else {
3623                                                    query.append(ORDER_BY_DESC);
3624                                            }
3625                                    }
3626                            }
3627                    }
3628    
3629                    else {
3630                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3631                    }
3632    
3633                    String sql = query.toString();
3634    
3635                    Query q = session.createQuery(sql);
3636    
3637                    q.setFirstResult(0);
3638                    q.setMaxResults(2);
3639    
3640                    QueryPos qPos = QueryPos.getInstance(q);
3641    
3642                    qPos.add(threadId);
3643    
3644                    if (orderByComparator != null) {
3645                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3646    
3647                            for (Object value : values) {
3648                                    qPos.add(value);
3649                            }
3650                    }
3651    
3652                    List<MBMessage> list = q.list();
3653    
3654                    if (list.size() == 2) {
3655                            return list.get(1);
3656                    }
3657                    else {
3658                            return null;
3659                    }
3660            }
3661    
3662            /**
3663             * Returns all the message-boards messages where threadId = &#63;.
3664             *
3665             * @param threadId the thread ID
3666             * @return the matching message-boards messages
3667             * @throws SystemException if a system exception occurred
3668             */
3669            public List<MBMessage> findByThreadReplies(long threadId)
3670                    throws SystemException {
3671                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3672                            QueryUtil.ALL_POS, null);
3673            }
3674    
3675            /**
3676             * Returns a range of all the message-boards messages where threadId = &#63;.
3677             *
3678             * <p>
3679             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3680             * </p>
3681             *
3682             * @param threadId the thread ID
3683             * @param start the lower bound of the range of message-boards messages
3684             * @param end the upper bound of the range of message-boards messages (not inclusive)
3685             * @return the range of matching message-boards messages
3686             * @throws SystemException if a system exception occurred
3687             */
3688            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3689                    throws SystemException {
3690                    return findByThreadReplies(threadId, start, end, null);
3691            }
3692    
3693            /**
3694             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3695             *
3696             * <p>
3697             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3698             * </p>
3699             *
3700             * @param threadId the thread ID
3701             * @param start the lower bound of the range of message-boards messages
3702             * @param end the upper bound of the range of message-boards messages (not inclusive)
3703             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3704             * @return the ordered range of matching message-boards messages
3705             * @throws SystemException if a system exception occurred
3706             */
3707            public List<MBMessage> findByThreadReplies(long threadId, int start,
3708                    int end, OrderByComparator orderByComparator) throws SystemException {
3709                    FinderPath finderPath = null;
3710                    Object[] finderArgs = null;
3711    
3712                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3713                                    (orderByComparator == null)) {
3714                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3715                            finderArgs = new Object[] { threadId };
3716                    }
3717                    else {
3718                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3719                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3720                    }
3721    
3722                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3723                                    finderArgs, this);
3724    
3725                    if ((list != null) && !list.isEmpty()) {
3726                            for (MBMessage mbMessage : list) {
3727                                    if ((threadId != mbMessage.getThreadId())) {
3728                                            list = null;
3729    
3730                                            break;
3731                                    }
3732                            }
3733                    }
3734    
3735                    if (list == null) {
3736                            StringBundler query = null;
3737    
3738                            if (orderByComparator != null) {
3739                                    query = new StringBundler(3 +
3740                                                    (orderByComparator.getOrderByFields().length * 3));
3741                            }
3742                            else {
3743                                    query = new StringBundler(3);
3744                            }
3745    
3746                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3747    
3748                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3749    
3750                            if (orderByComparator != null) {
3751                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3752                                            orderByComparator);
3753                            }
3754    
3755                            else {
3756                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3757                            }
3758    
3759                            String sql = query.toString();
3760    
3761                            Session session = null;
3762    
3763                            try {
3764                                    session = openSession();
3765    
3766                                    Query q = session.createQuery(sql);
3767    
3768                                    QueryPos qPos = QueryPos.getInstance(q);
3769    
3770                                    qPos.add(threadId);
3771    
3772                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3773                                                    end);
3774                            }
3775                            catch (Exception e) {
3776                                    throw processException(e);
3777                            }
3778                            finally {
3779                                    if (list == null) {
3780                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3781                                    }
3782                                    else {
3783                                            cacheResult(list);
3784    
3785                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3786                                    }
3787    
3788                                    closeSession(session);
3789                            }
3790                    }
3791    
3792                    return list;
3793            }
3794    
3795            /**
3796             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3797             *
3798             * @param threadId the thread ID
3799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3800             * @return the first matching message-boards message
3801             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3802             * @throws SystemException if a system exception occurred
3803             */
3804            public MBMessage findByThreadReplies_First(long threadId,
3805                    OrderByComparator orderByComparator)
3806                    throws NoSuchMessageException, SystemException {
3807                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3808                                    orderByComparator);
3809    
3810                    if (mbMessage != null) {
3811                            return mbMessage;
3812                    }
3813    
3814                    StringBundler msg = new StringBundler(4);
3815    
3816                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3817    
3818                    msg.append("threadId=");
3819                    msg.append(threadId);
3820    
3821                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3822    
3823                    throw new NoSuchMessageException(msg.toString());
3824            }
3825    
3826            /**
3827             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3828             *
3829             * @param threadId the thread ID
3830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3831             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3832             * @throws SystemException if a system exception occurred
3833             */
3834            public MBMessage fetchByThreadReplies_First(long threadId,
3835                    OrderByComparator orderByComparator) throws SystemException {
3836                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3837                                    orderByComparator);
3838    
3839                    if (!list.isEmpty()) {
3840                            return list.get(0);
3841                    }
3842    
3843                    return null;
3844            }
3845    
3846            /**
3847             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3848             *
3849             * @param threadId the thread ID
3850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3851             * @return the last matching message-boards message
3852             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3853             * @throws SystemException if a system exception occurred
3854             */
3855            public MBMessage findByThreadReplies_Last(long threadId,
3856                    OrderByComparator orderByComparator)
3857                    throws NoSuchMessageException, SystemException {
3858                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3859                                    orderByComparator);
3860    
3861                    if (mbMessage != null) {
3862                            return mbMessage;
3863                    }
3864    
3865                    StringBundler msg = new StringBundler(4);
3866    
3867                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3868    
3869                    msg.append("threadId=");
3870                    msg.append(threadId);
3871    
3872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3873    
3874                    throw new NoSuchMessageException(msg.toString());
3875            }
3876    
3877            /**
3878             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3879             *
3880             * @param threadId the thread ID
3881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3882             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3883             * @throws SystemException if a system exception occurred
3884             */
3885            public MBMessage fetchByThreadReplies_Last(long threadId,
3886                    OrderByComparator orderByComparator) throws SystemException {
3887                    int count = countByThreadReplies(threadId);
3888    
3889                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3890                                    orderByComparator);
3891    
3892                    if (!list.isEmpty()) {
3893                            return list.get(0);
3894                    }
3895    
3896                    return null;
3897            }
3898    
3899            /**
3900             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3901             *
3902             * @param messageId the primary key of the current message-boards message
3903             * @param threadId the thread ID
3904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3905             * @return the previous, current, and next message-boards message
3906             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3907             * @throws SystemException if a system exception occurred
3908             */
3909            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3910                    long threadId, OrderByComparator orderByComparator)
3911                    throws NoSuchMessageException, SystemException {
3912                    MBMessage mbMessage = findByPrimaryKey(messageId);
3913    
3914                    Session session = null;
3915    
3916                    try {
3917                            session = openSession();
3918    
3919                            MBMessage[] array = new MBMessageImpl[3];
3920    
3921                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3922                                            threadId, orderByComparator, true);
3923    
3924                            array[1] = mbMessage;
3925    
3926                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3927                                            threadId, orderByComparator, false);
3928    
3929                            return array;
3930                    }
3931                    catch (Exception e) {
3932                            throw processException(e);
3933                    }
3934                    finally {
3935                            closeSession(session);
3936                    }
3937            }
3938    
3939            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3940                    MBMessage mbMessage, long threadId,
3941                    OrderByComparator orderByComparator, boolean previous) {
3942                    StringBundler query = null;
3943    
3944                    if (orderByComparator != null) {
3945                            query = new StringBundler(6 +
3946                                            (orderByComparator.getOrderByFields().length * 6));
3947                    }
3948                    else {
3949                            query = new StringBundler(3);
3950                    }
3951    
3952                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3953    
3954                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3955    
3956                    if (orderByComparator != null) {
3957                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3958    
3959                            if (orderByConditionFields.length > 0) {
3960                                    query.append(WHERE_AND);
3961                            }
3962    
3963                            for (int i = 0; i < orderByConditionFields.length; i++) {
3964                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3965                                    query.append(orderByConditionFields[i]);
3966    
3967                                    if ((i + 1) < orderByConditionFields.length) {
3968                                            if (orderByComparator.isAscending() ^ previous) {
3969                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3970                                            }
3971                                            else {
3972                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3973                                            }
3974                                    }
3975                                    else {
3976                                            if (orderByComparator.isAscending() ^ previous) {
3977                                                    query.append(WHERE_GREATER_THAN);
3978                                            }
3979                                            else {
3980                                                    query.append(WHERE_LESSER_THAN);
3981                                            }
3982                                    }
3983                            }
3984    
3985                            query.append(ORDER_BY_CLAUSE);
3986    
3987                            String[] orderByFields = orderByComparator.getOrderByFields();
3988    
3989                            for (int i = 0; i < orderByFields.length; i++) {
3990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3991                                    query.append(orderByFields[i]);
3992    
3993                                    if ((i + 1) < orderByFields.length) {
3994                                            if (orderByComparator.isAscending() ^ previous) {
3995                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3996                                            }
3997                                            else {
3998                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3999                                            }
4000                                    }
4001                                    else {
4002                                            if (orderByComparator.isAscending() ^ previous) {
4003                                                    query.append(ORDER_BY_ASC);
4004                                            }
4005                                            else {
4006                                                    query.append(ORDER_BY_DESC);
4007                                            }
4008                                    }
4009                            }
4010                    }
4011    
4012                    else {
4013                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4014                    }
4015    
4016                    String sql = query.toString();
4017    
4018                    Query q = session.createQuery(sql);
4019    
4020                    q.setFirstResult(0);
4021                    q.setMaxResults(2);
4022    
4023                    QueryPos qPos = QueryPos.getInstance(q);
4024    
4025                    qPos.add(threadId);
4026    
4027                    if (orderByComparator != null) {
4028                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4029    
4030                            for (Object value : values) {
4031                                    qPos.add(value);
4032                            }
4033                    }
4034    
4035                    List<MBMessage> list = q.list();
4036    
4037                    if (list.size() == 2) {
4038                            return list.get(1);
4039                    }
4040                    else {
4041                            return null;
4042                    }
4043            }
4044    
4045            /**
4046             * Returns all the message-boards messages where userId = &#63;.
4047             *
4048             * @param userId the user ID
4049             * @return the matching message-boards messages
4050             * @throws SystemException if a system exception occurred
4051             */
4052            public List<MBMessage> findByUserId(long userId) throws SystemException {
4053                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4054            }
4055    
4056            /**
4057             * Returns a range of all the message-boards messages where userId = &#63;.
4058             *
4059             * <p>
4060             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4061             * </p>
4062             *
4063             * @param userId the user ID
4064             * @param start the lower bound of the range of message-boards messages
4065             * @param end the upper bound of the range of message-boards messages (not inclusive)
4066             * @return the range of matching message-boards messages
4067             * @throws SystemException if a system exception occurred
4068             */
4069            public List<MBMessage> findByUserId(long userId, int start, int end)
4070                    throws SystemException {
4071                    return findByUserId(userId, start, end, null);
4072            }
4073    
4074            /**
4075             * Returns an ordered range of all the message-boards messages where userId = &#63;.
4076             *
4077             * <p>
4078             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4079             * </p>
4080             *
4081             * @param userId the user ID
4082             * @param start the lower bound of the range of message-boards messages
4083             * @param end the upper bound of the range of message-boards messages (not inclusive)
4084             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4085             * @return the ordered range of matching message-boards messages
4086             * @throws SystemException if a system exception occurred
4087             */
4088            public List<MBMessage> findByUserId(long userId, int start, int end,
4089                    OrderByComparator orderByComparator) throws SystemException {
4090                    FinderPath finderPath = null;
4091                    Object[] finderArgs = null;
4092    
4093                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4094                                    (orderByComparator == null)) {
4095                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
4096                            finderArgs = new Object[] { userId };
4097                    }
4098                    else {
4099                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
4100                            finderArgs = new Object[] { userId, start, end, orderByComparator };
4101                    }
4102    
4103                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4104                                    finderArgs, this);
4105    
4106                    if ((list != null) && !list.isEmpty()) {
4107                            for (MBMessage mbMessage : list) {
4108                                    if ((userId != mbMessage.getUserId())) {
4109                                            list = null;
4110    
4111                                            break;
4112                                    }
4113                            }
4114                    }
4115    
4116                    if (list == null) {
4117                            StringBundler query = null;
4118    
4119                            if (orderByComparator != null) {
4120                                    query = new StringBundler(3 +
4121                                                    (orderByComparator.getOrderByFields().length * 3));
4122                            }
4123                            else {
4124                                    query = new StringBundler(3);
4125                            }
4126    
4127                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4128    
4129                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4130    
4131                            if (orderByComparator != null) {
4132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4133                                            orderByComparator);
4134                            }
4135    
4136                            else {
4137                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4138                            }
4139    
4140                            String sql = query.toString();
4141    
4142                            Session session = null;
4143    
4144                            try {
4145                                    session = openSession();
4146    
4147                                    Query q = session.createQuery(sql);
4148    
4149                                    QueryPos qPos = QueryPos.getInstance(q);
4150    
4151                                    qPos.add(userId);
4152    
4153                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4154                                                    end);
4155                            }
4156                            catch (Exception e) {
4157                                    throw processException(e);
4158                            }
4159                            finally {
4160                                    if (list == null) {
4161                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4162                                    }
4163                                    else {
4164                                            cacheResult(list);
4165    
4166                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4167                                    }
4168    
4169                                    closeSession(session);
4170                            }
4171                    }
4172    
4173                    return list;
4174            }
4175    
4176            /**
4177             * Returns the first message-boards message in the ordered set where userId = &#63;.
4178             *
4179             * @param userId the user ID
4180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4181             * @return the first matching message-boards message
4182             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4183             * @throws SystemException if a system exception occurred
4184             */
4185            public MBMessage findByUserId_First(long userId,
4186                    OrderByComparator orderByComparator)
4187                    throws NoSuchMessageException, SystemException {
4188                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
4189    
4190                    if (mbMessage != null) {
4191                            return mbMessage;
4192                    }
4193    
4194                    StringBundler msg = new StringBundler(4);
4195    
4196                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4197    
4198                    msg.append("userId=");
4199                    msg.append(userId);
4200    
4201                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4202    
4203                    throw new NoSuchMessageException(msg.toString());
4204            }
4205    
4206            /**
4207             * Returns the first message-boards message in the ordered set where userId = &#63;.
4208             *
4209             * @param userId the user ID
4210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4211             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4212             * @throws SystemException if a system exception occurred
4213             */
4214            public MBMessage fetchByUserId_First(long userId,
4215                    OrderByComparator orderByComparator) throws SystemException {
4216                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
4217    
4218                    if (!list.isEmpty()) {
4219                            return list.get(0);
4220                    }
4221    
4222                    return null;
4223            }
4224    
4225            /**
4226             * Returns the last message-boards message in the ordered set where userId = &#63;.
4227             *
4228             * @param userId the user ID
4229             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4230             * @return the last matching message-boards message
4231             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4232             * @throws SystemException if a system exception occurred
4233             */
4234            public MBMessage findByUserId_Last(long userId,
4235                    OrderByComparator orderByComparator)
4236                    throws NoSuchMessageException, SystemException {
4237                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
4238    
4239                    if (mbMessage != null) {
4240                            return mbMessage;
4241                    }
4242    
4243                    StringBundler msg = new StringBundler(4);
4244    
4245                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4246    
4247                    msg.append("userId=");
4248                    msg.append(userId);
4249    
4250                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4251    
4252                    throw new NoSuchMessageException(msg.toString());
4253            }
4254    
4255            /**
4256             * Returns the last message-boards message in the ordered set where userId = &#63;.
4257             *
4258             * @param userId the user ID
4259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4260             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4261             * @throws SystemException if a system exception occurred
4262             */
4263            public MBMessage fetchByUserId_Last(long userId,
4264                    OrderByComparator orderByComparator) throws SystemException {
4265                    int count = countByUserId(userId);
4266    
4267                    List<MBMessage> list = findByUserId(userId, count - 1, count,
4268                                    orderByComparator);
4269    
4270                    if (!list.isEmpty()) {
4271                            return list.get(0);
4272                    }
4273    
4274                    return null;
4275            }
4276    
4277            /**
4278             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
4279             *
4280             * @param messageId the primary key of the current message-boards message
4281             * @param userId the user ID
4282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4283             * @return the previous, current, and next message-boards message
4284             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4285             * @throws SystemException if a system exception occurred
4286             */
4287            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
4288                    OrderByComparator orderByComparator)
4289                    throws NoSuchMessageException, SystemException {
4290                    MBMessage mbMessage = findByPrimaryKey(messageId);
4291    
4292                    Session session = null;
4293    
4294                    try {
4295                            session = openSession();
4296    
4297                            MBMessage[] array = new MBMessageImpl[3];
4298    
4299                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
4300                                            orderByComparator, true);
4301    
4302                            array[1] = mbMessage;
4303    
4304                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
4305                                            orderByComparator, false);
4306    
4307                            return array;
4308                    }
4309                    catch (Exception e) {
4310                            throw processException(e);
4311                    }
4312                    finally {
4313                            closeSession(session);
4314                    }
4315            }
4316    
4317            protected MBMessage getByUserId_PrevAndNext(Session session,
4318                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
4319                    boolean previous) {
4320                    StringBundler query = null;
4321    
4322                    if (orderByComparator != null) {
4323                            query = new StringBundler(6 +
4324                                            (orderByComparator.getOrderByFields().length * 6));
4325                    }
4326                    else {
4327                            query = new StringBundler(3);
4328                    }
4329    
4330                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4331    
4332                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4333    
4334                    if (orderByComparator != null) {
4335                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4336    
4337                            if (orderByConditionFields.length > 0) {
4338                                    query.append(WHERE_AND);
4339                            }
4340    
4341                            for (int i = 0; i < orderByConditionFields.length; i++) {
4342                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4343                                    query.append(orderByConditionFields[i]);
4344    
4345                                    if ((i + 1) < orderByConditionFields.length) {
4346                                            if (orderByComparator.isAscending() ^ previous) {
4347                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4348                                            }
4349                                            else {
4350                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4351                                            }
4352                                    }
4353                                    else {
4354                                            if (orderByComparator.isAscending() ^ previous) {
4355                                                    query.append(WHERE_GREATER_THAN);
4356                                            }
4357                                            else {
4358                                                    query.append(WHERE_LESSER_THAN);
4359                                            }
4360                                    }
4361                            }
4362    
4363                            query.append(ORDER_BY_CLAUSE);
4364    
4365                            String[] orderByFields = orderByComparator.getOrderByFields();
4366    
4367                            for (int i = 0; i < orderByFields.length; i++) {
4368                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4369                                    query.append(orderByFields[i]);
4370    
4371                                    if ((i + 1) < orderByFields.length) {
4372                                            if (orderByComparator.isAscending() ^ previous) {
4373                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4374                                            }
4375                                            else {
4376                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4377                                            }
4378                                    }
4379                                    else {
4380                                            if (orderByComparator.isAscending() ^ previous) {
4381                                                    query.append(ORDER_BY_ASC);
4382                                            }
4383                                            else {
4384                                                    query.append(ORDER_BY_DESC);
4385                                            }
4386                                    }
4387                            }
4388                    }
4389    
4390                    else {
4391                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4392                    }
4393    
4394                    String sql = query.toString();
4395    
4396                    Query q = session.createQuery(sql);
4397    
4398                    q.setFirstResult(0);
4399                    q.setMaxResults(2);
4400    
4401                    QueryPos qPos = QueryPos.getInstance(q);
4402    
4403                    qPos.add(userId);
4404    
4405                    if (orderByComparator != null) {
4406                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4407    
4408                            for (Object value : values) {
4409                                    qPos.add(value);
4410                            }
4411                    }
4412    
4413                    List<MBMessage> list = q.list();
4414    
4415                    if (list.size() == 2) {
4416                            return list.get(1);
4417                    }
4418                    else {
4419                            return null;
4420                    }
4421            }
4422    
4423            /**
4424             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4425             *
4426             * @param groupId the group ID
4427             * @param userId the user ID
4428             * @return the matching message-boards messages
4429             * @throws SystemException if a system exception occurred
4430             */
4431            public List<MBMessage> findByG_U(long groupId, long userId)
4432                    throws SystemException {
4433                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4434                            null);
4435            }
4436    
4437            /**
4438             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4439             *
4440             * <p>
4441             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4442             * </p>
4443             *
4444             * @param groupId the group ID
4445             * @param userId the user ID
4446             * @param start the lower bound of the range of message-boards messages
4447             * @param end the upper bound of the range of message-boards messages (not inclusive)
4448             * @return the range of matching message-boards messages
4449             * @throws SystemException if a system exception occurred
4450             */
4451            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4452                    int end) throws SystemException {
4453                    return findByG_U(groupId, userId, start, end, null);
4454            }
4455    
4456            /**
4457             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4458             *
4459             * <p>
4460             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4461             * </p>
4462             *
4463             * @param groupId the group ID
4464             * @param userId the user ID
4465             * @param start the lower bound of the range of message-boards messages
4466             * @param end the upper bound of the range of message-boards messages (not inclusive)
4467             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4468             * @return the ordered range of matching message-boards messages
4469             * @throws SystemException if a system exception occurred
4470             */
4471            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4472                    int end, OrderByComparator orderByComparator) throws SystemException {
4473                    FinderPath finderPath = null;
4474                    Object[] finderArgs = null;
4475    
4476                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4477                                    (orderByComparator == null)) {
4478                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4479                            finderArgs = new Object[] { groupId, userId };
4480                    }
4481                    else {
4482                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4483                            finderArgs = new Object[] {
4484                                            groupId, userId,
4485                                            
4486                                            start, end, orderByComparator
4487                                    };
4488                    }
4489    
4490                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4491                                    finderArgs, this);
4492    
4493                    if ((list != null) && !list.isEmpty()) {
4494                            for (MBMessage mbMessage : list) {
4495                                    if ((groupId != mbMessage.getGroupId()) ||
4496                                                    (userId != mbMessage.getUserId())) {
4497                                            list = null;
4498    
4499                                            break;
4500                                    }
4501                            }
4502                    }
4503    
4504                    if (list == null) {
4505                            StringBundler query = null;
4506    
4507                            if (orderByComparator != null) {
4508                                    query = new StringBundler(4 +
4509                                                    (orderByComparator.getOrderByFields().length * 3));
4510                            }
4511                            else {
4512                                    query = new StringBundler(4);
4513                            }
4514    
4515                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4516    
4517                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4518    
4519                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4520    
4521                            if (orderByComparator != null) {
4522                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4523                                            orderByComparator);
4524                            }
4525    
4526                            else {
4527                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4528                            }
4529    
4530                            String sql = query.toString();
4531    
4532                            Session session = null;
4533    
4534                            try {
4535                                    session = openSession();
4536    
4537                                    Query q = session.createQuery(sql);
4538    
4539                                    QueryPos qPos = QueryPos.getInstance(q);
4540    
4541                                    qPos.add(groupId);
4542    
4543                                    qPos.add(userId);
4544    
4545                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4546                                                    end);
4547                            }
4548                            catch (Exception e) {
4549                                    throw processException(e);
4550                            }
4551                            finally {
4552                                    if (list == null) {
4553                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4554                                    }
4555                                    else {
4556                                            cacheResult(list);
4557    
4558                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4559                                    }
4560    
4561                                    closeSession(session);
4562                            }
4563                    }
4564    
4565                    return list;
4566            }
4567    
4568            /**
4569             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4570             *
4571             * @param groupId the group ID
4572             * @param userId the user ID
4573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4574             * @return the first matching message-boards message
4575             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4576             * @throws SystemException if a system exception occurred
4577             */
4578            public MBMessage findByG_U_First(long groupId, long userId,
4579                    OrderByComparator orderByComparator)
4580                    throws NoSuchMessageException, SystemException {
4581                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4582                                    orderByComparator);
4583    
4584                    if (mbMessage != null) {
4585                            return mbMessage;
4586                    }
4587    
4588                    StringBundler msg = new StringBundler(6);
4589    
4590                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4591    
4592                    msg.append("groupId=");
4593                    msg.append(groupId);
4594    
4595                    msg.append(", userId=");
4596                    msg.append(userId);
4597    
4598                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4599    
4600                    throw new NoSuchMessageException(msg.toString());
4601            }
4602    
4603            /**
4604             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4605             *
4606             * @param groupId the group ID
4607             * @param userId the user ID
4608             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4609             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4610             * @throws SystemException if a system exception occurred
4611             */
4612            public MBMessage fetchByG_U_First(long groupId, long userId,
4613                    OrderByComparator orderByComparator) throws SystemException {
4614                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4615                                    orderByComparator);
4616    
4617                    if (!list.isEmpty()) {
4618                            return list.get(0);
4619                    }
4620    
4621                    return null;
4622            }
4623    
4624            /**
4625             * Returns the last 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 last matching message-boards message
4631             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4632             * @throws SystemException if a system exception occurred
4633             */
4634            public MBMessage findByG_U_Last(long groupId, long userId,
4635                    OrderByComparator orderByComparator)
4636                    throws NoSuchMessageException, SystemException {
4637                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4638    
4639                    if (mbMessage != null) {
4640                            return mbMessage;
4641                    }
4642    
4643                    StringBundler msg = new StringBundler(6);
4644    
4645                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4646    
4647                    msg.append("groupId=");
4648                    msg.append(groupId);
4649    
4650                    msg.append(", userId=");
4651                    msg.append(userId);
4652    
4653                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4654    
4655                    throw new NoSuchMessageException(msg.toString());
4656            }
4657    
4658            /**
4659             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4660             *
4661             * @param groupId the group ID
4662             * @param userId the user ID
4663             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4664             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4665             * @throws SystemException if a system exception occurred
4666             */
4667            public MBMessage fetchByG_U_Last(long groupId, long userId,
4668                    OrderByComparator orderByComparator) throws SystemException {
4669                    int count = countByG_U(groupId, userId);
4670    
4671                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4672                                    orderByComparator);
4673    
4674                    if (!list.isEmpty()) {
4675                            return list.get(0);
4676                    }
4677    
4678                    return null;
4679            }
4680    
4681            /**
4682             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4683             *
4684             * @param messageId the primary key of the current message-boards message
4685             * @param groupId the group ID
4686             * @param userId the user ID
4687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4688             * @return the previous, current, and next message-boards message
4689             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4690             * @throws SystemException if a system exception occurred
4691             */
4692            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4693                    long userId, OrderByComparator orderByComparator)
4694                    throws NoSuchMessageException, SystemException {
4695                    MBMessage mbMessage = findByPrimaryKey(messageId);
4696    
4697                    Session session = null;
4698    
4699                    try {
4700                            session = openSession();
4701    
4702                            MBMessage[] array = new MBMessageImpl[3];
4703    
4704                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4705                                            userId, orderByComparator, true);
4706    
4707                            array[1] = mbMessage;
4708    
4709                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4710                                            userId, orderByComparator, false);
4711    
4712                            return array;
4713                    }
4714                    catch (Exception e) {
4715                            throw processException(e);
4716                    }
4717                    finally {
4718                            closeSession(session);
4719                    }
4720            }
4721    
4722            protected MBMessage getByG_U_PrevAndNext(Session session,
4723                    MBMessage mbMessage, long groupId, long userId,
4724                    OrderByComparator orderByComparator, boolean previous) {
4725                    StringBundler query = null;
4726    
4727                    if (orderByComparator != null) {
4728                            query = new StringBundler(6 +
4729                                            (orderByComparator.getOrderByFields().length * 6));
4730                    }
4731                    else {
4732                            query = new StringBundler(3);
4733                    }
4734    
4735                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4736    
4737                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4738    
4739                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4740    
4741                    if (orderByComparator != null) {
4742                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4743    
4744                            if (orderByConditionFields.length > 0) {
4745                                    query.append(WHERE_AND);
4746                            }
4747    
4748                            for (int i = 0; i < orderByConditionFields.length; i++) {
4749                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4750                                    query.append(orderByConditionFields[i]);
4751    
4752                                    if ((i + 1) < orderByConditionFields.length) {
4753                                            if (orderByComparator.isAscending() ^ previous) {
4754                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4755                                            }
4756                                            else {
4757                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4758                                            }
4759                                    }
4760                                    else {
4761                                            if (orderByComparator.isAscending() ^ previous) {
4762                                                    query.append(WHERE_GREATER_THAN);
4763                                            }
4764                                            else {
4765                                                    query.append(WHERE_LESSER_THAN);
4766                                            }
4767                                    }
4768                            }
4769    
4770                            query.append(ORDER_BY_CLAUSE);
4771    
4772                            String[] orderByFields = orderByComparator.getOrderByFields();
4773    
4774                            for (int i = 0; i < orderByFields.length; i++) {
4775                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4776                                    query.append(orderByFields[i]);
4777    
4778                                    if ((i + 1) < orderByFields.length) {
4779                                            if (orderByComparator.isAscending() ^ previous) {
4780                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4781                                            }
4782                                            else {
4783                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4784                                            }
4785                                    }
4786                                    else {
4787                                            if (orderByComparator.isAscending() ^ previous) {
4788                                                    query.append(ORDER_BY_ASC);
4789                                            }
4790                                            else {
4791                                                    query.append(ORDER_BY_DESC);
4792                                            }
4793                                    }
4794                            }
4795                    }
4796    
4797                    else {
4798                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4799                    }
4800    
4801                    String sql = query.toString();
4802    
4803                    Query q = session.createQuery(sql);
4804    
4805                    q.setFirstResult(0);
4806                    q.setMaxResults(2);
4807    
4808                    QueryPos qPos = QueryPos.getInstance(q);
4809    
4810                    qPos.add(groupId);
4811    
4812                    qPos.add(userId);
4813    
4814                    if (orderByComparator != null) {
4815                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4816    
4817                            for (Object value : values) {
4818                                    qPos.add(value);
4819                            }
4820                    }
4821    
4822                    List<MBMessage> list = q.list();
4823    
4824                    if (list.size() == 2) {
4825                            return list.get(1);
4826                    }
4827                    else {
4828                            return null;
4829                    }
4830            }
4831    
4832            /**
4833             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4834             *
4835             * @param groupId the group ID
4836             * @param userId the user ID
4837             * @return the matching message-boards messages that the user has permission to view
4838             * @throws SystemException if a system exception occurred
4839             */
4840            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4841                    throws SystemException {
4842                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4843                            QueryUtil.ALL_POS, null);
4844            }
4845    
4846            /**
4847             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4848             *
4849             * <p>
4850             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4851             * </p>
4852             *
4853             * @param groupId the group ID
4854             * @param userId the user ID
4855             * @param start the lower bound of the range of message-boards messages
4856             * @param end the upper bound of the range of message-boards messages (not inclusive)
4857             * @return the range of matching message-boards messages that the user has permission to view
4858             * @throws SystemException if a system exception occurred
4859             */
4860            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4861                    int start, int end) throws SystemException {
4862                    return filterFindByG_U(groupId, userId, start, end, null);
4863            }
4864    
4865            /**
4866             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4867             *
4868             * <p>
4869             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4870             * </p>
4871             *
4872             * @param groupId the group ID
4873             * @param userId the user ID
4874             * @param start the lower bound of the range of message-boards messages
4875             * @param end the upper bound of the range of message-boards messages (not inclusive)
4876             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4877             * @return the ordered range of matching message-boards messages that the user has permission to view
4878             * @throws SystemException if a system exception occurred
4879             */
4880            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4881                    int start, int end, OrderByComparator orderByComparator)
4882                    throws SystemException {
4883                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4884                            return findByG_U(groupId, userId, start, end, orderByComparator);
4885                    }
4886    
4887                    StringBundler query = null;
4888    
4889                    if (orderByComparator != null) {
4890                            query = new StringBundler(4 +
4891                                            (orderByComparator.getOrderByFields().length * 3));
4892                    }
4893                    else {
4894                            query = new StringBundler(4);
4895                    }
4896    
4897                    if (getDB().isSupportsInlineDistinct()) {
4898                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4899                    }
4900                    else {
4901                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4902                    }
4903    
4904                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4905    
4906                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4907    
4908                    if (!getDB().isSupportsInlineDistinct()) {
4909                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4910                    }
4911    
4912                    if (orderByComparator != null) {
4913                            if (getDB().isSupportsInlineDistinct()) {
4914                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4915                                            orderByComparator);
4916                            }
4917                            else {
4918                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4919                                            orderByComparator);
4920                            }
4921                    }
4922    
4923                    else {
4924                            if (getDB().isSupportsInlineDistinct()) {
4925                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4926                            }
4927                            else {
4928                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4929                            }
4930                    }
4931    
4932                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4933                                    MBMessage.class.getName(),
4934                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4935    
4936                    Session session = null;
4937    
4938                    try {
4939                            session = openSession();
4940    
4941                            SQLQuery q = session.createSQLQuery(sql);
4942    
4943                            if (getDB().isSupportsInlineDistinct()) {
4944                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4945                            }
4946                            else {
4947                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4948                            }
4949    
4950                            QueryPos qPos = QueryPos.getInstance(q);
4951    
4952                            qPos.add(groupId);
4953    
4954                            qPos.add(userId);
4955    
4956                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4957                    }
4958                    catch (Exception e) {
4959                            throw processException(e);
4960                    }
4961                    finally {
4962                            closeSession(session);
4963                    }
4964            }
4965    
4966            /**
4967             * 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;.
4968             *
4969             * @param messageId the primary key of the current message-boards message
4970             * @param groupId the group ID
4971             * @param userId the user ID
4972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4973             * @return the previous, current, and next message-boards message
4974             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4975             * @throws SystemException if a system exception occurred
4976             */
4977            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4978                    long groupId, long userId, OrderByComparator orderByComparator)
4979                    throws NoSuchMessageException, SystemException {
4980                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4981                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4982                                    orderByComparator);
4983                    }
4984    
4985                    MBMessage mbMessage = findByPrimaryKey(messageId);
4986    
4987                    Session session = null;
4988    
4989                    try {
4990                            session = openSession();
4991    
4992                            MBMessage[] array = new MBMessageImpl[3];
4993    
4994                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4995                                            userId, orderByComparator, true);
4996    
4997                            array[1] = mbMessage;
4998    
4999                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
5000                                            userId, orderByComparator, false);
5001    
5002                            return array;
5003                    }
5004                    catch (Exception e) {
5005                            throw processException(e);
5006                    }
5007                    finally {
5008                            closeSession(session);
5009                    }
5010            }
5011    
5012            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5013                    MBMessage mbMessage, long groupId, long userId,
5014                    OrderByComparator orderByComparator, boolean previous) {
5015                    StringBundler query = null;
5016    
5017                    if (orderByComparator != null) {
5018                            query = new StringBundler(6 +
5019                                            (orderByComparator.getOrderByFields().length * 6));
5020                    }
5021                    else {
5022                            query = new StringBundler(3);
5023                    }
5024    
5025                    if (getDB().isSupportsInlineDistinct()) {
5026                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5027                    }
5028                    else {
5029                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5030                    }
5031    
5032                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5033    
5034                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5035    
5036                    if (!getDB().isSupportsInlineDistinct()) {
5037                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5038                    }
5039    
5040                    if (orderByComparator != null) {
5041                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5042    
5043                            if (orderByConditionFields.length > 0) {
5044                                    query.append(WHERE_AND);
5045                            }
5046    
5047                            for (int i = 0; i < orderByConditionFields.length; i++) {
5048                                    if (getDB().isSupportsInlineDistinct()) {
5049                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5050                                    }
5051                                    else {
5052                                            query.append(_ORDER_BY_ENTITY_TABLE);
5053                                    }
5054    
5055                                    query.append(orderByConditionFields[i]);
5056    
5057                                    if ((i + 1) < orderByConditionFields.length) {
5058                                            if (orderByComparator.isAscending() ^ previous) {
5059                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5060                                            }
5061                                            else {
5062                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5063                                            }
5064                                    }
5065                                    else {
5066                                            if (orderByComparator.isAscending() ^ previous) {
5067                                                    query.append(WHERE_GREATER_THAN);
5068                                            }
5069                                            else {
5070                                                    query.append(WHERE_LESSER_THAN);
5071                                            }
5072                                    }
5073                            }
5074    
5075                            query.append(ORDER_BY_CLAUSE);
5076    
5077                            String[] orderByFields = orderByComparator.getOrderByFields();
5078    
5079                            for (int i = 0; i < orderByFields.length; i++) {
5080                                    if (getDB().isSupportsInlineDistinct()) {
5081                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5082                                    }
5083                                    else {
5084                                            query.append(_ORDER_BY_ENTITY_TABLE);
5085                                    }
5086    
5087                                    query.append(orderByFields[i]);
5088    
5089                                    if ((i + 1) < orderByFields.length) {
5090                                            if (orderByComparator.isAscending() ^ previous) {
5091                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5092                                            }
5093                                            else {
5094                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5095                                            }
5096                                    }
5097                                    else {
5098                                            if (orderByComparator.isAscending() ^ previous) {
5099                                                    query.append(ORDER_BY_ASC);
5100                                            }
5101                                            else {
5102                                                    query.append(ORDER_BY_DESC);
5103                                            }
5104                                    }
5105                            }
5106                    }
5107    
5108                    else {
5109                            if (getDB().isSupportsInlineDistinct()) {
5110                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5111                            }
5112                            else {
5113                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5114                            }
5115                    }
5116    
5117                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5118                                    MBMessage.class.getName(),
5119                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5120    
5121                    SQLQuery q = session.createSQLQuery(sql);
5122    
5123                    q.setFirstResult(0);
5124                    q.setMaxResults(2);
5125    
5126                    if (getDB().isSupportsInlineDistinct()) {
5127                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5128                    }
5129                    else {
5130                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5131                    }
5132    
5133                    QueryPos qPos = QueryPos.getInstance(q);
5134    
5135                    qPos.add(groupId);
5136    
5137                    qPos.add(userId);
5138    
5139                    if (orderByComparator != null) {
5140                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5141    
5142                            for (Object value : values) {
5143                                    qPos.add(value);
5144                            }
5145                    }
5146    
5147                    List<MBMessage> list = q.list();
5148    
5149                    if (list.size() == 2) {
5150                            return list.get(1);
5151                    }
5152                    else {
5153                            return null;
5154                    }
5155            }
5156    
5157            /**
5158             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5159             *
5160             * @param groupId the group ID
5161             * @param categoryId the category ID
5162             * @return the matching message-boards messages
5163             * @throws SystemException if a system exception occurred
5164             */
5165            public List<MBMessage> findByG_C(long groupId, long categoryId)
5166                    throws SystemException {
5167                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5168                            QueryUtil.ALL_POS, null);
5169            }
5170    
5171            /**
5172             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5173             *
5174             * <p>
5175             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5176             * </p>
5177             *
5178             * @param groupId the group ID
5179             * @param categoryId the category ID
5180             * @param start the lower bound of the range of message-boards messages
5181             * @param end the upper bound of the range of message-boards messages (not inclusive)
5182             * @return the range of matching message-boards messages
5183             * @throws SystemException if a system exception occurred
5184             */
5185            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5186                    int end) throws SystemException {
5187                    return findByG_C(groupId, categoryId, start, end, null);
5188            }
5189    
5190            /**
5191             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5192             *
5193             * <p>
5194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5195             * </p>
5196             *
5197             * @param groupId the group ID
5198             * @param categoryId the category ID
5199             * @param start the lower bound of the range of message-boards messages
5200             * @param end the upper bound of the range of message-boards messages (not inclusive)
5201             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5202             * @return the ordered range of matching message-boards messages
5203             * @throws SystemException if a system exception occurred
5204             */
5205            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5206                    int end, OrderByComparator orderByComparator) throws SystemException {
5207                    FinderPath finderPath = null;
5208                    Object[] finderArgs = null;
5209    
5210                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5211                                    (orderByComparator == null)) {
5212                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5213                            finderArgs = new Object[] { groupId, categoryId };
5214                    }
5215                    else {
5216                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5217                            finderArgs = new Object[] {
5218                                            groupId, categoryId,
5219                                            
5220                                            start, end, orderByComparator
5221                                    };
5222                    }
5223    
5224                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5225                                    finderArgs, this);
5226    
5227                    if ((list != null) && !list.isEmpty()) {
5228                            for (MBMessage mbMessage : list) {
5229                                    if ((groupId != mbMessage.getGroupId()) ||
5230                                                    (categoryId != mbMessage.getCategoryId())) {
5231                                            list = null;
5232    
5233                                            break;
5234                                    }
5235                            }
5236                    }
5237    
5238                    if (list == null) {
5239                            StringBundler query = null;
5240    
5241                            if (orderByComparator != null) {
5242                                    query = new StringBundler(4 +
5243                                                    (orderByComparator.getOrderByFields().length * 3));
5244                            }
5245                            else {
5246                                    query = new StringBundler(4);
5247                            }
5248    
5249                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5250    
5251                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5252    
5253                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5254    
5255                            if (orderByComparator != null) {
5256                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5257                                            orderByComparator);
5258                            }
5259    
5260                            else {
5261                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5262                            }
5263    
5264                            String sql = query.toString();
5265    
5266                            Session session = null;
5267    
5268                            try {
5269                                    session = openSession();
5270    
5271                                    Query q = session.createQuery(sql);
5272    
5273                                    QueryPos qPos = QueryPos.getInstance(q);
5274    
5275                                    qPos.add(groupId);
5276    
5277                                    qPos.add(categoryId);
5278    
5279                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5280                                                    end);
5281                            }
5282                            catch (Exception e) {
5283                                    throw processException(e);
5284                            }
5285                            finally {
5286                                    if (list == null) {
5287                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5288                                    }
5289                                    else {
5290                                            cacheResult(list);
5291    
5292                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5293                                    }
5294    
5295                                    closeSession(session);
5296                            }
5297                    }
5298    
5299                    return list;
5300            }
5301    
5302            /**
5303             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5304             *
5305             * @param groupId the group ID
5306             * @param categoryId the category ID
5307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5308             * @return the first matching message-boards message
5309             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5310             * @throws SystemException if a system exception occurred
5311             */
5312            public MBMessage findByG_C_First(long groupId, long categoryId,
5313                    OrderByComparator orderByComparator)
5314                    throws NoSuchMessageException, SystemException {
5315                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5316                                    orderByComparator);
5317    
5318                    if (mbMessage != null) {
5319                            return mbMessage;
5320                    }
5321    
5322                    StringBundler msg = new StringBundler(6);
5323    
5324                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5325    
5326                    msg.append("groupId=");
5327                    msg.append(groupId);
5328    
5329                    msg.append(", categoryId=");
5330                    msg.append(categoryId);
5331    
5332                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5333    
5334                    throw new NoSuchMessageException(msg.toString());
5335            }
5336    
5337            /**
5338             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5339             *
5340             * @param groupId the group ID
5341             * @param categoryId the category ID
5342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5343             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5344             * @throws SystemException if a system exception occurred
5345             */
5346            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5347                    OrderByComparator orderByComparator) throws SystemException {
5348                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5349                                    orderByComparator);
5350    
5351                    if (!list.isEmpty()) {
5352                            return list.get(0);
5353                    }
5354    
5355                    return null;
5356            }
5357    
5358            /**
5359             * Returns the last 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 last matching message-boards message
5365             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5366             * @throws SystemException if a system exception occurred
5367             */
5368            public MBMessage findByG_C_Last(long groupId, long categoryId,
5369                    OrderByComparator orderByComparator)
5370                    throws NoSuchMessageException, SystemException {
5371                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5372                                    orderByComparator);
5373    
5374                    if (mbMessage != null) {
5375                            return mbMessage;
5376                    }
5377    
5378                    StringBundler msg = new StringBundler(6);
5379    
5380                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5381    
5382                    msg.append("groupId=");
5383                    msg.append(groupId);
5384    
5385                    msg.append(", categoryId=");
5386                    msg.append(categoryId);
5387    
5388                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5389    
5390                    throw new NoSuchMessageException(msg.toString());
5391            }
5392    
5393            /**
5394             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5395             *
5396             * @param groupId the group ID
5397             * @param categoryId the category ID
5398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5399             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5400             * @throws SystemException if a system exception occurred
5401             */
5402            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5403                    OrderByComparator orderByComparator) throws SystemException {
5404                    int count = countByG_C(groupId, categoryId);
5405    
5406                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5407                                    orderByComparator);
5408    
5409                    if (!list.isEmpty()) {
5410                            return list.get(0);
5411                    }
5412    
5413                    return null;
5414            }
5415    
5416            /**
5417             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5418             *
5419             * @param messageId the primary key of the current message-boards message
5420             * @param groupId the group ID
5421             * @param categoryId the category ID
5422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5423             * @return the previous, current, and next message-boards message
5424             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5425             * @throws SystemException if a system exception occurred
5426             */
5427            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5428                    long categoryId, OrderByComparator orderByComparator)
5429                    throws NoSuchMessageException, SystemException {
5430                    MBMessage mbMessage = findByPrimaryKey(messageId);
5431    
5432                    Session session = null;
5433    
5434                    try {
5435                            session = openSession();
5436    
5437                            MBMessage[] array = new MBMessageImpl[3];
5438    
5439                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5440                                            categoryId, orderByComparator, true);
5441    
5442                            array[1] = mbMessage;
5443    
5444                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5445                                            categoryId, orderByComparator, false);
5446    
5447                            return array;
5448                    }
5449                    catch (Exception e) {
5450                            throw processException(e);
5451                    }
5452                    finally {
5453                            closeSession(session);
5454                    }
5455            }
5456    
5457            protected MBMessage getByG_C_PrevAndNext(Session session,
5458                    MBMessage mbMessage, long groupId, long categoryId,
5459                    OrderByComparator orderByComparator, boolean previous) {
5460                    StringBundler query = null;
5461    
5462                    if (orderByComparator != null) {
5463                            query = new StringBundler(6 +
5464                                            (orderByComparator.getOrderByFields().length * 6));
5465                    }
5466                    else {
5467                            query = new StringBundler(3);
5468                    }
5469    
5470                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5471    
5472                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5473    
5474                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5475    
5476                    if (orderByComparator != null) {
5477                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5478    
5479                            if (orderByConditionFields.length > 0) {
5480                                    query.append(WHERE_AND);
5481                            }
5482    
5483                            for (int i = 0; i < orderByConditionFields.length; i++) {
5484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5485                                    query.append(orderByConditionFields[i]);
5486    
5487                                    if ((i + 1) < orderByConditionFields.length) {
5488                                            if (orderByComparator.isAscending() ^ previous) {
5489                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5490                                            }
5491                                            else {
5492                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5493                                            }
5494                                    }
5495                                    else {
5496                                            if (orderByComparator.isAscending() ^ previous) {
5497                                                    query.append(WHERE_GREATER_THAN);
5498                                            }
5499                                            else {
5500                                                    query.append(WHERE_LESSER_THAN);
5501                                            }
5502                                    }
5503                            }
5504    
5505                            query.append(ORDER_BY_CLAUSE);
5506    
5507                            String[] orderByFields = orderByComparator.getOrderByFields();
5508    
5509                            for (int i = 0; i < orderByFields.length; i++) {
5510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5511                                    query.append(orderByFields[i]);
5512    
5513                                    if ((i + 1) < orderByFields.length) {
5514                                            if (orderByComparator.isAscending() ^ previous) {
5515                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5516                                            }
5517                                            else {
5518                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5519                                            }
5520                                    }
5521                                    else {
5522                                            if (orderByComparator.isAscending() ^ previous) {
5523                                                    query.append(ORDER_BY_ASC);
5524                                            }
5525                                            else {
5526                                                    query.append(ORDER_BY_DESC);
5527                                            }
5528                                    }
5529                            }
5530                    }
5531    
5532                    else {
5533                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5534                    }
5535    
5536                    String sql = query.toString();
5537    
5538                    Query q = session.createQuery(sql);
5539    
5540                    q.setFirstResult(0);
5541                    q.setMaxResults(2);
5542    
5543                    QueryPos qPos = QueryPos.getInstance(q);
5544    
5545                    qPos.add(groupId);
5546    
5547                    qPos.add(categoryId);
5548    
5549                    if (orderByComparator != null) {
5550                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5551    
5552                            for (Object value : values) {
5553                                    qPos.add(value);
5554                            }
5555                    }
5556    
5557                    List<MBMessage> list = q.list();
5558    
5559                    if (list.size() == 2) {
5560                            return list.get(1);
5561                    }
5562                    else {
5563                            return null;
5564                    }
5565            }
5566    
5567            /**
5568             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5569             *
5570             * @param groupId the group ID
5571             * @param categoryId the category ID
5572             * @return the matching message-boards messages that the user has permission to view
5573             * @throws SystemException if a system exception occurred
5574             */
5575            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5576                    throws SystemException {
5577                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5578                            QueryUtil.ALL_POS, null);
5579            }
5580    
5581            /**
5582             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5583             *
5584             * <p>
5585             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5586             * </p>
5587             *
5588             * @param groupId the group ID
5589             * @param categoryId the category ID
5590             * @param start the lower bound of the range of message-boards messages
5591             * @param end the upper bound of the range of message-boards messages (not inclusive)
5592             * @return the range of matching message-boards messages that the user has permission to view
5593             * @throws SystemException if a system exception occurred
5594             */
5595            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5596                    int start, int end) throws SystemException {
5597                    return filterFindByG_C(groupId, categoryId, start, end, null);
5598            }
5599    
5600            /**
5601             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5602             *
5603             * <p>
5604             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5605             * </p>
5606             *
5607             * @param groupId the group ID
5608             * @param categoryId the category ID
5609             * @param start the lower bound of the range of message-boards messages
5610             * @param end the upper bound of the range of message-boards messages (not inclusive)
5611             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5612             * @return the ordered range of matching message-boards messages that the user has permission to view
5613             * @throws SystemException if a system exception occurred
5614             */
5615            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5616                    int start, int end, OrderByComparator orderByComparator)
5617                    throws SystemException {
5618                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5619                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5620                    }
5621    
5622                    StringBundler query = null;
5623    
5624                    if (orderByComparator != null) {
5625                            query = new StringBundler(4 +
5626                                            (orderByComparator.getOrderByFields().length * 3));
5627                    }
5628                    else {
5629                            query = new StringBundler(4);
5630                    }
5631    
5632                    if (getDB().isSupportsInlineDistinct()) {
5633                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5634                    }
5635                    else {
5636                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5637                    }
5638    
5639                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5640    
5641                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5642    
5643                    if (!getDB().isSupportsInlineDistinct()) {
5644                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5645                    }
5646    
5647                    if (orderByComparator != null) {
5648                            if (getDB().isSupportsInlineDistinct()) {
5649                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5650                                            orderByComparator);
5651                            }
5652                            else {
5653                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5654                                            orderByComparator);
5655                            }
5656                    }
5657    
5658                    else {
5659                            if (getDB().isSupportsInlineDistinct()) {
5660                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5661                            }
5662                            else {
5663                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5664                            }
5665                    }
5666    
5667                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5668                                    MBMessage.class.getName(),
5669                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5670    
5671                    Session session = null;
5672    
5673                    try {
5674                            session = openSession();
5675    
5676                            SQLQuery q = session.createSQLQuery(sql);
5677    
5678                            if (getDB().isSupportsInlineDistinct()) {
5679                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5680                            }
5681                            else {
5682                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5683                            }
5684    
5685                            QueryPos qPos = QueryPos.getInstance(q);
5686    
5687                            qPos.add(groupId);
5688    
5689                            qPos.add(categoryId);
5690    
5691                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5692                    }
5693                    catch (Exception e) {
5694                            throw processException(e);
5695                    }
5696                    finally {
5697                            closeSession(session);
5698                    }
5699            }
5700    
5701            /**
5702             * 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;.
5703             *
5704             * @param messageId the primary key of the current message-boards message
5705             * @param groupId the group ID
5706             * @param categoryId the category ID
5707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5708             * @return the previous, current, and next message-boards message
5709             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5710             * @throws SystemException if a system exception occurred
5711             */
5712            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5713                    long groupId, long categoryId, OrderByComparator orderByComparator)
5714                    throws NoSuchMessageException, SystemException {
5715                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5716                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5717                                    orderByComparator);
5718                    }
5719    
5720                    MBMessage mbMessage = findByPrimaryKey(messageId);
5721    
5722                    Session session = null;
5723    
5724                    try {
5725                            session = openSession();
5726    
5727                            MBMessage[] array = new MBMessageImpl[3];
5728    
5729                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5730                                            categoryId, orderByComparator, true);
5731    
5732                            array[1] = mbMessage;
5733    
5734                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5735                                            categoryId, orderByComparator, false);
5736    
5737                            return array;
5738                    }
5739                    catch (Exception e) {
5740                            throw processException(e);
5741                    }
5742                    finally {
5743                            closeSession(session);
5744                    }
5745            }
5746    
5747            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5748                    MBMessage mbMessage, long groupId, long categoryId,
5749                    OrderByComparator orderByComparator, boolean previous) {
5750                    StringBundler query = null;
5751    
5752                    if (orderByComparator != null) {
5753                            query = new StringBundler(6 +
5754                                            (orderByComparator.getOrderByFields().length * 6));
5755                    }
5756                    else {
5757                            query = new StringBundler(3);
5758                    }
5759    
5760                    if (getDB().isSupportsInlineDistinct()) {
5761                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5762                    }
5763                    else {
5764                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5765                    }
5766    
5767                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5768    
5769                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5770    
5771                    if (!getDB().isSupportsInlineDistinct()) {
5772                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5773                    }
5774    
5775                    if (orderByComparator != null) {
5776                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5777    
5778                            if (orderByConditionFields.length > 0) {
5779                                    query.append(WHERE_AND);
5780                            }
5781    
5782                            for (int i = 0; i < orderByConditionFields.length; i++) {
5783                                    if (getDB().isSupportsInlineDistinct()) {
5784                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5785                                    }
5786                                    else {
5787                                            query.append(_ORDER_BY_ENTITY_TABLE);
5788                                    }
5789    
5790                                    query.append(orderByConditionFields[i]);
5791    
5792                                    if ((i + 1) < orderByConditionFields.length) {
5793                                            if (orderByComparator.isAscending() ^ previous) {
5794                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5795                                            }
5796                                            else {
5797                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5798                                            }
5799                                    }
5800                                    else {
5801                                            if (orderByComparator.isAscending() ^ previous) {
5802                                                    query.append(WHERE_GREATER_THAN);
5803                                            }
5804                                            else {
5805                                                    query.append(WHERE_LESSER_THAN);
5806                                            }
5807                                    }
5808                            }
5809    
5810                            query.append(ORDER_BY_CLAUSE);
5811    
5812                            String[] orderByFields = orderByComparator.getOrderByFields();
5813    
5814                            for (int i = 0; i < orderByFields.length; i++) {
5815                                    if (getDB().isSupportsInlineDistinct()) {
5816                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5817                                    }
5818                                    else {
5819                                            query.append(_ORDER_BY_ENTITY_TABLE);
5820                                    }
5821    
5822                                    query.append(orderByFields[i]);
5823    
5824                                    if ((i + 1) < orderByFields.length) {
5825                                            if (orderByComparator.isAscending() ^ previous) {
5826                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5827                                            }
5828                                            else {
5829                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5830                                            }
5831                                    }
5832                                    else {
5833                                            if (orderByComparator.isAscending() ^ previous) {
5834                                                    query.append(ORDER_BY_ASC);
5835                                            }
5836                                            else {
5837                                                    query.append(ORDER_BY_DESC);
5838                                            }
5839                                    }
5840                            }
5841                    }
5842    
5843                    else {
5844                            if (getDB().isSupportsInlineDistinct()) {
5845                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5846                            }
5847                            else {
5848                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5849                            }
5850                    }
5851    
5852                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5853                                    MBMessage.class.getName(),
5854                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5855    
5856                    SQLQuery q = session.createSQLQuery(sql);
5857    
5858                    q.setFirstResult(0);
5859                    q.setMaxResults(2);
5860    
5861                    if (getDB().isSupportsInlineDistinct()) {
5862                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5863                    }
5864                    else {
5865                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5866                    }
5867    
5868                    QueryPos qPos = QueryPos.getInstance(q);
5869    
5870                    qPos.add(groupId);
5871    
5872                    qPos.add(categoryId);
5873    
5874                    if (orderByComparator != null) {
5875                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5876    
5877                            for (Object value : values) {
5878                                    qPos.add(value);
5879                            }
5880                    }
5881    
5882                    List<MBMessage> list = q.list();
5883    
5884                    if (list.size() == 2) {
5885                            return list.get(1);
5886                    }
5887                    else {
5888                            return null;
5889                    }
5890            }
5891    
5892            /**
5893             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5894             *
5895             * @param groupId the group ID
5896             * @param status the status
5897             * @return the matching message-boards messages
5898             * @throws SystemException if a system exception occurred
5899             */
5900            public List<MBMessage> findByG_S(long groupId, int status)
5901                    throws SystemException {
5902                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5903                            null);
5904            }
5905    
5906            /**
5907             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5908             *
5909             * <p>
5910             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5911             * </p>
5912             *
5913             * @param groupId the group ID
5914             * @param status the status
5915             * @param start the lower bound of the range of message-boards messages
5916             * @param end the upper bound of the range of message-boards messages (not inclusive)
5917             * @return the range of matching message-boards messages
5918             * @throws SystemException if a system exception occurred
5919             */
5920            public List<MBMessage> findByG_S(long groupId, int status, int start,
5921                    int end) throws SystemException {
5922                    return findByG_S(groupId, status, start, end, null);
5923            }
5924    
5925            /**
5926             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
5927             *
5928             * <p>
5929             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5930             * </p>
5931             *
5932             * @param groupId the group ID
5933             * @param status the status
5934             * @param start the lower bound of the range of message-boards messages
5935             * @param end the upper bound of the range of message-boards messages (not inclusive)
5936             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5937             * @return the ordered range of matching message-boards messages
5938             * @throws SystemException if a system exception occurred
5939             */
5940            public List<MBMessage> findByG_S(long groupId, int status, int start,
5941                    int end, OrderByComparator orderByComparator) throws SystemException {
5942                    FinderPath finderPath = null;
5943                    Object[] finderArgs = null;
5944    
5945                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5946                                    (orderByComparator == null)) {
5947                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
5948                            finderArgs = new Object[] { groupId, status };
5949                    }
5950                    else {
5951                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
5952                            finderArgs = new Object[] {
5953                                            groupId, status,
5954                                            
5955                                            start, end, orderByComparator
5956                                    };
5957                    }
5958    
5959                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5960                                    finderArgs, this);
5961    
5962                    if ((list != null) && !list.isEmpty()) {
5963                            for (MBMessage mbMessage : list) {
5964                                    if ((groupId != mbMessage.getGroupId()) ||
5965                                                    (status != mbMessage.getStatus())) {
5966                                            list = null;
5967    
5968                                            break;
5969                                    }
5970                            }
5971                    }
5972    
5973                    if (list == null) {
5974                            StringBundler query = null;
5975    
5976                            if (orderByComparator != null) {
5977                                    query = new StringBundler(4 +
5978                                                    (orderByComparator.getOrderByFields().length * 3));
5979                            }
5980                            else {
5981                                    query = new StringBundler(4);
5982                            }
5983    
5984                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5985    
5986                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5987    
5988                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5989    
5990                            if (orderByComparator != null) {
5991                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5992                                            orderByComparator);
5993                            }
5994    
5995                            else {
5996                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5997                            }
5998    
5999                            String sql = query.toString();
6000    
6001                            Session session = null;
6002    
6003                            try {
6004                                    session = openSession();
6005    
6006                                    Query q = session.createQuery(sql);
6007    
6008                                    QueryPos qPos = QueryPos.getInstance(q);
6009    
6010                                    qPos.add(groupId);
6011    
6012                                    qPos.add(status);
6013    
6014                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6015                                                    end);
6016                            }
6017                            catch (Exception e) {
6018                                    throw processException(e);
6019                            }
6020                            finally {
6021                                    if (list == null) {
6022                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6023                                    }
6024                                    else {
6025                                            cacheResult(list);
6026    
6027                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6028                                    }
6029    
6030                                    closeSession(session);
6031                            }
6032                    }
6033    
6034                    return list;
6035            }
6036    
6037            /**
6038             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6039             *
6040             * @param groupId the group ID
6041             * @param status the status
6042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6043             * @return the first matching message-boards message
6044             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6045             * @throws SystemException if a system exception occurred
6046             */
6047            public MBMessage findByG_S_First(long groupId, int status,
6048                    OrderByComparator orderByComparator)
6049                    throws NoSuchMessageException, SystemException {
6050                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6051                                    orderByComparator);
6052    
6053                    if (mbMessage != null) {
6054                            return mbMessage;
6055                    }
6056    
6057                    StringBundler msg = new StringBundler(6);
6058    
6059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6060    
6061                    msg.append("groupId=");
6062                    msg.append(groupId);
6063    
6064                    msg.append(", status=");
6065                    msg.append(status);
6066    
6067                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6068    
6069                    throw new NoSuchMessageException(msg.toString());
6070            }
6071    
6072            /**
6073             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6074             *
6075             * @param groupId the group ID
6076             * @param status the status
6077             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6078             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6079             * @throws SystemException if a system exception occurred
6080             */
6081            public MBMessage fetchByG_S_First(long groupId, int status,
6082                    OrderByComparator orderByComparator) throws SystemException {
6083                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6084                                    orderByComparator);
6085    
6086                    if (!list.isEmpty()) {
6087                            return list.get(0);
6088                    }
6089    
6090                    return null;
6091            }
6092    
6093            /**
6094             * Returns the last 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 last matching message-boards message
6100             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6101             * @throws SystemException if a system exception occurred
6102             */
6103            public MBMessage findByG_S_Last(long groupId, int status,
6104                    OrderByComparator orderByComparator)
6105                    throws NoSuchMessageException, SystemException {
6106                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6107    
6108                    if (mbMessage != null) {
6109                            return mbMessage;
6110                    }
6111    
6112                    StringBundler msg = new StringBundler(6);
6113    
6114                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6115    
6116                    msg.append("groupId=");
6117                    msg.append(groupId);
6118    
6119                    msg.append(", status=");
6120                    msg.append(status);
6121    
6122                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6123    
6124                    throw new NoSuchMessageException(msg.toString());
6125            }
6126    
6127            /**
6128             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6129             *
6130             * @param groupId the group ID
6131             * @param status the status
6132             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6133             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6134             * @throws SystemException if a system exception occurred
6135             */
6136            public MBMessage fetchByG_S_Last(long groupId, int status,
6137                    OrderByComparator orderByComparator) throws SystemException {
6138                    int count = countByG_S(groupId, status);
6139    
6140                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6141                                    orderByComparator);
6142    
6143                    if (!list.isEmpty()) {
6144                            return list.get(0);
6145                    }
6146    
6147                    return null;
6148            }
6149    
6150            /**
6151             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6152             *
6153             * @param messageId the primary key of the current message-boards message
6154             * @param groupId the group ID
6155             * @param status the status
6156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6157             * @return the previous, current, and next message-boards message
6158             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6159             * @throws SystemException if a system exception occurred
6160             */
6161            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6162                    int status, OrderByComparator orderByComparator)
6163                    throws NoSuchMessageException, SystemException {
6164                    MBMessage mbMessage = findByPrimaryKey(messageId);
6165    
6166                    Session session = null;
6167    
6168                    try {
6169                            session = openSession();
6170    
6171                            MBMessage[] array = new MBMessageImpl[3];
6172    
6173                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6174                                            status, orderByComparator, true);
6175    
6176                            array[1] = mbMessage;
6177    
6178                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6179                                            status, orderByComparator, false);
6180    
6181                            return array;
6182                    }
6183                    catch (Exception e) {
6184                            throw processException(e);
6185                    }
6186                    finally {
6187                            closeSession(session);
6188                    }
6189            }
6190    
6191            protected MBMessage getByG_S_PrevAndNext(Session session,
6192                    MBMessage mbMessage, long groupId, int status,
6193                    OrderByComparator orderByComparator, boolean previous) {
6194                    StringBundler query = null;
6195    
6196                    if (orderByComparator != null) {
6197                            query = new StringBundler(6 +
6198                                            (orderByComparator.getOrderByFields().length * 6));
6199                    }
6200                    else {
6201                            query = new StringBundler(3);
6202                    }
6203    
6204                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6205    
6206                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6207    
6208                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6209    
6210                    if (orderByComparator != null) {
6211                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6212    
6213                            if (orderByConditionFields.length > 0) {
6214                                    query.append(WHERE_AND);
6215                            }
6216    
6217                            for (int i = 0; i < orderByConditionFields.length; i++) {
6218                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6219                                    query.append(orderByConditionFields[i]);
6220    
6221                                    if ((i + 1) < orderByConditionFields.length) {
6222                                            if (orderByComparator.isAscending() ^ previous) {
6223                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6224                                            }
6225                                            else {
6226                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6227                                            }
6228                                    }
6229                                    else {
6230                                            if (orderByComparator.isAscending() ^ previous) {
6231                                                    query.append(WHERE_GREATER_THAN);
6232                                            }
6233                                            else {
6234                                                    query.append(WHERE_LESSER_THAN);
6235                                            }
6236                                    }
6237                            }
6238    
6239                            query.append(ORDER_BY_CLAUSE);
6240    
6241                            String[] orderByFields = orderByComparator.getOrderByFields();
6242    
6243                            for (int i = 0; i < orderByFields.length; i++) {
6244                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6245                                    query.append(orderByFields[i]);
6246    
6247                                    if ((i + 1) < orderByFields.length) {
6248                                            if (orderByComparator.isAscending() ^ previous) {
6249                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6250                                            }
6251                                            else {
6252                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6253                                            }
6254                                    }
6255                                    else {
6256                                            if (orderByComparator.isAscending() ^ previous) {
6257                                                    query.append(ORDER_BY_ASC);
6258                                            }
6259                                            else {
6260                                                    query.append(ORDER_BY_DESC);
6261                                            }
6262                                    }
6263                            }
6264                    }
6265    
6266                    else {
6267                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6268                    }
6269    
6270                    String sql = query.toString();
6271    
6272                    Query q = session.createQuery(sql);
6273    
6274                    q.setFirstResult(0);
6275                    q.setMaxResults(2);
6276    
6277                    QueryPos qPos = QueryPos.getInstance(q);
6278    
6279                    qPos.add(groupId);
6280    
6281                    qPos.add(status);
6282    
6283                    if (orderByComparator != null) {
6284                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6285    
6286                            for (Object value : values) {
6287                                    qPos.add(value);
6288                            }
6289                    }
6290    
6291                    List<MBMessage> list = q.list();
6292    
6293                    if (list.size() == 2) {
6294                            return list.get(1);
6295                    }
6296                    else {
6297                            return null;
6298                    }
6299            }
6300    
6301            /**
6302             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6303             *
6304             * @param groupId the group ID
6305             * @param status the status
6306             * @return the matching message-boards messages that the user has permission to view
6307             * @throws SystemException if a system exception occurred
6308             */
6309            public List<MBMessage> filterFindByG_S(long groupId, int status)
6310                    throws SystemException {
6311                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6312                            QueryUtil.ALL_POS, null);
6313            }
6314    
6315            /**
6316             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6317             *
6318             * <p>
6319             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6320             * </p>
6321             *
6322             * @param groupId the group ID
6323             * @param status the status
6324             * @param start the lower bound of the range of message-boards messages
6325             * @param end the upper bound of the range of message-boards messages (not inclusive)
6326             * @return the range of matching message-boards messages that the user has permission to view
6327             * @throws SystemException if a system exception occurred
6328             */
6329            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6330                    int end) throws SystemException {
6331                    return filterFindByG_S(groupId, status, start, end, null);
6332            }
6333    
6334            /**
6335             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6336             *
6337             * <p>
6338             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6339             * </p>
6340             *
6341             * @param groupId the group ID
6342             * @param status the status
6343             * @param start the lower bound of the range of message-boards messages
6344             * @param end the upper bound of the range of message-boards messages (not inclusive)
6345             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6346             * @return the ordered range of matching message-boards messages that the user has permission to view
6347             * @throws SystemException if a system exception occurred
6348             */
6349            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6350                    int end, OrderByComparator orderByComparator) throws SystemException {
6351                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6352                            return findByG_S(groupId, status, start, end, orderByComparator);
6353                    }
6354    
6355                    StringBundler query = null;
6356    
6357                    if (orderByComparator != null) {
6358                            query = new StringBundler(4 +
6359                                            (orderByComparator.getOrderByFields().length * 3));
6360                    }
6361                    else {
6362                            query = new StringBundler(4);
6363                    }
6364    
6365                    if (getDB().isSupportsInlineDistinct()) {
6366                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6367                    }
6368                    else {
6369                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6370                    }
6371    
6372                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6373    
6374                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6375    
6376                    if (!getDB().isSupportsInlineDistinct()) {
6377                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6378                    }
6379    
6380                    if (orderByComparator != null) {
6381                            if (getDB().isSupportsInlineDistinct()) {
6382                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6383                                            orderByComparator);
6384                            }
6385                            else {
6386                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6387                                            orderByComparator);
6388                            }
6389                    }
6390    
6391                    else {
6392                            if (getDB().isSupportsInlineDistinct()) {
6393                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6394                            }
6395                            else {
6396                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6397                            }
6398                    }
6399    
6400                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6401                                    MBMessage.class.getName(),
6402                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6403    
6404                    Session session = null;
6405    
6406                    try {
6407                            session = openSession();
6408    
6409                            SQLQuery q = session.createSQLQuery(sql);
6410    
6411                            if (getDB().isSupportsInlineDistinct()) {
6412                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6413                            }
6414                            else {
6415                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6416                            }
6417    
6418                            QueryPos qPos = QueryPos.getInstance(q);
6419    
6420                            qPos.add(groupId);
6421    
6422                            qPos.add(status);
6423    
6424                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6425                    }
6426                    catch (Exception e) {
6427                            throw processException(e);
6428                    }
6429                    finally {
6430                            closeSession(session);
6431                    }
6432            }
6433    
6434            /**
6435             * 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;.
6436             *
6437             * @param messageId the primary key of the current message-boards message
6438             * @param groupId the group ID
6439             * @param status the status
6440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6441             * @return the previous, current, and next message-boards message
6442             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6443             * @throws SystemException if a system exception occurred
6444             */
6445            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6446                    long groupId, int status, OrderByComparator orderByComparator)
6447                    throws NoSuchMessageException, SystemException {
6448                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6449                            return findByG_S_PrevAndNext(messageId, groupId, status,
6450                                    orderByComparator);
6451                    }
6452    
6453                    MBMessage mbMessage = findByPrimaryKey(messageId);
6454    
6455                    Session session = null;
6456    
6457                    try {
6458                            session = openSession();
6459    
6460                            MBMessage[] array = new MBMessageImpl[3];
6461    
6462                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6463                                            status, orderByComparator, true);
6464    
6465                            array[1] = mbMessage;
6466    
6467                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6468                                            status, orderByComparator, false);
6469    
6470                            return array;
6471                    }
6472                    catch (Exception e) {
6473                            throw processException(e);
6474                    }
6475                    finally {
6476                            closeSession(session);
6477                    }
6478            }
6479    
6480            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6481                    MBMessage mbMessage, long groupId, int status,
6482                    OrderByComparator orderByComparator, boolean previous) {
6483                    StringBundler query = null;
6484    
6485                    if (orderByComparator != null) {
6486                            query = new StringBundler(6 +
6487                                            (orderByComparator.getOrderByFields().length * 6));
6488                    }
6489                    else {
6490                            query = new StringBundler(3);
6491                    }
6492    
6493                    if (getDB().isSupportsInlineDistinct()) {
6494                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6495                    }
6496                    else {
6497                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6498                    }
6499    
6500                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6501    
6502                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6503    
6504                    if (!getDB().isSupportsInlineDistinct()) {
6505                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6506                    }
6507    
6508                    if (orderByComparator != null) {
6509                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6510    
6511                            if (orderByConditionFields.length > 0) {
6512                                    query.append(WHERE_AND);
6513                            }
6514    
6515                            for (int i = 0; i < orderByConditionFields.length; i++) {
6516                                    if (getDB().isSupportsInlineDistinct()) {
6517                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6518                                    }
6519                                    else {
6520                                            query.append(_ORDER_BY_ENTITY_TABLE);
6521                                    }
6522    
6523                                    query.append(orderByConditionFields[i]);
6524    
6525                                    if ((i + 1) < orderByConditionFields.length) {
6526                                            if (orderByComparator.isAscending() ^ previous) {
6527                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6528                                            }
6529                                            else {
6530                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6531                                            }
6532                                    }
6533                                    else {
6534                                            if (orderByComparator.isAscending() ^ previous) {
6535                                                    query.append(WHERE_GREATER_THAN);
6536                                            }
6537                                            else {
6538                                                    query.append(WHERE_LESSER_THAN);
6539                                            }
6540                                    }
6541                            }
6542    
6543                            query.append(ORDER_BY_CLAUSE);
6544    
6545                            String[] orderByFields = orderByComparator.getOrderByFields();
6546    
6547                            for (int i = 0; i < orderByFields.length; i++) {
6548                                    if (getDB().isSupportsInlineDistinct()) {
6549                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6550                                    }
6551                                    else {
6552                                            query.append(_ORDER_BY_ENTITY_TABLE);
6553                                    }
6554    
6555                                    query.append(orderByFields[i]);
6556    
6557                                    if ((i + 1) < orderByFields.length) {
6558                                            if (orderByComparator.isAscending() ^ previous) {
6559                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6560                                            }
6561                                            else {
6562                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6563                                            }
6564                                    }
6565                                    else {
6566                                            if (orderByComparator.isAscending() ^ previous) {
6567                                                    query.append(ORDER_BY_ASC);
6568                                            }
6569                                            else {
6570                                                    query.append(ORDER_BY_DESC);
6571                                            }
6572                                    }
6573                            }
6574                    }
6575    
6576                    else {
6577                            if (getDB().isSupportsInlineDistinct()) {
6578                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6579                            }
6580                            else {
6581                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6582                            }
6583                    }
6584    
6585                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6586                                    MBMessage.class.getName(),
6587                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6588    
6589                    SQLQuery q = session.createSQLQuery(sql);
6590    
6591                    q.setFirstResult(0);
6592                    q.setMaxResults(2);
6593    
6594                    if (getDB().isSupportsInlineDistinct()) {
6595                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6596                    }
6597                    else {
6598                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6599                    }
6600    
6601                    QueryPos qPos = QueryPos.getInstance(q);
6602    
6603                    qPos.add(groupId);
6604    
6605                    qPos.add(status);
6606    
6607                    if (orderByComparator != null) {
6608                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6609    
6610                            for (Object value : values) {
6611                                    qPos.add(value);
6612                            }
6613                    }
6614    
6615                    List<MBMessage> list = q.list();
6616    
6617                    if (list.size() == 2) {
6618                            return list.get(1);
6619                    }
6620                    else {
6621                            return null;
6622                    }
6623            }
6624    
6625            /**
6626             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6627             *
6628             * @param companyId the company ID
6629             * @param status the status
6630             * @return the matching message-boards messages
6631             * @throws SystemException if a system exception occurred
6632             */
6633            public List<MBMessage> findByC_S(long companyId, int status)
6634                    throws SystemException {
6635                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6636                            QueryUtil.ALL_POS, null);
6637            }
6638    
6639            /**
6640             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6641             *
6642             * <p>
6643             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6644             * </p>
6645             *
6646             * @param companyId the company ID
6647             * @param status the status
6648             * @param start the lower bound of the range of message-boards messages
6649             * @param end the upper bound of the range of message-boards messages (not inclusive)
6650             * @return the range of matching message-boards messages
6651             * @throws SystemException if a system exception occurred
6652             */
6653            public List<MBMessage> findByC_S(long companyId, int status, int start,
6654                    int end) throws SystemException {
6655                    return findByC_S(companyId, status, start, end, null);
6656            }
6657    
6658            /**
6659             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6660             *
6661             * <p>
6662             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6663             * </p>
6664             *
6665             * @param companyId the company ID
6666             * @param status the status
6667             * @param start the lower bound of the range of message-boards messages
6668             * @param end the upper bound of the range of message-boards messages (not inclusive)
6669             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6670             * @return the ordered range of matching message-boards messages
6671             * @throws SystemException if a system exception occurred
6672             */
6673            public List<MBMessage> findByC_S(long companyId, int status, int start,
6674                    int end, OrderByComparator orderByComparator) throws SystemException {
6675                    FinderPath finderPath = null;
6676                    Object[] finderArgs = null;
6677    
6678                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6679                                    (orderByComparator == null)) {
6680                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6681                            finderArgs = new Object[] { companyId, status };
6682                    }
6683                    else {
6684                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6685                            finderArgs = new Object[] {
6686                                            companyId, status,
6687                                            
6688                                            start, end, orderByComparator
6689                                    };
6690                    }
6691    
6692                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6693                                    finderArgs, this);
6694    
6695                    if ((list != null) && !list.isEmpty()) {
6696                            for (MBMessage mbMessage : list) {
6697                                    if ((companyId != mbMessage.getCompanyId()) ||
6698                                                    (status != mbMessage.getStatus())) {
6699                                            list = null;
6700    
6701                                            break;
6702                                    }
6703                            }
6704                    }
6705    
6706                    if (list == null) {
6707                            StringBundler query = null;
6708    
6709                            if (orderByComparator != null) {
6710                                    query = new StringBundler(4 +
6711                                                    (orderByComparator.getOrderByFields().length * 3));
6712                            }
6713                            else {
6714                                    query = new StringBundler(4);
6715                            }
6716    
6717                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6718    
6719                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6720    
6721                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6722    
6723                            if (orderByComparator != null) {
6724                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6725                                            orderByComparator);
6726                            }
6727    
6728                            else {
6729                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6730                            }
6731    
6732                            String sql = query.toString();
6733    
6734                            Session session = null;
6735    
6736                            try {
6737                                    session = openSession();
6738    
6739                                    Query q = session.createQuery(sql);
6740    
6741                                    QueryPos qPos = QueryPos.getInstance(q);
6742    
6743                                    qPos.add(companyId);
6744    
6745                                    qPos.add(status);
6746    
6747                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6748                                                    end);
6749                            }
6750                            catch (Exception e) {
6751                                    throw processException(e);
6752                            }
6753                            finally {
6754                                    if (list == null) {
6755                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6756                                    }
6757                                    else {
6758                                            cacheResult(list);
6759    
6760                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6761                                    }
6762    
6763                                    closeSession(session);
6764                            }
6765                    }
6766    
6767                    return list;
6768            }
6769    
6770            /**
6771             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6772             *
6773             * @param companyId the company ID
6774             * @param status the status
6775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6776             * @return the first matching message-boards message
6777             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6778             * @throws SystemException if a system exception occurred
6779             */
6780            public MBMessage findByC_S_First(long companyId, int status,
6781                    OrderByComparator orderByComparator)
6782                    throws NoSuchMessageException, SystemException {
6783                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
6784                                    orderByComparator);
6785    
6786                    if (mbMessage != null) {
6787                            return mbMessage;
6788                    }
6789    
6790                    StringBundler msg = new StringBundler(6);
6791    
6792                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6793    
6794                    msg.append("companyId=");
6795                    msg.append(companyId);
6796    
6797                    msg.append(", status=");
6798                    msg.append(status);
6799    
6800                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6801    
6802                    throw new NoSuchMessageException(msg.toString());
6803            }
6804    
6805            /**
6806             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6807             *
6808             * @param companyId the company ID
6809             * @param status the status
6810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6811             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6812             * @throws SystemException if a system exception occurred
6813             */
6814            public MBMessage fetchByC_S_First(long companyId, int status,
6815                    OrderByComparator orderByComparator) throws SystemException {
6816                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
6817                                    orderByComparator);
6818    
6819                    if (!list.isEmpty()) {
6820                            return list.get(0);
6821                    }
6822    
6823                    return null;
6824            }
6825    
6826            /**
6827             * Returns the last 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 last matching message-boards message
6833             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6834             * @throws SystemException if a system exception occurred
6835             */
6836            public MBMessage findByC_S_Last(long companyId, int status,
6837                    OrderByComparator orderByComparator)
6838                    throws NoSuchMessageException, SystemException {
6839                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
6840                                    orderByComparator);
6841    
6842                    if (mbMessage != null) {
6843                            return mbMessage;
6844                    }
6845    
6846                    StringBundler msg = new StringBundler(6);
6847    
6848                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6849    
6850                    msg.append("companyId=");
6851                    msg.append(companyId);
6852    
6853                    msg.append(", status=");
6854                    msg.append(status);
6855    
6856                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6857    
6858                    throw new NoSuchMessageException(msg.toString());
6859            }
6860    
6861            /**
6862             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6863             *
6864             * @param companyId the company ID
6865             * @param status the status
6866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6867             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6868             * @throws SystemException if a system exception occurred
6869             */
6870            public MBMessage fetchByC_S_Last(long companyId, int status,
6871                    OrderByComparator orderByComparator) throws SystemException {
6872                    int count = countByC_S(companyId, status);
6873    
6874                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
6875                                    orderByComparator);
6876    
6877                    if (!list.isEmpty()) {
6878                            return list.get(0);
6879                    }
6880    
6881                    return null;
6882            }
6883    
6884            /**
6885             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6886             *
6887             * @param messageId the primary key of the current message-boards message
6888             * @param companyId the company ID
6889             * @param status the status
6890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6891             * @return the previous, current, and next message-boards message
6892             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6893             * @throws SystemException if a system exception occurred
6894             */
6895            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
6896                    int status, OrderByComparator orderByComparator)
6897                    throws NoSuchMessageException, SystemException {
6898                    MBMessage mbMessage = findByPrimaryKey(messageId);
6899    
6900                    Session session = null;
6901    
6902                    try {
6903                            session = openSession();
6904    
6905                            MBMessage[] array = new MBMessageImpl[3];
6906    
6907                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6908                                            status, orderByComparator, true);
6909    
6910                            array[1] = mbMessage;
6911    
6912                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6913                                            status, orderByComparator, false);
6914    
6915                            return array;
6916                    }
6917                    catch (Exception e) {
6918                            throw processException(e);
6919                    }
6920                    finally {
6921                            closeSession(session);
6922                    }
6923            }
6924    
6925            protected MBMessage getByC_S_PrevAndNext(Session session,
6926                    MBMessage mbMessage, long companyId, int status,
6927                    OrderByComparator orderByComparator, boolean previous) {
6928                    StringBundler query = null;
6929    
6930                    if (orderByComparator != null) {
6931                            query = new StringBundler(6 +
6932                                            (orderByComparator.getOrderByFields().length * 6));
6933                    }
6934                    else {
6935                            query = new StringBundler(3);
6936                    }
6937    
6938                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6939    
6940                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6941    
6942                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
6943    
6944                    if (orderByComparator != null) {
6945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6946    
6947                            if (orderByConditionFields.length > 0) {
6948                                    query.append(WHERE_AND);
6949                            }
6950    
6951                            for (int i = 0; i < orderByConditionFields.length; i++) {
6952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6953                                    query.append(orderByConditionFields[i]);
6954    
6955                                    if ((i + 1) < orderByConditionFields.length) {
6956                                            if (orderByComparator.isAscending() ^ previous) {
6957                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6958                                            }
6959                                            else {
6960                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6961                                            }
6962                                    }
6963                                    else {
6964                                            if (orderByComparator.isAscending() ^ previous) {
6965                                                    query.append(WHERE_GREATER_THAN);
6966                                            }
6967                                            else {
6968                                                    query.append(WHERE_LESSER_THAN);
6969                                            }
6970                                    }
6971                            }
6972    
6973                            query.append(ORDER_BY_CLAUSE);
6974    
6975                            String[] orderByFields = orderByComparator.getOrderByFields();
6976    
6977                            for (int i = 0; i < orderByFields.length; i++) {
6978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6979                                    query.append(orderByFields[i]);
6980    
6981                                    if ((i + 1) < orderByFields.length) {
6982                                            if (orderByComparator.isAscending() ^ previous) {
6983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6984                                            }
6985                                            else {
6986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6987                                            }
6988                                    }
6989                                    else {
6990                                            if (orderByComparator.isAscending() ^ previous) {
6991                                                    query.append(ORDER_BY_ASC);
6992                                            }
6993                                            else {
6994                                                    query.append(ORDER_BY_DESC);
6995                                            }
6996                                    }
6997                            }
6998                    }
6999    
7000                    else {
7001                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7002                    }
7003    
7004                    String sql = query.toString();
7005    
7006                    Query q = session.createQuery(sql);
7007    
7008                    q.setFirstResult(0);
7009                    q.setMaxResults(2);
7010    
7011                    QueryPos qPos = QueryPos.getInstance(q);
7012    
7013                    qPos.add(companyId);
7014    
7015                    qPos.add(status);
7016    
7017                    if (orderByComparator != null) {
7018                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7019    
7020                            for (Object value : values) {
7021                                    qPos.add(value);
7022                            }
7023                    }
7024    
7025                    List<MBMessage> list = q.list();
7026    
7027                    if (list.size() == 2) {
7028                            return list.get(1);
7029                    }
7030                    else {
7031                            return null;
7032                    }
7033            }
7034    
7035            /**
7036             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7037             *
7038             * @param userId the user ID
7039             * @param classNameId the class name ID
7040             * @return the matching message-boards messages
7041             * @throws SystemException if a system exception occurred
7042             */
7043            public List<MBMessage> findByU_C(long userId, long classNameId)
7044                    throws SystemException {
7045                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7046                            QueryUtil.ALL_POS, null);
7047            }
7048    
7049            /**
7050             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7051             *
7052             * <p>
7053             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7054             * </p>
7055             *
7056             * @param userId the user ID
7057             * @param classNameId the class name ID
7058             * @param start the lower bound of the range of message-boards messages
7059             * @param end the upper bound of the range of message-boards messages (not inclusive)
7060             * @return the range of matching message-boards messages
7061             * @throws SystemException if a system exception occurred
7062             */
7063            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7064                    int end) throws SystemException {
7065                    return findByU_C(userId, classNameId, start, end, null);
7066            }
7067    
7068            /**
7069             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7070             *
7071             * <p>
7072             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7073             * </p>
7074             *
7075             * @param userId the user ID
7076             * @param classNameId the class name ID
7077             * @param start the lower bound of the range of message-boards messages
7078             * @param end the upper bound of the range of message-boards messages (not inclusive)
7079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7080             * @return the ordered range of matching message-boards messages
7081             * @throws SystemException if a system exception occurred
7082             */
7083            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7084                    int end, OrderByComparator orderByComparator) throws SystemException {
7085                    FinderPath finderPath = null;
7086                    Object[] finderArgs = null;
7087    
7088                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7089                                    (orderByComparator == null)) {
7090                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7091                            finderArgs = new Object[] { userId, classNameId };
7092                    }
7093                    else {
7094                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7095                            finderArgs = new Object[] {
7096                                            userId, classNameId,
7097                                            
7098                                            start, end, orderByComparator
7099                                    };
7100                    }
7101    
7102                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7103                                    finderArgs, this);
7104    
7105                    if ((list != null) && !list.isEmpty()) {
7106                            for (MBMessage mbMessage : list) {
7107                                    if ((userId != mbMessage.getUserId()) ||
7108                                                    (classNameId != mbMessage.getClassNameId())) {
7109                                            list = null;
7110    
7111                                            break;
7112                                    }
7113                            }
7114                    }
7115    
7116                    if (list == null) {
7117                            StringBundler query = null;
7118    
7119                            if (orderByComparator != null) {
7120                                    query = new StringBundler(4 +
7121                                                    (orderByComparator.getOrderByFields().length * 3));
7122                            }
7123                            else {
7124                                    query = new StringBundler(4);
7125                            }
7126    
7127                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7128    
7129                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7130    
7131                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7132    
7133                            if (orderByComparator != null) {
7134                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7135                                            orderByComparator);
7136                            }
7137    
7138                            else {
7139                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7140                            }
7141    
7142                            String sql = query.toString();
7143    
7144                            Session session = null;
7145    
7146                            try {
7147                                    session = openSession();
7148    
7149                                    Query q = session.createQuery(sql);
7150    
7151                                    QueryPos qPos = QueryPos.getInstance(q);
7152    
7153                                    qPos.add(userId);
7154    
7155                                    qPos.add(classNameId);
7156    
7157                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7158                                                    end);
7159                            }
7160                            catch (Exception e) {
7161                                    throw processException(e);
7162                            }
7163                            finally {
7164                                    if (list == null) {
7165                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7166                                    }
7167                                    else {
7168                                            cacheResult(list);
7169    
7170                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7171                                    }
7172    
7173                                    closeSession(session);
7174                            }
7175                    }
7176    
7177                    return list;
7178            }
7179    
7180            /**
7181             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7182             *
7183             * @param userId the user ID
7184             * @param classNameId the class name ID
7185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7186             * @return the first matching message-boards message
7187             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7188             * @throws SystemException if a system exception occurred
7189             */
7190            public MBMessage findByU_C_First(long userId, long classNameId,
7191                    OrderByComparator orderByComparator)
7192                    throws NoSuchMessageException, SystemException {
7193                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7194                                    orderByComparator);
7195    
7196                    if (mbMessage != null) {
7197                            return mbMessage;
7198                    }
7199    
7200                    StringBundler msg = new StringBundler(6);
7201    
7202                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7203    
7204                    msg.append("userId=");
7205                    msg.append(userId);
7206    
7207                    msg.append(", classNameId=");
7208                    msg.append(classNameId);
7209    
7210                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7211    
7212                    throw new NoSuchMessageException(msg.toString());
7213            }
7214    
7215            /**
7216             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7217             *
7218             * @param userId the user ID
7219             * @param classNameId the class name ID
7220             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7221             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7222             * @throws SystemException if a system exception occurred
7223             */
7224            public MBMessage fetchByU_C_First(long userId, long classNameId,
7225                    OrderByComparator orderByComparator) throws SystemException {
7226                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7227                                    orderByComparator);
7228    
7229                    if (!list.isEmpty()) {
7230                            return list.get(0);
7231                    }
7232    
7233                    return null;
7234            }
7235    
7236            /**
7237             * Returns the last 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 last matching message-boards message
7243             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7244             * @throws SystemException if a system exception occurred
7245             */
7246            public MBMessage findByU_C_Last(long userId, long classNameId,
7247                    OrderByComparator orderByComparator)
7248                    throws NoSuchMessageException, SystemException {
7249                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7250                                    orderByComparator);
7251    
7252                    if (mbMessage != null) {
7253                            return mbMessage;
7254                    }
7255    
7256                    StringBundler msg = new StringBundler(6);
7257    
7258                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7259    
7260                    msg.append("userId=");
7261                    msg.append(userId);
7262    
7263                    msg.append(", classNameId=");
7264                    msg.append(classNameId);
7265    
7266                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7267    
7268                    throw new NoSuchMessageException(msg.toString());
7269            }
7270    
7271            /**
7272             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7273             *
7274             * @param userId the user ID
7275             * @param classNameId the class name ID
7276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7277             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7278             * @throws SystemException if a system exception occurred
7279             */
7280            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7281                    OrderByComparator orderByComparator) throws SystemException {
7282                    int count = countByU_C(userId, classNameId);
7283    
7284                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7285                                    orderByComparator);
7286    
7287                    if (!list.isEmpty()) {
7288                            return list.get(0);
7289                    }
7290    
7291                    return null;
7292            }
7293    
7294            /**
7295             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7296             *
7297             * @param messageId the primary key of the current message-boards message
7298             * @param userId the user ID
7299             * @param classNameId the class name ID
7300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7301             * @return the previous, current, and next message-boards message
7302             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7303             * @throws SystemException if a system exception occurred
7304             */
7305            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7306                    long classNameId, OrderByComparator orderByComparator)
7307                    throws NoSuchMessageException, SystemException {
7308                    MBMessage mbMessage = findByPrimaryKey(messageId);
7309    
7310                    Session session = null;
7311    
7312                    try {
7313                            session = openSession();
7314    
7315                            MBMessage[] array = new MBMessageImpl[3];
7316    
7317                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7318                                            classNameId, orderByComparator, true);
7319    
7320                            array[1] = mbMessage;
7321    
7322                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7323                                            classNameId, orderByComparator, false);
7324    
7325                            return array;
7326                    }
7327                    catch (Exception e) {
7328                            throw processException(e);
7329                    }
7330                    finally {
7331                            closeSession(session);
7332                    }
7333            }
7334    
7335            protected MBMessage getByU_C_PrevAndNext(Session session,
7336                    MBMessage mbMessage, long userId, long classNameId,
7337                    OrderByComparator orderByComparator, boolean previous) {
7338                    StringBundler query = null;
7339    
7340                    if (orderByComparator != null) {
7341                            query = new StringBundler(6 +
7342                                            (orderByComparator.getOrderByFields().length * 6));
7343                    }
7344                    else {
7345                            query = new StringBundler(3);
7346                    }
7347    
7348                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7349    
7350                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7351    
7352                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7353    
7354                    if (orderByComparator != null) {
7355                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7356    
7357                            if (orderByConditionFields.length > 0) {
7358                                    query.append(WHERE_AND);
7359                            }
7360    
7361                            for (int i = 0; i < orderByConditionFields.length; i++) {
7362                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7363                                    query.append(orderByConditionFields[i]);
7364    
7365                                    if ((i + 1) < orderByConditionFields.length) {
7366                                            if (orderByComparator.isAscending() ^ previous) {
7367                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7368                                            }
7369                                            else {
7370                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7371                                            }
7372                                    }
7373                                    else {
7374                                            if (orderByComparator.isAscending() ^ previous) {
7375                                                    query.append(WHERE_GREATER_THAN);
7376                                            }
7377                                            else {
7378                                                    query.append(WHERE_LESSER_THAN);
7379                                            }
7380                                    }
7381                            }
7382    
7383                            query.append(ORDER_BY_CLAUSE);
7384    
7385                            String[] orderByFields = orderByComparator.getOrderByFields();
7386    
7387                            for (int i = 0; i < orderByFields.length; i++) {
7388                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7389                                    query.append(orderByFields[i]);
7390    
7391                                    if ((i + 1) < orderByFields.length) {
7392                                            if (orderByComparator.isAscending() ^ previous) {
7393                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7394                                            }
7395                                            else {
7396                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7397                                            }
7398                                    }
7399                                    else {
7400                                            if (orderByComparator.isAscending() ^ previous) {
7401                                                    query.append(ORDER_BY_ASC);
7402                                            }
7403                                            else {
7404                                                    query.append(ORDER_BY_DESC);
7405                                            }
7406                                    }
7407                            }
7408                    }
7409    
7410                    else {
7411                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7412                    }
7413    
7414                    String sql = query.toString();
7415    
7416                    Query q = session.createQuery(sql);
7417    
7418                    q.setFirstResult(0);
7419                    q.setMaxResults(2);
7420    
7421                    QueryPos qPos = QueryPos.getInstance(q);
7422    
7423                    qPos.add(userId);
7424    
7425                    qPos.add(classNameId);
7426    
7427                    if (orderByComparator != null) {
7428                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7429    
7430                            for (Object value : values) {
7431                                    qPos.add(value);
7432                            }
7433                    }
7434    
7435                    List<MBMessage> list = q.list();
7436    
7437                    if (list.size() == 2) {
7438                            return list.get(1);
7439                    }
7440                    else {
7441                            return null;
7442                    }
7443            }
7444    
7445            /**
7446             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7447             *
7448             * <p>
7449             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7450             * </p>
7451             *
7452             * @param userId the user ID
7453             * @param classNameIds the class name IDs
7454             * @return the matching message-boards messages
7455             * @throws SystemException if a system exception occurred
7456             */
7457            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7458                    throws SystemException {
7459                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7460                            QueryUtil.ALL_POS, null);
7461            }
7462    
7463            /**
7464             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7465             *
7466             * <p>
7467             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7468             * </p>
7469             *
7470             * @param userId the user ID
7471             * @param classNameIds the class name IDs
7472             * @param start the lower bound of the range of message-boards messages
7473             * @param end the upper bound of the range of message-boards messages (not inclusive)
7474             * @return the range of matching message-boards messages
7475             * @throws SystemException if a system exception occurred
7476             */
7477            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7478                    int start, int end) throws SystemException {
7479                    return findByU_C(userId, classNameIds, start, end, null);
7480            }
7481    
7482            /**
7483             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7484             *
7485             * <p>
7486             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7487             * </p>
7488             *
7489             * @param userId the user ID
7490             * @param classNameIds the class name IDs
7491             * @param start the lower bound of the range of message-boards messages
7492             * @param end the upper bound of the range of message-boards messages (not inclusive)
7493             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7494             * @return the ordered range of matching message-boards messages
7495             * @throws SystemException if a system exception occurred
7496             */
7497            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7498                    int start, int end, OrderByComparator orderByComparator)
7499                    throws SystemException {
7500                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7501                    Object[] finderArgs = null;
7502    
7503                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7504                                    (orderByComparator == null)) {
7505                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7506                    }
7507                    else {
7508                            finderArgs = new Object[] {
7509                                            userId, StringUtil.merge(classNameIds),
7510                                            
7511                                            start, end, orderByComparator
7512                                    };
7513                    }
7514    
7515                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7516                                    finderArgs, this);
7517    
7518                    if ((list != null) && !list.isEmpty()) {
7519                            for (MBMessage mbMessage : list) {
7520                                    if ((userId != mbMessage.getUserId()) ||
7521                                                    !ArrayUtil.contains(classNameIds,
7522                                                            mbMessage.getClassNameId())) {
7523                                            list = null;
7524    
7525                                            break;
7526                                    }
7527                            }
7528                    }
7529    
7530                    if (list == null) {
7531                            StringBundler query = new StringBundler();
7532    
7533                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7534    
7535                            boolean conjunctionable = false;
7536    
7537                            if (conjunctionable) {
7538                                    query.append(WHERE_AND);
7539                            }
7540    
7541                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7542    
7543                            conjunctionable = true;
7544    
7545                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7546                                    if (conjunctionable) {
7547                                            query.append(WHERE_AND);
7548                                    }
7549    
7550                                    query.append(StringPool.OPEN_PARENTHESIS);
7551    
7552                                    for (int i = 0; i < classNameIds.length; i++) {
7553                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7554    
7555                                            if ((i + 1) < classNameIds.length) {
7556                                                    query.append(WHERE_OR);
7557                                            }
7558                                    }
7559    
7560                                    query.append(StringPool.CLOSE_PARENTHESIS);
7561    
7562                                    conjunctionable = true;
7563                            }
7564    
7565                            if (orderByComparator != null) {
7566                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7567                                            orderByComparator);
7568                            }
7569    
7570                            else {
7571                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7572                            }
7573    
7574                            String sql = query.toString();
7575    
7576                            Session session = null;
7577    
7578                            try {
7579                                    session = openSession();
7580    
7581                                    Query q = session.createQuery(sql);
7582    
7583                                    QueryPos qPos = QueryPos.getInstance(q);
7584    
7585                                    qPos.add(userId);
7586    
7587                                    if (classNameIds != null) {
7588                                            qPos.add(classNameIds);
7589                                    }
7590    
7591                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7592                                                    end);
7593                            }
7594                            catch (Exception e) {
7595                                    throw processException(e);
7596                            }
7597                            finally {
7598                                    if (list == null) {
7599                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7600                                    }
7601                                    else {
7602                                            cacheResult(list);
7603    
7604                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7605                                    }
7606    
7607                                    closeSession(session);
7608                            }
7609                    }
7610    
7611                    return list;
7612            }
7613    
7614            /**
7615             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7616             *
7617             * @param classNameId the class name ID
7618             * @param classPK the class p k
7619             * @return the matching message-boards messages
7620             * @throws SystemException if a system exception occurred
7621             */
7622            public List<MBMessage> findByC_C(long classNameId, long classPK)
7623                    throws SystemException {
7624                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
7625                            QueryUtil.ALL_POS, null);
7626            }
7627    
7628            /**
7629             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7630             *
7631             * <p>
7632             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7633             * </p>
7634             *
7635             * @param classNameId the class name ID
7636             * @param classPK the class p k
7637             * @param start the lower bound of the range of message-boards messages
7638             * @param end the upper bound of the range of message-boards messages (not inclusive)
7639             * @return the range of matching message-boards messages
7640             * @throws SystemException if a system exception occurred
7641             */
7642            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7643                    int end) throws SystemException {
7644                    return findByC_C(classNameId, classPK, start, end, null);
7645            }
7646    
7647            /**
7648             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7649             *
7650             * <p>
7651             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7652             * </p>
7653             *
7654             * @param classNameId the class name ID
7655             * @param classPK the class p k
7656             * @param start the lower bound of the range of message-boards messages
7657             * @param end the upper bound of the range of message-boards messages (not inclusive)
7658             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7659             * @return the ordered range of matching message-boards messages
7660             * @throws SystemException if a system exception occurred
7661             */
7662            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7663                    int end, OrderByComparator orderByComparator) throws SystemException {
7664                    FinderPath finderPath = null;
7665                    Object[] finderArgs = null;
7666    
7667                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7668                                    (orderByComparator == null)) {
7669                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
7670                            finderArgs = new Object[] { classNameId, classPK };
7671                    }
7672                    else {
7673                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
7674                            finderArgs = new Object[] {
7675                                            classNameId, classPK,
7676                                            
7677                                            start, end, orderByComparator
7678                                    };
7679                    }
7680    
7681                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7682                                    finderArgs, this);
7683    
7684                    if ((list != null) && !list.isEmpty()) {
7685                            for (MBMessage mbMessage : list) {
7686                                    if ((classNameId != mbMessage.getClassNameId()) ||
7687                                                    (classPK != mbMessage.getClassPK())) {
7688                                            list = null;
7689    
7690                                            break;
7691                                    }
7692                            }
7693                    }
7694    
7695                    if (list == null) {
7696                            StringBundler query = null;
7697    
7698                            if (orderByComparator != null) {
7699                                    query = new StringBundler(4 +
7700                                                    (orderByComparator.getOrderByFields().length * 3));
7701                            }
7702                            else {
7703                                    query = new StringBundler(4);
7704                            }
7705    
7706                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7707    
7708                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7709    
7710                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7711    
7712                            if (orderByComparator != null) {
7713                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7714                                            orderByComparator);
7715                            }
7716    
7717                            else {
7718                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7719                            }
7720    
7721                            String sql = query.toString();
7722    
7723                            Session session = null;
7724    
7725                            try {
7726                                    session = openSession();
7727    
7728                                    Query q = session.createQuery(sql);
7729    
7730                                    QueryPos qPos = QueryPos.getInstance(q);
7731    
7732                                    qPos.add(classNameId);
7733    
7734                                    qPos.add(classPK);
7735    
7736                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7737                                                    end);
7738                            }
7739                            catch (Exception e) {
7740                                    throw processException(e);
7741                            }
7742                            finally {
7743                                    if (list == null) {
7744                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7745                                    }
7746                                    else {
7747                                            cacheResult(list);
7748    
7749                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7750                                    }
7751    
7752                                    closeSession(session);
7753                            }
7754                    }
7755    
7756                    return list;
7757            }
7758    
7759            /**
7760             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7761             *
7762             * @param classNameId the class name ID
7763             * @param classPK the class p k
7764             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7765             * @return the first matching message-boards message
7766             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7767             * @throws SystemException if a system exception occurred
7768             */
7769            public MBMessage findByC_C_First(long classNameId, long classPK,
7770                    OrderByComparator orderByComparator)
7771                    throws NoSuchMessageException, SystemException {
7772                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
7773                                    orderByComparator);
7774    
7775                    if (mbMessage != null) {
7776                            return mbMessage;
7777                    }
7778    
7779                    StringBundler msg = new StringBundler(6);
7780    
7781                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7782    
7783                    msg.append("classNameId=");
7784                    msg.append(classNameId);
7785    
7786                    msg.append(", classPK=");
7787                    msg.append(classPK);
7788    
7789                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7790    
7791                    throw new NoSuchMessageException(msg.toString());
7792            }
7793    
7794            /**
7795             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7796             *
7797             * @param classNameId the class name ID
7798             * @param classPK the class p k
7799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7800             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7801             * @throws SystemException if a system exception occurred
7802             */
7803            public MBMessage fetchByC_C_First(long classNameId, long classPK,
7804                    OrderByComparator orderByComparator) throws SystemException {
7805                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
7806                                    orderByComparator);
7807    
7808                    if (!list.isEmpty()) {
7809                            return list.get(0);
7810                    }
7811    
7812                    return null;
7813            }
7814    
7815            /**
7816             * Returns the last 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 last matching message-boards message
7822             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7823             * @throws SystemException if a system exception occurred
7824             */
7825            public MBMessage findByC_C_Last(long classNameId, long classPK,
7826                    OrderByComparator orderByComparator)
7827                    throws NoSuchMessageException, SystemException {
7828                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
7829                                    orderByComparator);
7830    
7831                    if (mbMessage != null) {
7832                            return mbMessage;
7833                    }
7834    
7835                    StringBundler msg = new StringBundler(6);
7836    
7837                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7838    
7839                    msg.append("classNameId=");
7840                    msg.append(classNameId);
7841    
7842                    msg.append(", classPK=");
7843                    msg.append(classPK);
7844    
7845                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7846    
7847                    throw new NoSuchMessageException(msg.toString());
7848            }
7849    
7850            /**
7851             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7852             *
7853             * @param classNameId the class name ID
7854             * @param classPK the class p k
7855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7856             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7857             * @throws SystemException if a system exception occurred
7858             */
7859            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
7860                    OrderByComparator orderByComparator) throws SystemException {
7861                    int count = countByC_C(classNameId, classPK);
7862    
7863                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
7864                                    count, orderByComparator);
7865    
7866                    if (!list.isEmpty()) {
7867                            return list.get(0);
7868                    }
7869    
7870                    return null;
7871            }
7872    
7873            /**
7874             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7875             *
7876             * @param messageId the primary key of the current message-boards message
7877             * @param classNameId the class name ID
7878             * @param classPK the class p k
7879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7880             * @return the previous, current, and next message-boards message
7881             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7882             * @throws SystemException if a system exception occurred
7883             */
7884            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
7885                    long classPK, OrderByComparator orderByComparator)
7886                    throws NoSuchMessageException, SystemException {
7887                    MBMessage mbMessage = findByPrimaryKey(messageId);
7888    
7889                    Session session = null;
7890    
7891                    try {
7892                            session = openSession();
7893    
7894                            MBMessage[] array = new MBMessageImpl[3];
7895    
7896                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7897                                            classPK, orderByComparator, true);
7898    
7899                            array[1] = mbMessage;
7900    
7901                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7902                                            classPK, orderByComparator, false);
7903    
7904                            return array;
7905                    }
7906                    catch (Exception e) {
7907                            throw processException(e);
7908                    }
7909                    finally {
7910                            closeSession(session);
7911                    }
7912            }
7913    
7914            protected MBMessage getByC_C_PrevAndNext(Session session,
7915                    MBMessage mbMessage, long classNameId, long classPK,
7916                    OrderByComparator orderByComparator, boolean previous) {
7917                    StringBundler query = null;
7918    
7919                    if (orderByComparator != null) {
7920                            query = new StringBundler(6 +
7921                                            (orderByComparator.getOrderByFields().length * 6));
7922                    }
7923                    else {
7924                            query = new StringBundler(3);
7925                    }
7926    
7927                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7928    
7929                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7930    
7931                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7932    
7933                    if (orderByComparator != null) {
7934                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7935    
7936                            if (orderByConditionFields.length > 0) {
7937                                    query.append(WHERE_AND);
7938                            }
7939    
7940                            for (int i = 0; i < orderByConditionFields.length; i++) {
7941                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7942                                    query.append(orderByConditionFields[i]);
7943    
7944                                    if ((i + 1) < orderByConditionFields.length) {
7945                                            if (orderByComparator.isAscending() ^ previous) {
7946                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7947                                            }
7948                                            else {
7949                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7950                                            }
7951                                    }
7952                                    else {
7953                                            if (orderByComparator.isAscending() ^ previous) {
7954                                                    query.append(WHERE_GREATER_THAN);
7955                                            }
7956                                            else {
7957                                                    query.append(WHERE_LESSER_THAN);
7958                                            }
7959                                    }
7960                            }
7961    
7962                            query.append(ORDER_BY_CLAUSE);
7963    
7964                            String[] orderByFields = orderByComparator.getOrderByFields();
7965    
7966                            for (int i = 0; i < orderByFields.length; i++) {
7967                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7968                                    query.append(orderByFields[i]);
7969    
7970                                    if ((i + 1) < orderByFields.length) {
7971                                            if (orderByComparator.isAscending() ^ previous) {
7972                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7973                                            }
7974                                            else {
7975                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7976                                            }
7977                                    }
7978                                    else {
7979                                            if (orderByComparator.isAscending() ^ previous) {
7980                                                    query.append(ORDER_BY_ASC);
7981                                            }
7982                                            else {
7983                                                    query.append(ORDER_BY_DESC);
7984                                            }
7985                                    }
7986                            }
7987                    }
7988    
7989                    else {
7990                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7991                    }
7992    
7993                    String sql = query.toString();
7994    
7995                    Query q = session.createQuery(sql);
7996    
7997                    q.setFirstResult(0);
7998                    q.setMaxResults(2);
7999    
8000                    QueryPos qPos = QueryPos.getInstance(q);
8001    
8002                    qPos.add(classNameId);
8003    
8004                    qPos.add(classPK);
8005    
8006                    if (orderByComparator != null) {
8007                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8008    
8009                            for (Object value : values) {
8010                                    qPos.add(value);
8011                            }
8012                    }
8013    
8014                    List<MBMessage> list = q.list();
8015    
8016                    if (list.size() == 2) {
8017                            return list.get(1);
8018                    }
8019                    else {
8020                            return null;
8021                    }
8022            }
8023    
8024            /**
8025             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8026             *
8027             * @param threadId the thread ID
8028             * @param parentMessageId the parent message ID
8029             * @return the matching message-boards messages
8030             * @throws SystemException if a system exception occurred
8031             */
8032            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8033                    throws SystemException {
8034                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8035                            QueryUtil.ALL_POS, null);
8036            }
8037    
8038            /**
8039             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8040             *
8041             * <p>
8042             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8043             * </p>
8044             *
8045             * @param threadId the thread ID
8046             * @param parentMessageId the parent message ID
8047             * @param start the lower bound of the range of message-boards messages
8048             * @param end the upper bound of the range of message-boards messages (not inclusive)
8049             * @return the range of matching message-boards messages
8050             * @throws SystemException if a system exception occurred
8051             */
8052            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8053                    int start, int end) throws SystemException {
8054                    return findByT_P(threadId, parentMessageId, start, end, null);
8055            }
8056    
8057            /**
8058             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8059             *
8060             * <p>
8061             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8062             * </p>
8063             *
8064             * @param threadId the thread ID
8065             * @param parentMessageId the parent message ID
8066             * @param start the lower bound of the range of message-boards messages
8067             * @param end the upper bound of the range of message-boards messages (not inclusive)
8068             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8069             * @return the ordered range of matching message-boards messages
8070             * @throws SystemException if a system exception occurred
8071             */
8072            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8073                    int start, int end, OrderByComparator orderByComparator)
8074                    throws SystemException {
8075                    FinderPath finderPath = null;
8076                    Object[] finderArgs = null;
8077    
8078                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8079                                    (orderByComparator == null)) {
8080                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8081                            finderArgs = new Object[] { threadId, parentMessageId };
8082                    }
8083                    else {
8084                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8085                            finderArgs = new Object[] {
8086                                            threadId, parentMessageId,
8087                                            
8088                                            start, end, orderByComparator
8089                                    };
8090                    }
8091    
8092                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8093                                    finderArgs, this);
8094    
8095                    if ((list != null) && !list.isEmpty()) {
8096                            for (MBMessage mbMessage : list) {
8097                                    if ((threadId != mbMessage.getThreadId()) ||
8098                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8099                                            list = null;
8100    
8101                                            break;
8102                                    }
8103                            }
8104                    }
8105    
8106                    if (list == null) {
8107                            StringBundler query = null;
8108    
8109                            if (orderByComparator != null) {
8110                                    query = new StringBundler(4 +
8111                                                    (orderByComparator.getOrderByFields().length * 3));
8112                            }
8113                            else {
8114                                    query = new StringBundler(4);
8115                            }
8116    
8117                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8118    
8119                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8120    
8121                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8122    
8123                            if (orderByComparator != null) {
8124                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8125                                            orderByComparator);
8126                            }
8127    
8128                            else {
8129                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8130                            }
8131    
8132                            String sql = query.toString();
8133    
8134                            Session session = null;
8135    
8136                            try {
8137                                    session = openSession();
8138    
8139                                    Query q = session.createQuery(sql);
8140    
8141                                    QueryPos qPos = QueryPos.getInstance(q);
8142    
8143                                    qPos.add(threadId);
8144    
8145                                    qPos.add(parentMessageId);
8146    
8147                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8148                                                    end);
8149                            }
8150                            catch (Exception e) {
8151                                    throw processException(e);
8152                            }
8153                            finally {
8154                                    if (list == null) {
8155                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8156                                    }
8157                                    else {
8158                                            cacheResult(list);
8159    
8160                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8161                                    }
8162    
8163                                    closeSession(session);
8164                            }
8165                    }
8166    
8167                    return list;
8168            }
8169    
8170            /**
8171             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8172             *
8173             * @param threadId the thread ID
8174             * @param parentMessageId the parent message ID
8175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8176             * @return the first matching message-boards message
8177             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8178             * @throws SystemException if a system exception occurred
8179             */
8180            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8181                    OrderByComparator orderByComparator)
8182                    throws NoSuchMessageException, SystemException {
8183                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8184                                    orderByComparator);
8185    
8186                    if (mbMessage != null) {
8187                            return mbMessage;
8188                    }
8189    
8190                    StringBundler msg = new StringBundler(6);
8191    
8192                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8193    
8194                    msg.append("threadId=");
8195                    msg.append(threadId);
8196    
8197                    msg.append(", parentMessageId=");
8198                    msg.append(parentMessageId);
8199    
8200                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8201    
8202                    throw new NoSuchMessageException(msg.toString());
8203            }
8204    
8205            /**
8206             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8207             *
8208             * @param threadId the thread ID
8209             * @param parentMessageId the parent message ID
8210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8211             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8212             * @throws SystemException if a system exception occurred
8213             */
8214            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8215                    OrderByComparator orderByComparator) throws SystemException {
8216                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8217                                    orderByComparator);
8218    
8219                    if (!list.isEmpty()) {
8220                            return list.get(0);
8221                    }
8222    
8223                    return null;
8224            }
8225    
8226            /**
8227             * Returns the last 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 last matching message-boards message
8233             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8234             * @throws SystemException if a system exception occurred
8235             */
8236            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8237                    OrderByComparator orderByComparator)
8238                    throws NoSuchMessageException, SystemException {
8239                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8240                                    orderByComparator);
8241    
8242                    if (mbMessage != null) {
8243                            return mbMessage;
8244                    }
8245    
8246                    StringBundler msg = new StringBundler(6);
8247    
8248                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8249    
8250                    msg.append("threadId=");
8251                    msg.append(threadId);
8252    
8253                    msg.append(", parentMessageId=");
8254                    msg.append(parentMessageId);
8255    
8256                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8257    
8258                    throw new NoSuchMessageException(msg.toString());
8259            }
8260    
8261            /**
8262             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8263             *
8264             * @param threadId the thread ID
8265             * @param parentMessageId the parent message ID
8266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8267             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8268             * @throws SystemException if a system exception occurred
8269             */
8270            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8271                    OrderByComparator orderByComparator) throws SystemException {
8272                    int count = countByT_P(threadId, parentMessageId);
8273    
8274                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8275                                    count, orderByComparator);
8276    
8277                    if (!list.isEmpty()) {
8278                            return list.get(0);
8279                    }
8280    
8281                    return null;
8282            }
8283    
8284            /**
8285             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8286             *
8287             * @param messageId the primary key of the current message-boards message
8288             * @param threadId the thread ID
8289             * @param parentMessageId the parent message ID
8290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8291             * @return the previous, current, and next message-boards message
8292             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8293             * @throws SystemException if a system exception occurred
8294             */
8295            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8296                    long parentMessageId, OrderByComparator orderByComparator)
8297                    throws NoSuchMessageException, SystemException {
8298                    MBMessage mbMessage = findByPrimaryKey(messageId);
8299    
8300                    Session session = null;
8301    
8302                    try {
8303                            session = openSession();
8304    
8305                            MBMessage[] array = new MBMessageImpl[3];
8306    
8307                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8308                                            parentMessageId, orderByComparator, true);
8309    
8310                            array[1] = mbMessage;
8311    
8312                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8313                                            parentMessageId, orderByComparator, false);
8314    
8315                            return array;
8316                    }
8317                    catch (Exception e) {
8318                            throw processException(e);
8319                    }
8320                    finally {
8321                            closeSession(session);
8322                    }
8323            }
8324    
8325            protected MBMessage getByT_P_PrevAndNext(Session session,
8326                    MBMessage mbMessage, long threadId, long parentMessageId,
8327                    OrderByComparator orderByComparator, boolean previous) {
8328                    StringBundler query = null;
8329    
8330                    if (orderByComparator != null) {
8331                            query = new StringBundler(6 +
8332                                            (orderByComparator.getOrderByFields().length * 6));
8333                    }
8334                    else {
8335                            query = new StringBundler(3);
8336                    }
8337    
8338                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8339    
8340                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8341    
8342                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8343    
8344                    if (orderByComparator != null) {
8345                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8346    
8347                            if (orderByConditionFields.length > 0) {
8348                                    query.append(WHERE_AND);
8349                            }
8350    
8351                            for (int i = 0; i < orderByConditionFields.length; i++) {
8352                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8353                                    query.append(orderByConditionFields[i]);
8354    
8355                                    if ((i + 1) < orderByConditionFields.length) {
8356                                            if (orderByComparator.isAscending() ^ previous) {
8357                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8358                                            }
8359                                            else {
8360                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8361                                            }
8362                                    }
8363                                    else {
8364                                            if (orderByComparator.isAscending() ^ previous) {
8365                                                    query.append(WHERE_GREATER_THAN);
8366                                            }
8367                                            else {
8368                                                    query.append(WHERE_LESSER_THAN);
8369                                            }
8370                                    }
8371                            }
8372    
8373                            query.append(ORDER_BY_CLAUSE);
8374    
8375                            String[] orderByFields = orderByComparator.getOrderByFields();
8376    
8377                            for (int i = 0; i < orderByFields.length; i++) {
8378                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8379                                    query.append(orderByFields[i]);
8380    
8381                                    if ((i + 1) < orderByFields.length) {
8382                                            if (orderByComparator.isAscending() ^ previous) {
8383                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8384                                            }
8385                                            else {
8386                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8387                                            }
8388                                    }
8389                                    else {
8390                                            if (orderByComparator.isAscending() ^ previous) {
8391                                                    query.append(ORDER_BY_ASC);
8392                                            }
8393                                            else {
8394                                                    query.append(ORDER_BY_DESC);
8395                                            }
8396                                    }
8397                            }
8398                    }
8399    
8400                    else {
8401                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8402                    }
8403    
8404                    String sql = query.toString();
8405    
8406                    Query q = session.createQuery(sql);
8407    
8408                    q.setFirstResult(0);
8409                    q.setMaxResults(2);
8410    
8411                    QueryPos qPos = QueryPos.getInstance(q);
8412    
8413                    qPos.add(threadId);
8414    
8415                    qPos.add(parentMessageId);
8416    
8417                    if (orderByComparator != null) {
8418                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8419    
8420                            for (Object value : values) {
8421                                    qPos.add(value);
8422                            }
8423                    }
8424    
8425                    List<MBMessage> list = q.list();
8426    
8427                    if (list.size() == 2) {
8428                            return list.get(1);
8429                    }
8430                    else {
8431                            return null;
8432                    }
8433            }
8434    
8435            /**
8436             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
8437             *
8438             * @param threadId the thread ID
8439             * @param answer the answer
8440             * @return the matching message-boards messages
8441             * @throws SystemException if a system exception occurred
8442             */
8443            public List<MBMessage> findByT_A(long threadId, boolean answer)
8444                    throws SystemException {
8445                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
8446                            QueryUtil.ALL_POS, null);
8447            }
8448    
8449            /**
8450             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8451             *
8452             * <p>
8453             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8454             * </p>
8455             *
8456             * @param threadId the thread ID
8457             * @param answer the answer
8458             * @param start the lower bound of the range of message-boards messages
8459             * @param end the upper bound of the range of message-boards messages (not inclusive)
8460             * @return the range of matching message-boards messages
8461             * @throws SystemException if a system exception occurred
8462             */
8463            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8464                    int end) throws SystemException {
8465                    return findByT_A(threadId, answer, start, end, null);
8466            }
8467    
8468            /**
8469             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8470             *
8471             * <p>
8472             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8473             * </p>
8474             *
8475             * @param threadId the thread ID
8476             * @param answer the answer
8477             * @param start the lower bound of the range of message-boards messages
8478             * @param end the upper bound of the range of message-boards messages (not inclusive)
8479             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8480             * @return the ordered range of matching message-boards messages
8481             * @throws SystemException if a system exception occurred
8482             */
8483            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8484                    int end, OrderByComparator orderByComparator) throws SystemException {
8485                    FinderPath finderPath = null;
8486                    Object[] finderArgs = null;
8487    
8488                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8489                                    (orderByComparator == null)) {
8490                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
8491                            finderArgs = new Object[] { threadId, answer };
8492                    }
8493                    else {
8494                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
8495                            finderArgs = new Object[] {
8496                                            threadId, answer,
8497                                            
8498                                            start, end, orderByComparator
8499                                    };
8500                    }
8501    
8502                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8503                                    finderArgs, this);
8504    
8505                    if ((list != null) && !list.isEmpty()) {
8506                            for (MBMessage mbMessage : list) {
8507                                    if ((threadId != mbMessage.getThreadId()) ||
8508                                                    (answer != mbMessage.getAnswer())) {
8509                                            list = null;
8510    
8511                                            break;
8512                                    }
8513                            }
8514                    }
8515    
8516                    if (list == null) {
8517                            StringBundler query = null;
8518    
8519                            if (orderByComparator != null) {
8520                                    query = new StringBundler(4 +
8521                                                    (orderByComparator.getOrderByFields().length * 3));
8522                            }
8523                            else {
8524                                    query = new StringBundler(4);
8525                            }
8526    
8527                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8528    
8529                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
8530    
8531                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8532    
8533                            if (orderByComparator != null) {
8534                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8535                                            orderByComparator);
8536                            }
8537    
8538                            else {
8539                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8540                            }
8541    
8542                            String sql = query.toString();
8543    
8544                            Session session = null;
8545    
8546                            try {
8547                                    session = openSession();
8548    
8549                                    Query q = session.createQuery(sql);
8550    
8551                                    QueryPos qPos = QueryPos.getInstance(q);
8552    
8553                                    qPos.add(threadId);
8554    
8555                                    qPos.add(answer);
8556    
8557                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8558                                                    end);
8559                            }
8560                            catch (Exception e) {
8561                                    throw processException(e);
8562                            }
8563                            finally {
8564                                    if (list == null) {
8565                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8566                                    }
8567                                    else {
8568                                            cacheResult(list);
8569    
8570                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8571                                    }
8572    
8573                                    closeSession(session);
8574                            }
8575                    }
8576    
8577                    return list;
8578            }
8579    
8580            /**
8581             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8582             *
8583             * @param threadId the thread ID
8584             * @param answer the answer
8585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8586             * @return the first matching message-boards message
8587             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8588             * @throws SystemException if a system exception occurred
8589             */
8590            public MBMessage findByT_A_First(long threadId, boolean answer,
8591                    OrderByComparator orderByComparator)
8592                    throws NoSuchMessageException, SystemException {
8593                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
8594                                    orderByComparator);
8595    
8596                    if (mbMessage != null) {
8597                            return mbMessage;
8598                    }
8599    
8600                    StringBundler msg = new StringBundler(6);
8601    
8602                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8603    
8604                    msg.append("threadId=");
8605                    msg.append(threadId);
8606    
8607                    msg.append(", answer=");
8608                    msg.append(answer);
8609    
8610                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8611    
8612                    throw new NoSuchMessageException(msg.toString());
8613            }
8614    
8615            /**
8616             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8617             *
8618             * @param threadId the thread ID
8619             * @param answer the answer
8620             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8621             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8622             * @throws SystemException if a system exception occurred
8623             */
8624            public MBMessage fetchByT_A_First(long threadId, boolean answer,
8625                    OrderByComparator orderByComparator) throws SystemException {
8626                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
8627                                    orderByComparator);
8628    
8629                    if (!list.isEmpty()) {
8630                            return list.get(0);
8631                    }
8632    
8633                    return null;
8634            }
8635    
8636            /**
8637             * Returns the last 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 last matching message-boards message
8643             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8644             * @throws SystemException if a system exception occurred
8645             */
8646            public MBMessage findByT_A_Last(long threadId, boolean answer,
8647                    OrderByComparator orderByComparator)
8648                    throws NoSuchMessageException, SystemException {
8649                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
8650                                    orderByComparator);
8651    
8652                    if (mbMessage != null) {
8653                            return mbMessage;
8654                    }
8655    
8656                    StringBundler msg = new StringBundler(6);
8657    
8658                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8659    
8660                    msg.append("threadId=");
8661                    msg.append(threadId);
8662    
8663                    msg.append(", answer=");
8664                    msg.append(answer);
8665    
8666                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8667    
8668                    throw new NoSuchMessageException(msg.toString());
8669            }
8670    
8671            /**
8672             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8673             *
8674             * @param threadId the thread ID
8675             * @param answer the answer
8676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8677             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8678             * @throws SystemException if a system exception occurred
8679             */
8680            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
8681                    OrderByComparator orderByComparator) throws SystemException {
8682                    int count = countByT_A(threadId, answer);
8683    
8684                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
8685                                    orderByComparator);
8686    
8687                    if (!list.isEmpty()) {
8688                            return list.get(0);
8689                    }
8690    
8691                    return null;
8692            }
8693    
8694            /**
8695             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8696             *
8697             * @param messageId the primary key of the current message-boards message
8698             * @param threadId the thread ID
8699             * @param answer the answer
8700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8701             * @return the previous, current, and next message-boards message
8702             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8703             * @throws SystemException if a system exception occurred
8704             */
8705            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
8706                    boolean answer, OrderByComparator orderByComparator)
8707                    throws NoSuchMessageException, SystemException {
8708                    MBMessage mbMessage = findByPrimaryKey(messageId);
8709    
8710                    Session session = null;
8711    
8712                    try {
8713                            session = openSession();
8714    
8715                            MBMessage[] array = new MBMessageImpl[3];
8716    
8717                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8718                                            answer, orderByComparator, true);
8719    
8720                            array[1] = mbMessage;
8721    
8722                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8723                                            answer, orderByComparator, false);
8724    
8725                            return array;
8726                    }
8727                    catch (Exception e) {
8728                            throw processException(e);
8729                    }
8730                    finally {
8731                            closeSession(session);
8732                    }
8733            }
8734    
8735            protected MBMessage getByT_A_PrevAndNext(Session session,
8736                    MBMessage mbMessage, long threadId, boolean answer,
8737                    OrderByComparator orderByComparator, boolean previous) {
8738                    StringBundler query = null;
8739    
8740                    if (orderByComparator != null) {
8741                            query = new StringBundler(6 +
8742                                            (orderByComparator.getOrderByFields().length * 6));
8743                    }
8744                    else {
8745                            query = new StringBundler(3);
8746                    }
8747    
8748                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8749    
8750                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
8751    
8752                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8753    
8754                    if (orderByComparator != null) {
8755                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8756    
8757                            if (orderByConditionFields.length > 0) {
8758                                    query.append(WHERE_AND);
8759                            }
8760    
8761                            for (int i = 0; i < orderByConditionFields.length; i++) {
8762                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8763                                    query.append(orderByConditionFields[i]);
8764    
8765                                    if ((i + 1) < orderByConditionFields.length) {
8766                                            if (orderByComparator.isAscending() ^ previous) {
8767                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8768                                            }
8769                                            else {
8770                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8771                                            }
8772                                    }
8773                                    else {
8774                                            if (orderByComparator.isAscending() ^ previous) {
8775                                                    query.append(WHERE_GREATER_THAN);
8776                                            }
8777                                            else {
8778                                                    query.append(WHERE_LESSER_THAN);
8779                                            }
8780                                    }
8781                            }
8782    
8783                            query.append(ORDER_BY_CLAUSE);
8784    
8785                            String[] orderByFields = orderByComparator.getOrderByFields();
8786    
8787                            for (int i = 0; i < orderByFields.length; i++) {
8788                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8789                                    query.append(orderByFields[i]);
8790    
8791                                    if ((i + 1) < orderByFields.length) {
8792                                            if (orderByComparator.isAscending() ^ previous) {
8793                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8794                                            }
8795                                            else {
8796                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8797                                            }
8798                                    }
8799                                    else {
8800                                            if (orderByComparator.isAscending() ^ previous) {
8801                                                    query.append(ORDER_BY_ASC);
8802                                            }
8803                                            else {
8804                                                    query.append(ORDER_BY_DESC);
8805                                            }
8806                                    }
8807                            }
8808                    }
8809    
8810                    else {
8811                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8812                    }
8813    
8814                    String sql = query.toString();
8815    
8816                    Query q = session.createQuery(sql);
8817    
8818                    q.setFirstResult(0);
8819                    q.setMaxResults(2);
8820    
8821                    QueryPos qPos = QueryPos.getInstance(q);
8822    
8823                    qPos.add(threadId);
8824    
8825                    qPos.add(answer);
8826    
8827                    if (orderByComparator != null) {
8828                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8829    
8830                            for (Object value : values) {
8831                                    qPos.add(value);
8832                            }
8833                    }
8834    
8835                    List<MBMessage> list = q.list();
8836    
8837                    if (list.size() == 2) {
8838                            return list.get(1);
8839                    }
8840                    else {
8841                            return null;
8842                    }
8843            }
8844    
8845            /**
8846             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
8847             *
8848             * @param threadId the thread ID
8849             * @param status the status
8850             * @return the matching message-boards messages
8851             * @throws SystemException if a system exception occurred
8852             */
8853            public List<MBMessage> findByT_S(long threadId, int status)
8854                    throws SystemException {
8855                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
8856                            QueryUtil.ALL_POS, null);
8857            }
8858    
8859            /**
8860             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
8861             *
8862             * <p>
8863             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8864             * </p>
8865             *
8866             * @param threadId the thread ID
8867             * @param status the status
8868             * @param start the lower bound of the range of message-boards messages
8869             * @param end the upper bound of the range of message-boards messages (not inclusive)
8870             * @return the range of matching message-boards messages
8871             * @throws SystemException if a system exception occurred
8872             */
8873            public List<MBMessage> findByT_S(long threadId, int status, int start,
8874                    int end) throws SystemException {
8875                    return findByT_S(threadId, status, start, end, null);
8876            }
8877    
8878            /**
8879             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
8880             *
8881             * <p>
8882             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8883             * </p>
8884             *
8885             * @param threadId the thread ID
8886             * @param status the status
8887             * @param start the lower bound of the range of message-boards messages
8888             * @param end the upper bound of the range of message-boards messages (not inclusive)
8889             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8890             * @return the ordered range of matching message-boards messages
8891             * @throws SystemException if a system exception occurred
8892             */
8893            public List<MBMessage> findByT_S(long threadId, int status, int start,
8894                    int end, OrderByComparator orderByComparator) throws SystemException {
8895                    FinderPath finderPath = null;
8896                    Object[] finderArgs = null;
8897    
8898                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8899                                    (orderByComparator == null)) {
8900                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
8901                            finderArgs = new Object[] { threadId, status };
8902                    }
8903                    else {
8904                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
8905                            finderArgs = new Object[] {
8906                                            threadId, status,
8907                                            
8908                                            start, end, orderByComparator
8909                                    };
8910                    }
8911    
8912                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8913                                    finderArgs, this);
8914    
8915                    if ((list != null) && !list.isEmpty()) {
8916                            for (MBMessage mbMessage : list) {
8917                                    if ((threadId != mbMessage.getThreadId()) ||
8918                                                    (status != mbMessage.getStatus())) {
8919                                            list = null;
8920    
8921                                            break;
8922                                    }
8923                            }
8924                    }
8925    
8926                    if (list == null) {
8927                            StringBundler query = null;
8928    
8929                            if (orderByComparator != null) {
8930                                    query = new StringBundler(4 +
8931                                                    (orderByComparator.getOrderByFields().length * 3));
8932                            }
8933                            else {
8934                                    query = new StringBundler(4);
8935                            }
8936    
8937                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8938    
8939                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
8940    
8941                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
8942    
8943                            if (orderByComparator != null) {
8944                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8945                                            orderByComparator);
8946                            }
8947    
8948                            else {
8949                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8950                            }
8951    
8952                            String sql = query.toString();
8953    
8954                            Session session = null;
8955    
8956                            try {
8957                                    session = openSession();
8958    
8959                                    Query q = session.createQuery(sql);
8960    
8961                                    QueryPos qPos = QueryPos.getInstance(q);
8962    
8963                                    qPos.add(threadId);
8964    
8965                                    qPos.add(status);
8966    
8967                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8968                                                    end);
8969                            }
8970                            catch (Exception e) {
8971                                    throw processException(e);
8972                            }
8973                            finally {
8974                                    if (list == null) {
8975                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8976                                    }
8977                                    else {
8978                                            cacheResult(list);
8979    
8980                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8981                                    }
8982    
8983                                    closeSession(session);
8984                            }
8985                    }
8986    
8987                    return list;
8988            }
8989    
8990            /**
8991             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8992             *
8993             * @param threadId the thread ID
8994             * @param status the status
8995             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8996             * @return the first matching message-boards message
8997             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8998             * @throws SystemException if a system exception occurred
8999             */
9000            public MBMessage findByT_S_First(long threadId, int status,
9001                    OrderByComparator orderByComparator)
9002                    throws NoSuchMessageException, SystemException {
9003                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9004                                    orderByComparator);
9005    
9006                    if (mbMessage != null) {
9007                            return mbMessage;
9008                    }
9009    
9010                    StringBundler msg = new StringBundler(6);
9011    
9012                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9013    
9014                    msg.append("threadId=");
9015                    msg.append(threadId);
9016    
9017                    msg.append(", status=");
9018                    msg.append(status);
9019    
9020                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9021    
9022                    throw new NoSuchMessageException(msg.toString());
9023            }
9024    
9025            /**
9026             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9027             *
9028             * @param threadId the thread ID
9029             * @param status the status
9030             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9031             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9032             * @throws SystemException if a system exception occurred
9033             */
9034            public MBMessage fetchByT_S_First(long threadId, int status,
9035                    OrderByComparator orderByComparator) throws SystemException {
9036                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9037                                    orderByComparator);
9038    
9039                    if (!list.isEmpty()) {
9040                            return list.get(0);
9041                    }
9042    
9043                    return null;
9044            }
9045    
9046            /**
9047             * Returns the last 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 last matching message-boards message
9053             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9054             * @throws SystemException if a system exception occurred
9055             */
9056            public MBMessage findByT_S_Last(long threadId, int status,
9057                    OrderByComparator orderByComparator)
9058                    throws NoSuchMessageException, SystemException {
9059                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9060                                    orderByComparator);
9061    
9062                    if (mbMessage != null) {
9063                            return mbMessage;
9064                    }
9065    
9066                    StringBundler msg = new StringBundler(6);
9067    
9068                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9069    
9070                    msg.append("threadId=");
9071                    msg.append(threadId);
9072    
9073                    msg.append(", status=");
9074                    msg.append(status);
9075    
9076                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9077    
9078                    throw new NoSuchMessageException(msg.toString());
9079            }
9080    
9081            /**
9082             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9083             *
9084             * @param threadId the thread ID
9085             * @param status the status
9086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9087             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9088             * @throws SystemException if a system exception occurred
9089             */
9090            public MBMessage fetchByT_S_Last(long threadId, int status,
9091                    OrderByComparator orderByComparator) throws SystemException {
9092                    int count = countByT_S(threadId, status);
9093    
9094                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9095                                    orderByComparator);
9096    
9097                    if (!list.isEmpty()) {
9098                            return list.get(0);
9099                    }
9100    
9101                    return null;
9102            }
9103    
9104            /**
9105             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9106             *
9107             * @param messageId the primary key of the current message-boards message
9108             * @param threadId the thread ID
9109             * @param status the status
9110             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9111             * @return the previous, current, and next message-boards message
9112             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9113             * @throws SystemException if a system exception occurred
9114             */
9115            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9116                    int status, OrderByComparator orderByComparator)
9117                    throws NoSuchMessageException, SystemException {
9118                    MBMessage mbMessage = findByPrimaryKey(messageId);
9119    
9120                    Session session = null;
9121    
9122                    try {
9123                            session = openSession();
9124    
9125                            MBMessage[] array = new MBMessageImpl[3];
9126    
9127                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9128                                            status, orderByComparator, true);
9129    
9130                            array[1] = mbMessage;
9131    
9132                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9133                                            status, orderByComparator, false);
9134    
9135                            return array;
9136                    }
9137                    catch (Exception e) {
9138                            throw processException(e);
9139                    }
9140                    finally {
9141                            closeSession(session);
9142                    }
9143            }
9144    
9145            protected MBMessage getByT_S_PrevAndNext(Session session,
9146                    MBMessage mbMessage, long threadId, int status,
9147                    OrderByComparator orderByComparator, boolean previous) {
9148                    StringBundler query = null;
9149    
9150                    if (orderByComparator != null) {
9151                            query = new StringBundler(6 +
9152                                            (orderByComparator.getOrderByFields().length * 6));
9153                    }
9154                    else {
9155                            query = new StringBundler(3);
9156                    }
9157    
9158                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9159    
9160                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
9161    
9162                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
9163    
9164                    if (orderByComparator != null) {
9165                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9166    
9167                            if (orderByConditionFields.length > 0) {
9168                                    query.append(WHERE_AND);
9169                            }
9170    
9171                            for (int i = 0; i < orderByConditionFields.length; i++) {
9172                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9173                                    query.append(orderByConditionFields[i]);
9174    
9175                                    if ((i + 1) < orderByConditionFields.length) {
9176                                            if (orderByComparator.isAscending() ^ previous) {
9177                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9178                                            }
9179                                            else {
9180                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9181                                            }
9182                                    }
9183                                    else {
9184                                            if (orderByComparator.isAscending() ^ previous) {
9185                                                    query.append(WHERE_GREATER_THAN);
9186                                            }
9187                                            else {
9188                                                    query.append(WHERE_LESSER_THAN);
9189                                            }
9190                                    }
9191                            }
9192    
9193                            query.append(ORDER_BY_CLAUSE);
9194    
9195                            String[] orderByFields = orderByComparator.getOrderByFields();
9196    
9197                            for (int i = 0; i < orderByFields.length; i++) {
9198                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9199                                    query.append(orderByFields[i]);
9200    
9201                                    if ((i + 1) < orderByFields.length) {
9202                                            if (orderByComparator.isAscending() ^ previous) {
9203                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9204                                            }
9205                                            else {
9206                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9207                                            }
9208                                    }
9209                                    else {
9210                                            if (orderByComparator.isAscending() ^ previous) {
9211                                                    query.append(ORDER_BY_ASC);
9212                                            }
9213                                            else {
9214                                                    query.append(ORDER_BY_DESC);
9215                                            }
9216                                    }
9217                            }
9218                    }
9219    
9220                    else {
9221                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9222                    }
9223    
9224                    String sql = query.toString();
9225    
9226                    Query q = session.createQuery(sql);
9227    
9228                    q.setFirstResult(0);
9229                    q.setMaxResults(2);
9230    
9231                    QueryPos qPos = QueryPos.getInstance(q);
9232    
9233                    qPos.add(threadId);
9234    
9235                    qPos.add(status);
9236    
9237                    if (orderByComparator != null) {
9238                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9239    
9240                            for (Object value : values) {
9241                                    qPos.add(value);
9242                            }
9243                    }
9244    
9245                    List<MBMessage> list = q.list();
9246    
9247                    if (list.size() == 2) {
9248                            return list.get(1);
9249                    }
9250                    else {
9251                            return null;
9252                    }
9253            }
9254    
9255            /**
9256             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9257             *
9258             * @param threadId the thread ID
9259             * @param status the status
9260             * @return the matching message-boards messages
9261             * @throws SystemException if a system exception occurred
9262             */
9263            public List<MBMessage> findByTR_S(long threadId, int status)
9264                    throws SystemException {
9265                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
9266                            QueryUtil.ALL_POS, null);
9267            }
9268    
9269            /**
9270             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9271             *
9272             * <p>
9273             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9274             * </p>
9275             *
9276             * @param threadId the thread ID
9277             * @param status the status
9278             * @param start the lower bound of the range of message-boards messages
9279             * @param end the upper bound of the range of message-boards messages (not inclusive)
9280             * @return the range of matching message-boards messages
9281             * @throws SystemException if a system exception occurred
9282             */
9283            public List<MBMessage> findByTR_S(long threadId, int status, int start,
9284                    int end) throws SystemException {
9285                    return findByTR_S(threadId, status, start, end, null);
9286            }
9287    
9288            /**
9289             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9290             *
9291             * <p>
9292             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9293             * </p>
9294             *
9295             * @param threadId the thread ID
9296             * @param status the status
9297             * @param start the lower bound of the range of message-boards messages
9298             * @param end the upper bound of the range of message-boards messages (not inclusive)
9299             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9300             * @return the ordered range of matching message-boards messages
9301             * @throws SystemException if a system exception occurred
9302             */
9303            public List<MBMessage> findByTR_S(long threadId, int status, int start,
9304                    int end, OrderByComparator orderByComparator) throws SystemException {
9305                    FinderPath finderPath = null;
9306                    Object[] finderArgs = null;
9307    
9308                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9309                                    (orderByComparator == null)) {
9310                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
9311                            finderArgs = new Object[] { threadId, status };
9312                    }
9313                    else {
9314                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
9315                            finderArgs = new Object[] {
9316                                            threadId, status,
9317                                            
9318                                            start, end, orderByComparator
9319                                    };
9320                    }
9321    
9322                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9323                                    finderArgs, this);
9324    
9325                    if ((list != null) && !list.isEmpty()) {
9326                            for (MBMessage mbMessage : list) {
9327                                    if ((threadId != mbMessage.getThreadId()) ||
9328                                                    (status != mbMessage.getStatus())) {
9329                                            list = null;
9330    
9331                                            break;
9332                                    }
9333                            }
9334                    }
9335    
9336                    if (list == null) {
9337                            StringBundler query = null;
9338    
9339                            if (orderByComparator != null) {
9340                                    query = new StringBundler(4 +
9341                                                    (orderByComparator.getOrderByFields().length * 3));
9342                            }
9343                            else {
9344                                    query = new StringBundler(4);
9345                            }
9346    
9347                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9348    
9349                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
9350    
9351                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
9352    
9353                            if (orderByComparator != null) {
9354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9355                                            orderByComparator);
9356                            }
9357    
9358                            else {
9359                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9360                            }
9361    
9362                            String sql = query.toString();
9363    
9364                            Session session = null;
9365    
9366                            try {
9367                                    session = openSession();
9368    
9369                                    Query q = session.createQuery(sql);
9370    
9371                                    QueryPos qPos = QueryPos.getInstance(q);
9372    
9373                                    qPos.add(threadId);
9374    
9375                                    qPos.add(status);
9376    
9377                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9378                                                    end);
9379                            }
9380                            catch (Exception e) {
9381                                    throw processException(e);
9382                            }
9383                            finally {
9384                                    if (list == null) {
9385                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9386                                    }
9387                                    else {
9388                                            cacheResult(list);
9389    
9390                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9391                                    }
9392    
9393                                    closeSession(session);
9394                            }
9395                    }
9396    
9397                    return list;
9398            }
9399    
9400            /**
9401             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9402             *
9403             * @param threadId the thread ID
9404             * @param status the status
9405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9406             * @return the first matching message-boards message
9407             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9408             * @throws SystemException if a system exception occurred
9409             */
9410            public MBMessage findByTR_S_First(long threadId, int status,
9411                    OrderByComparator orderByComparator)
9412                    throws NoSuchMessageException, SystemException {
9413                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
9414                                    orderByComparator);
9415    
9416                    if (mbMessage != null) {
9417                            return mbMessage;
9418                    }
9419    
9420                    StringBundler msg = new StringBundler(6);
9421    
9422                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9423    
9424                    msg.append("threadId=");
9425                    msg.append(threadId);
9426    
9427                    msg.append(", status=");
9428                    msg.append(status);
9429    
9430                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9431    
9432                    throw new NoSuchMessageException(msg.toString());
9433            }
9434    
9435            /**
9436             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9437             *
9438             * @param threadId the thread ID
9439             * @param status the status
9440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9441             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9442             * @throws SystemException if a system exception occurred
9443             */
9444            public MBMessage fetchByTR_S_First(long threadId, int status,
9445                    OrderByComparator orderByComparator) throws SystemException {
9446                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
9447                                    orderByComparator);
9448    
9449                    if (!list.isEmpty()) {
9450                            return list.get(0);
9451                    }
9452    
9453                    return null;
9454            }
9455    
9456            /**
9457             * Returns the last 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 last matching message-boards message
9463             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9464             * @throws SystemException if a system exception occurred
9465             */
9466            public MBMessage findByTR_S_Last(long threadId, int status,
9467                    OrderByComparator orderByComparator)
9468                    throws NoSuchMessageException, SystemException {
9469                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
9470                                    orderByComparator);
9471    
9472                    if (mbMessage != null) {
9473                            return mbMessage;
9474                    }
9475    
9476                    StringBundler msg = new StringBundler(6);
9477    
9478                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9479    
9480                    msg.append("threadId=");
9481                    msg.append(threadId);
9482    
9483                    msg.append(", status=");
9484                    msg.append(status);
9485    
9486                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9487    
9488                    throw new NoSuchMessageException(msg.toString());
9489            }
9490    
9491            /**
9492             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9493             *
9494             * @param threadId the thread ID
9495             * @param status the status
9496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9497             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9498             * @throws SystemException if a system exception occurred
9499             */
9500            public MBMessage fetchByTR_S_Last(long threadId, int status,
9501                    OrderByComparator orderByComparator) throws SystemException {
9502                    int count = countByTR_S(threadId, status);
9503    
9504                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
9505                                    orderByComparator);
9506    
9507                    if (!list.isEmpty()) {
9508                            return list.get(0);
9509                    }
9510    
9511                    return null;
9512            }
9513    
9514            /**
9515             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9516             *
9517             * @param messageId the primary key of the current message-boards message
9518             * @param threadId the thread ID
9519             * @param status the status
9520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9521             * @return the previous, current, and next message-boards message
9522             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9523             * @throws SystemException if a system exception occurred
9524             */
9525            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
9526                    int status, OrderByComparator orderByComparator)
9527                    throws NoSuchMessageException, SystemException {
9528                    MBMessage mbMessage = findByPrimaryKey(messageId);
9529    
9530                    Session session = null;
9531    
9532                    try {
9533                            session = openSession();
9534    
9535                            MBMessage[] array = new MBMessageImpl[3];
9536    
9537                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
9538                                            status, orderByComparator, true);
9539    
9540                            array[1] = mbMessage;
9541    
9542                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
9543                                            status, orderByComparator, false);
9544    
9545                            return array;
9546                    }
9547                    catch (Exception e) {
9548                            throw processException(e);
9549                    }
9550                    finally {
9551                            closeSession(session);
9552                    }
9553            }
9554    
9555            protected MBMessage getByTR_S_PrevAndNext(Session session,
9556                    MBMessage mbMessage, long threadId, int status,
9557                    OrderByComparator orderByComparator, boolean previous) {
9558                    StringBundler query = null;
9559    
9560                    if (orderByComparator != null) {
9561                            query = new StringBundler(6 +
9562                                            (orderByComparator.getOrderByFields().length * 6));
9563                    }
9564                    else {
9565                            query = new StringBundler(3);
9566                    }
9567    
9568                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9569    
9570                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
9571    
9572                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
9573    
9574                    if (orderByComparator != null) {
9575                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9576    
9577                            if (orderByConditionFields.length > 0) {
9578                                    query.append(WHERE_AND);
9579                            }
9580    
9581                            for (int i = 0; i < orderByConditionFields.length; i++) {
9582                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9583                                    query.append(orderByConditionFields[i]);
9584    
9585                                    if ((i + 1) < orderByConditionFields.length) {
9586                                            if (orderByComparator.isAscending() ^ previous) {
9587                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9588                                            }
9589                                            else {
9590                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9591                                            }
9592                                    }
9593                                    else {
9594                                            if (orderByComparator.isAscending() ^ previous) {
9595                                                    query.append(WHERE_GREATER_THAN);
9596                                            }
9597                                            else {
9598                                                    query.append(WHERE_LESSER_THAN);
9599                                            }
9600                                    }
9601                            }
9602    
9603                            query.append(ORDER_BY_CLAUSE);
9604    
9605                            String[] orderByFields = orderByComparator.getOrderByFields();
9606    
9607                            for (int i = 0; i < orderByFields.length; i++) {
9608                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9609                                    query.append(orderByFields[i]);
9610    
9611                                    if ((i + 1) < orderByFields.length) {
9612                                            if (orderByComparator.isAscending() ^ previous) {
9613                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9614                                            }
9615                                            else {
9616                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9617                                            }
9618                                    }
9619                                    else {
9620                                            if (orderByComparator.isAscending() ^ previous) {
9621                                                    query.append(ORDER_BY_ASC);
9622                                            }
9623                                            else {
9624                                                    query.append(ORDER_BY_DESC);
9625                                            }
9626                                    }
9627                            }
9628                    }
9629    
9630                    else {
9631                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9632                    }
9633    
9634                    String sql = query.toString();
9635    
9636                    Query q = session.createQuery(sql);
9637    
9638                    q.setFirstResult(0);
9639                    q.setMaxResults(2);
9640    
9641                    QueryPos qPos = QueryPos.getInstance(q);
9642    
9643                    qPos.add(threadId);
9644    
9645                    qPos.add(status);
9646    
9647                    if (orderByComparator != null) {
9648                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9649    
9650                            for (Object value : values) {
9651                                    qPos.add(value);
9652                            }
9653                    }
9654    
9655                    List<MBMessage> list = q.list();
9656    
9657                    if (list.size() == 2) {
9658                            return list.get(1);
9659                    }
9660                    else {
9661                            return null;
9662                    }
9663            }
9664    
9665            /**
9666             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9667             *
9668             * @param groupId the group ID
9669             * @param userId the user ID
9670             * @param status the status
9671             * @return the matching message-boards messages
9672             * @throws SystemException if a system exception occurred
9673             */
9674            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
9675                    throws SystemException {
9676                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
9677                            QueryUtil.ALL_POS, null);
9678            }
9679    
9680            /**
9681             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9682             *
9683             * <p>
9684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9685             * </p>
9686             *
9687             * @param groupId the group ID
9688             * @param userId the user ID
9689             * @param status the status
9690             * @param start the lower bound of the range of message-boards messages
9691             * @param end the upper bound of the range of message-boards messages (not inclusive)
9692             * @return the range of 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                    int start, int end) throws SystemException {
9697                    return findByG_U_S(groupId, userId, status, start, end, null);
9698            }
9699    
9700            /**
9701             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9702             *
9703             * <p>
9704             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9705             * </p>
9706             *
9707             * @param groupId the group ID
9708             * @param userId the user ID
9709             * @param status the status
9710             * @param start the lower bound of the range of message-boards messages
9711             * @param end the upper bound of the range of message-boards messages (not inclusive)
9712             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9713             * @return the ordered 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, OrderByComparator orderByComparator)
9718                    throws SystemException {
9719                    FinderPath finderPath = null;
9720                    Object[] finderArgs = null;
9721    
9722                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9723                                    (orderByComparator == null)) {
9724                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
9725                            finderArgs = new Object[] { groupId, userId, status };
9726                    }
9727                    else {
9728                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
9729                            finderArgs = new Object[] {
9730                                            groupId, userId, status,
9731                                            
9732                                            start, end, orderByComparator
9733                                    };
9734                    }
9735    
9736                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9737                                    finderArgs, this);
9738    
9739                    if ((list != null) && !list.isEmpty()) {
9740                            for (MBMessage mbMessage : list) {
9741                                    if ((groupId != mbMessage.getGroupId()) ||
9742                                                    (userId != mbMessage.getUserId()) ||
9743                                                    (status != mbMessage.getStatus())) {
9744                                            list = null;
9745    
9746                                            break;
9747                                    }
9748                            }
9749                    }
9750    
9751                    if (list == null) {
9752                            StringBundler query = null;
9753    
9754                            if (orderByComparator != null) {
9755                                    query = new StringBundler(5 +
9756                                                    (orderByComparator.getOrderByFields().length * 3));
9757                            }
9758                            else {
9759                                    query = new StringBundler(5);
9760                            }
9761    
9762                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9763    
9764                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9765    
9766                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9767    
9768                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9769    
9770                            if (orderByComparator != null) {
9771                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9772                                            orderByComparator);
9773                            }
9774    
9775                            else {
9776                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9777                            }
9778    
9779                            String sql = query.toString();
9780    
9781                            Session session = null;
9782    
9783                            try {
9784                                    session = openSession();
9785    
9786                                    Query q = session.createQuery(sql);
9787    
9788                                    QueryPos qPos = QueryPos.getInstance(q);
9789    
9790                                    qPos.add(groupId);
9791    
9792                                    qPos.add(userId);
9793    
9794                                    qPos.add(status);
9795    
9796                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9797                                                    end);
9798                            }
9799                            catch (Exception e) {
9800                                    throw processException(e);
9801                            }
9802                            finally {
9803                                    if (list == null) {
9804                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9805                                    }
9806                                    else {
9807                                            cacheResult(list);
9808    
9809                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9810                                    }
9811    
9812                                    closeSession(session);
9813                            }
9814                    }
9815    
9816                    return list;
9817            }
9818    
9819            /**
9820             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9821             *
9822             * @param groupId the group ID
9823             * @param userId the user ID
9824             * @param status the status
9825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9826             * @return the first matching message-boards message
9827             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9828             * @throws SystemException if a system exception occurred
9829             */
9830            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
9831                    OrderByComparator orderByComparator)
9832                    throws NoSuchMessageException, SystemException {
9833                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
9834                                    orderByComparator);
9835    
9836                    if (mbMessage != null) {
9837                            return mbMessage;
9838                    }
9839    
9840                    StringBundler msg = new StringBundler(8);
9841    
9842                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9843    
9844                    msg.append("groupId=");
9845                    msg.append(groupId);
9846    
9847                    msg.append(", userId=");
9848                    msg.append(userId);
9849    
9850                    msg.append(", status=");
9851                    msg.append(status);
9852    
9853                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9854    
9855                    throw new NoSuchMessageException(msg.toString());
9856            }
9857    
9858            /**
9859             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9860             *
9861             * @param groupId the group ID
9862             * @param userId the user ID
9863             * @param status the status
9864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9865             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9866             * @throws SystemException if a system exception occurred
9867             */
9868            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
9869                    OrderByComparator orderByComparator) throws SystemException {
9870                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
9871                                    orderByComparator);
9872    
9873                    if (!list.isEmpty()) {
9874                            return list.get(0);
9875                    }
9876    
9877                    return null;
9878            }
9879    
9880            /**
9881             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9882             *
9883             * @param groupId the group ID
9884             * @param userId the user ID
9885             * @param status the status
9886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9887             * @return the last matching message-boards message
9888             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9889             * @throws SystemException if a system exception occurred
9890             */
9891            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
9892                    OrderByComparator orderByComparator)
9893                    throws NoSuchMessageException, SystemException {
9894                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
9895                                    orderByComparator);
9896    
9897                    if (mbMessage != null) {
9898                            return mbMessage;
9899                    }
9900    
9901                    StringBundler msg = new StringBundler(8);
9902    
9903                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9904    
9905                    msg.append("groupId=");
9906                    msg.append(groupId);
9907    
9908                    msg.append(", userId=");
9909                    msg.append(userId);
9910    
9911                    msg.append(", status=");
9912                    msg.append(status);
9913    
9914                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9915    
9916                    throw new NoSuchMessageException(msg.toString());
9917            }
9918    
9919            /**
9920             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9921             *
9922             * @param groupId the group ID
9923             * @param userId the user ID
9924             * @param status the status
9925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9926             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9927             * @throws SystemException if a system exception occurred
9928             */
9929            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
9930                    OrderByComparator orderByComparator) throws SystemException {
9931                    int count = countByG_U_S(groupId, userId, status);
9932    
9933                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
9934                                    count, orderByComparator);
9935    
9936                    if (!list.isEmpty()) {
9937                            return list.get(0);
9938                    }
9939    
9940                    return null;
9941            }
9942    
9943            /**
9944             * 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;.
9945             *
9946             * @param messageId the primary key of the current message-boards message
9947             * @param groupId the group ID
9948             * @param userId the user ID
9949             * @param status the status
9950             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9951             * @return the previous, current, and next message-boards message
9952             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9953             * @throws SystemException if a system exception occurred
9954             */
9955            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
9956                    long userId, int status, OrderByComparator orderByComparator)
9957                    throws NoSuchMessageException, SystemException {
9958                    MBMessage mbMessage = findByPrimaryKey(messageId);
9959    
9960                    Session session = null;
9961    
9962                    try {
9963                            session = openSession();
9964    
9965                            MBMessage[] array = new MBMessageImpl[3];
9966    
9967                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9968                                            userId, status, orderByComparator, true);
9969    
9970                            array[1] = mbMessage;
9971    
9972                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9973                                            userId, status, orderByComparator, false);
9974    
9975                            return array;
9976                    }
9977                    catch (Exception e) {
9978                            throw processException(e);
9979                    }
9980                    finally {
9981                            closeSession(session);
9982                    }
9983            }
9984    
9985            protected MBMessage getByG_U_S_PrevAndNext(Session session,
9986                    MBMessage mbMessage, long groupId, long userId, int status,
9987                    OrderByComparator orderByComparator, boolean previous) {
9988                    StringBundler query = null;
9989    
9990                    if (orderByComparator != null) {
9991                            query = new StringBundler(6 +
9992                                            (orderByComparator.getOrderByFields().length * 6));
9993                    }
9994                    else {
9995                            query = new StringBundler(3);
9996                    }
9997    
9998                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9999    
10000                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10001    
10002                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10003    
10004                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10005    
10006                    if (orderByComparator != null) {
10007                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10008    
10009                            if (orderByConditionFields.length > 0) {
10010                                    query.append(WHERE_AND);
10011                            }
10012    
10013                            for (int i = 0; i < orderByConditionFields.length; i++) {
10014                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10015                                    query.append(orderByConditionFields[i]);
10016    
10017                                    if ((i + 1) < orderByConditionFields.length) {
10018                                            if (orderByComparator.isAscending() ^ previous) {
10019                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10020                                            }
10021                                            else {
10022                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10023                                            }
10024                                    }
10025                                    else {
10026                                            if (orderByComparator.isAscending() ^ previous) {
10027                                                    query.append(WHERE_GREATER_THAN);
10028                                            }
10029                                            else {
10030                                                    query.append(WHERE_LESSER_THAN);
10031                                            }
10032                                    }
10033                            }
10034    
10035                            query.append(ORDER_BY_CLAUSE);
10036    
10037                            String[] orderByFields = orderByComparator.getOrderByFields();
10038    
10039                            for (int i = 0; i < orderByFields.length; i++) {
10040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10041                                    query.append(orderByFields[i]);
10042    
10043                                    if ((i + 1) < orderByFields.length) {
10044                                            if (orderByComparator.isAscending() ^ previous) {
10045                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10046                                            }
10047                                            else {
10048                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10049                                            }
10050                                    }
10051                                    else {
10052                                            if (orderByComparator.isAscending() ^ previous) {
10053                                                    query.append(ORDER_BY_ASC);
10054                                            }
10055                                            else {
10056                                                    query.append(ORDER_BY_DESC);
10057                                            }
10058                                    }
10059                            }
10060                    }
10061    
10062                    else {
10063                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10064                    }
10065    
10066                    String sql = query.toString();
10067    
10068                    Query q = session.createQuery(sql);
10069    
10070                    q.setFirstResult(0);
10071                    q.setMaxResults(2);
10072    
10073                    QueryPos qPos = QueryPos.getInstance(q);
10074    
10075                    qPos.add(groupId);
10076    
10077                    qPos.add(userId);
10078    
10079                    qPos.add(status);
10080    
10081                    if (orderByComparator != null) {
10082                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10083    
10084                            for (Object value : values) {
10085                                    qPos.add(value);
10086                            }
10087                    }
10088    
10089                    List<MBMessage> list = q.list();
10090    
10091                    if (list.size() == 2) {
10092                            return list.get(1);
10093                    }
10094                    else {
10095                            return null;
10096                    }
10097            }
10098    
10099            /**
10100             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
10101             *
10102             * @param groupId the group ID
10103             * @param userId the user ID
10104             * @param status the status
10105             * @return the matching message-boards messages that the user has permission to view
10106             * @throws SystemException if a system exception occurred
10107             */
10108            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10109                    int status) throws SystemException {
10110                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10111                            QueryUtil.ALL_POS, null);
10112            }
10113    
10114            /**
10115             * 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;.
10116             *
10117             * <p>
10118             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10119             * </p>
10120             *
10121             * @param groupId the group ID
10122             * @param userId the user ID
10123             * @param status the status
10124             * @param start the lower bound of the range of message-boards messages
10125             * @param end the upper bound of the range of message-boards messages (not inclusive)
10126             * @return the range of 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, int start, int end) throws SystemException {
10131                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
10132            }
10133    
10134            /**
10135             * 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;.
10136             *
10137             * <p>
10138             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10139             * </p>
10140             *
10141             * @param groupId the group ID
10142             * @param userId the user ID
10143             * @param status the status
10144             * @param start the lower bound of the range of message-boards messages
10145             * @param end the upper bound of the range of message-boards messages (not inclusive)
10146             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10147             * @return the ordered 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, OrderByComparator orderByComparator)
10152                    throws SystemException {
10153                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10154                            return findByG_U_S(groupId, userId, status, start, end,
10155                                    orderByComparator);
10156                    }
10157    
10158                    StringBundler query = null;
10159    
10160                    if (orderByComparator != null) {
10161                            query = new StringBundler(5 +
10162                                            (orderByComparator.getOrderByFields().length * 3));
10163                    }
10164                    else {
10165                            query = new StringBundler(5);
10166                    }
10167    
10168                    if (getDB().isSupportsInlineDistinct()) {
10169                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10170                    }
10171                    else {
10172                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10173                    }
10174    
10175                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10176    
10177                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10178    
10179                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10180    
10181                    if (!getDB().isSupportsInlineDistinct()) {
10182                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10183                    }
10184    
10185                    if (orderByComparator != null) {
10186                            if (getDB().isSupportsInlineDistinct()) {
10187                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10188                                            orderByComparator);
10189                            }
10190                            else {
10191                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10192                                            orderByComparator);
10193                            }
10194                    }
10195    
10196                    else {
10197                            if (getDB().isSupportsInlineDistinct()) {
10198                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10199                            }
10200                            else {
10201                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10202                            }
10203                    }
10204    
10205                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10206                                    MBMessage.class.getName(),
10207                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10208    
10209                    Session session = null;
10210    
10211                    try {
10212                            session = openSession();
10213    
10214                            SQLQuery q = session.createSQLQuery(sql);
10215    
10216                            if (getDB().isSupportsInlineDistinct()) {
10217                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10218                            }
10219                            else {
10220                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10221                            }
10222    
10223                            QueryPos qPos = QueryPos.getInstance(q);
10224    
10225                            qPos.add(groupId);
10226    
10227                            qPos.add(userId);
10228    
10229                            qPos.add(status);
10230    
10231                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
10232                    }
10233                    catch (Exception e) {
10234                            throw processException(e);
10235                    }
10236                    finally {
10237                            closeSession(session);
10238                    }
10239            }
10240    
10241            /**
10242             * 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;.
10243             *
10244             * @param messageId the primary key of the current message-boards message
10245             * @param groupId the group ID
10246             * @param userId the user ID
10247             * @param status the status
10248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10249             * @return the previous, current, and next message-boards message
10250             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10251             * @throws SystemException if a system exception occurred
10252             */
10253            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
10254                    long groupId, long userId, int status,
10255                    OrderByComparator orderByComparator)
10256                    throws NoSuchMessageException, SystemException {
10257                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10258                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
10259                                    orderByComparator);
10260                    }
10261    
10262                    MBMessage mbMessage = findByPrimaryKey(messageId);
10263    
10264                    Session session = null;
10265    
10266                    try {
10267                            session = openSession();
10268    
10269                            MBMessage[] array = new MBMessageImpl[3];
10270    
10271                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
10272                                            groupId, userId, status, orderByComparator, true);
10273    
10274                            array[1] = mbMessage;
10275    
10276                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
10277                                            groupId, userId, status, orderByComparator, false);
10278    
10279                            return array;
10280                    }
10281                    catch (Exception e) {
10282                            throw processException(e);
10283                    }
10284                    finally {
10285                            closeSession(session);
10286                    }
10287            }
10288    
10289            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
10290                    MBMessage mbMessage, long groupId, long userId, int status,
10291                    OrderByComparator orderByComparator, boolean previous) {
10292                    StringBundler query = null;
10293    
10294                    if (orderByComparator != null) {
10295                            query = new StringBundler(6 +
10296                                            (orderByComparator.getOrderByFields().length * 6));
10297                    }
10298                    else {
10299                            query = new StringBundler(3);
10300                    }
10301    
10302                    if (getDB().isSupportsInlineDistinct()) {
10303                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10304                    }
10305                    else {
10306                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10307                    }
10308    
10309                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10310    
10311                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10312    
10313                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10314    
10315                    if (!getDB().isSupportsInlineDistinct()) {
10316                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10317                    }
10318    
10319                    if (orderByComparator != null) {
10320                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10321    
10322                            if (orderByConditionFields.length > 0) {
10323                                    query.append(WHERE_AND);
10324                            }
10325    
10326                            for (int i = 0; i < orderByConditionFields.length; i++) {
10327                                    if (getDB().isSupportsInlineDistinct()) {
10328                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10329                                    }
10330                                    else {
10331                                            query.append(_ORDER_BY_ENTITY_TABLE);
10332                                    }
10333    
10334                                    query.append(orderByConditionFields[i]);
10335    
10336                                    if ((i + 1) < orderByConditionFields.length) {
10337                                            if (orderByComparator.isAscending() ^ previous) {
10338                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10339                                            }
10340                                            else {
10341                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10342                                            }
10343                                    }
10344                                    else {
10345                                            if (orderByComparator.isAscending() ^ previous) {
10346                                                    query.append(WHERE_GREATER_THAN);
10347                                            }
10348                                            else {
10349                                                    query.append(WHERE_LESSER_THAN);
10350                                            }
10351                                    }
10352                            }
10353    
10354                            query.append(ORDER_BY_CLAUSE);
10355    
10356                            String[] orderByFields = orderByComparator.getOrderByFields();
10357    
10358                            for (int i = 0; i < orderByFields.length; i++) {
10359                                    if (getDB().isSupportsInlineDistinct()) {
10360                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10361                                    }
10362                                    else {
10363                                            query.append(_ORDER_BY_ENTITY_TABLE);
10364                                    }
10365    
10366                                    query.append(orderByFields[i]);
10367    
10368                                    if ((i + 1) < orderByFields.length) {
10369                                            if (orderByComparator.isAscending() ^ previous) {
10370                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10371                                            }
10372                                            else {
10373                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10374                                            }
10375                                    }
10376                                    else {
10377                                            if (orderByComparator.isAscending() ^ previous) {
10378                                                    query.append(ORDER_BY_ASC);
10379                                            }
10380                                            else {
10381                                                    query.append(ORDER_BY_DESC);
10382                                            }
10383                                    }
10384                            }
10385                    }
10386    
10387                    else {
10388                            if (getDB().isSupportsInlineDistinct()) {
10389                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10390                            }
10391                            else {
10392                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10393                            }
10394                    }
10395    
10396                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10397                                    MBMessage.class.getName(),
10398                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10399    
10400                    SQLQuery q = session.createSQLQuery(sql);
10401    
10402                    q.setFirstResult(0);
10403                    q.setMaxResults(2);
10404    
10405                    if (getDB().isSupportsInlineDistinct()) {
10406                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10407                    }
10408                    else {
10409                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10410                    }
10411    
10412                    QueryPos qPos = QueryPos.getInstance(q);
10413    
10414                    qPos.add(groupId);
10415    
10416                    qPos.add(userId);
10417    
10418                    qPos.add(status);
10419    
10420                    if (orderByComparator != null) {
10421                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10422    
10423                            for (Object value : values) {
10424                                    qPos.add(value);
10425                            }
10426                    }
10427    
10428                    List<MBMessage> list = q.list();
10429    
10430                    if (list.size() == 2) {
10431                            return list.get(1);
10432                    }
10433                    else {
10434                            return null;
10435                    }
10436            }
10437    
10438            /**
10439             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10440             *
10441             * @param groupId the group ID
10442             * @param categoryId the category ID
10443             * @param threadId the thread ID
10444             * @return the matching message-boards messages
10445             * @throws SystemException if a system exception occurred
10446             */
10447            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10448                    long threadId) throws SystemException {
10449                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
10450                            QueryUtil.ALL_POS, null);
10451            }
10452    
10453            /**
10454             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10455             *
10456             * <p>
10457             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10458             * </p>
10459             *
10460             * @param groupId the group ID
10461             * @param categoryId the category ID
10462             * @param threadId the thread ID
10463             * @param start the lower bound of the range of message-boards messages
10464             * @param end the upper bound of the range of message-boards messages (not inclusive)
10465             * @return the range of 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, int start, int end) throws SystemException {
10470                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
10471            }
10472    
10473            /**
10474             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10475             *
10476             * <p>
10477             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10478             * </p>
10479             *
10480             * @param groupId the group ID
10481             * @param categoryId the category ID
10482             * @param threadId the thread ID
10483             * @param start the lower bound of the range of message-boards messages
10484             * @param end the upper bound of the range of message-boards messages (not inclusive)
10485             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10486             * @return the ordered 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, OrderByComparator orderByComparator)
10491                    throws SystemException {
10492                    FinderPath finderPath = null;
10493                    Object[] finderArgs = null;
10494    
10495                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10496                                    (orderByComparator == null)) {
10497                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
10498                            finderArgs = new Object[] { groupId, categoryId, threadId };
10499                    }
10500                    else {
10501                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
10502                            finderArgs = new Object[] {
10503                                            groupId, categoryId, threadId,
10504                                            
10505                                            start, end, orderByComparator
10506                                    };
10507                    }
10508    
10509                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10510                                    finderArgs, this);
10511    
10512                    if ((list != null) && !list.isEmpty()) {
10513                            for (MBMessage mbMessage : list) {
10514                                    if ((groupId != mbMessage.getGroupId()) ||
10515                                                    (categoryId != mbMessage.getCategoryId()) ||
10516                                                    (threadId != mbMessage.getThreadId())) {
10517                                            list = null;
10518    
10519                                            break;
10520                                    }
10521                            }
10522                    }
10523    
10524                    if (list == null) {
10525                            StringBundler query = null;
10526    
10527                            if (orderByComparator != null) {
10528                                    query = new StringBundler(5 +
10529                                                    (orderByComparator.getOrderByFields().length * 3));
10530                            }
10531                            else {
10532                                    query = new StringBundler(5);
10533                            }
10534    
10535                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10536    
10537                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10538    
10539                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10540    
10541                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10542    
10543                            if (orderByComparator != null) {
10544                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10545                                            orderByComparator);
10546                            }
10547    
10548                            else {
10549                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10550                            }
10551    
10552                            String sql = query.toString();
10553    
10554                            Session session = null;
10555    
10556                            try {
10557                                    session = openSession();
10558    
10559                                    Query q = session.createQuery(sql);
10560    
10561                                    QueryPos qPos = QueryPos.getInstance(q);
10562    
10563                                    qPos.add(groupId);
10564    
10565                                    qPos.add(categoryId);
10566    
10567                                    qPos.add(threadId);
10568    
10569                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
10570                                                    end);
10571                            }
10572                            catch (Exception e) {
10573                                    throw processException(e);
10574                            }
10575                            finally {
10576                                    if (list == null) {
10577                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
10578                                    }
10579                                    else {
10580                                            cacheResult(list);
10581    
10582                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
10583                                    }
10584    
10585                                    closeSession(session);
10586                            }
10587                    }
10588    
10589                    return list;
10590            }
10591    
10592            /**
10593             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10594             *
10595             * @param groupId the group ID
10596             * @param categoryId the category ID
10597             * @param threadId the thread ID
10598             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10599             * @return the first matching message-boards message
10600             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10601             * @throws SystemException if a system exception occurred
10602             */
10603            public MBMessage findByG_C_T_First(long groupId, long categoryId,
10604                    long threadId, OrderByComparator orderByComparator)
10605                    throws NoSuchMessageException, SystemException {
10606                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
10607                                    orderByComparator);
10608    
10609                    if (mbMessage != null) {
10610                            return mbMessage;
10611                    }
10612    
10613                    StringBundler msg = new StringBundler(8);
10614    
10615                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10616    
10617                    msg.append("groupId=");
10618                    msg.append(groupId);
10619    
10620                    msg.append(", categoryId=");
10621                    msg.append(categoryId);
10622    
10623                    msg.append(", threadId=");
10624                    msg.append(threadId);
10625    
10626                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10627    
10628                    throw new NoSuchMessageException(msg.toString());
10629            }
10630    
10631            /**
10632             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10633             *
10634             * @param groupId the group ID
10635             * @param categoryId the category ID
10636             * @param threadId the thread ID
10637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10638             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10639             * @throws SystemException if a system exception occurred
10640             */
10641            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
10642                    long threadId, OrderByComparator orderByComparator)
10643                    throws SystemException {
10644                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
10645                                    orderByComparator);
10646    
10647                    if (!list.isEmpty()) {
10648                            return list.get(0);
10649                    }
10650    
10651                    return null;
10652            }
10653    
10654            /**
10655             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10656             *
10657             * @param groupId the group ID
10658             * @param categoryId the category ID
10659             * @param threadId the thread ID
10660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10661             * @return the last matching message-boards message
10662             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10663             * @throws SystemException if a system exception occurred
10664             */
10665            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
10666                    long threadId, OrderByComparator orderByComparator)
10667                    throws NoSuchMessageException, SystemException {
10668                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
10669                                    orderByComparator);
10670    
10671                    if (mbMessage != null) {
10672                            return mbMessage;
10673                    }
10674    
10675                    StringBundler msg = new StringBundler(8);
10676    
10677                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10678    
10679                    msg.append("groupId=");
10680                    msg.append(groupId);
10681    
10682                    msg.append(", categoryId=");
10683                    msg.append(categoryId);
10684    
10685                    msg.append(", threadId=");
10686                    msg.append(threadId);
10687    
10688                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10689    
10690                    throw new NoSuchMessageException(msg.toString());
10691            }
10692    
10693            /**
10694             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10695             *
10696             * @param groupId the group ID
10697             * @param categoryId the category ID
10698             * @param threadId the thread ID
10699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10700             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10701             * @throws SystemException if a system exception occurred
10702             */
10703            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
10704                    long threadId, OrderByComparator orderByComparator)
10705                    throws SystemException {
10706                    int count = countByG_C_T(groupId, categoryId, threadId);
10707    
10708                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
10709                                    count - 1, count, orderByComparator);
10710    
10711                    if (!list.isEmpty()) {
10712                            return list.get(0);
10713                    }
10714    
10715                    return null;
10716            }
10717    
10718            /**
10719             * 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;.
10720             *
10721             * @param messageId the primary key of the current message-boards message
10722             * @param groupId the group ID
10723             * @param categoryId the category ID
10724             * @param threadId the thread ID
10725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10726             * @return the previous, current, and next message-boards message
10727             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10728             * @throws SystemException if a system exception occurred
10729             */
10730            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
10731                    long categoryId, long threadId, OrderByComparator orderByComparator)
10732                    throws NoSuchMessageException, SystemException {
10733                    MBMessage mbMessage = findByPrimaryKey(messageId);
10734    
10735                    Session session = null;
10736    
10737                    try {
10738                            session = openSession();
10739    
10740                            MBMessage[] array = new MBMessageImpl[3];
10741    
10742                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10743                                            categoryId, threadId, orderByComparator, true);
10744    
10745                            array[1] = mbMessage;
10746    
10747                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10748                                            categoryId, threadId, orderByComparator, false);
10749    
10750                            return array;
10751                    }
10752                    catch (Exception e) {
10753                            throw processException(e);
10754                    }
10755                    finally {
10756                            closeSession(session);
10757                    }
10758            }
10759    
10760            protected MBMessage getByG_C_T_PrevAndNext(Session session,
10761                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
10762                    OrderByComparator orderByComparator, boolean previous) {
10763                    StringBundler query = null;
10764    
10765                    if (orderByComparator != null) {
10766                            query = new StringBundler(6 +
10767                                            (orderByComparator.getOrderByFields().length * 6));
10768                    }
10769                    else {
10770                            query = new StringBundler(3);
10771                    }
10772    
10773                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10774    
10775                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10776    
10777                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10778    
10779                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10780    
10781                    if (orderByComparator != null) {
10782                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10783    
10784                            if (orderByConditionFields.length > 0) {
10785                                    query.append(WHERE_AND);
10786                            }
10787    
10788                            for (int i = 0; i < orderByConditionFields.length; i++) {
10789                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10790                                    query.append(orderByConditionFields[i]);
10791    
10792                                    if ((i + 1) < orderByConditionFields.length) {
10793                                            if (orderByComparator.isAscending() ^ previous) {
10794                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10795                                            }
10796                                            else {
10797                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10798                                            }
10799                                    }
10800                                    else {
10801                                            if (orderByComparator.isAscending() ^ previous) {
10802                                                    query.append(WHERE_GREATER_THAN);
10803                                            }
10804                                            else {
10805                                                    query.append(WHERE_LESSER_THAN);
10806                                            }
10807                                    }
10808                            }
10809    
10810                            query.append(ORDER_BY_CLAUSE);
10811    
10812                            String[] orderByFields = orderByComparator.getOrderByFields();
10813    
10814                            for (int i = 0; i < orderByFields.length; i++) {
10815                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10816                                    query.append(orderByFields[i]);
10817    
10818                                    if ((i + 1) < orderByFields.length) {
10819                                            if (orderByComparator.isAscending() ^ previous) {
10820                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10821                                            }
10822                                            else {
10823                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10824                                            }
10825                                    }
10826                                    else {
10827                                            if (orderByComparator.isAscending() ^ previous) {
10828                                                    query.append(ORDER_BY_ASC);
10829                                            }
10830                                            else {
10831                                                    query.append(ORDER_BY_DESC);
10832                                            }
10833                                    }
10834                            }
10835                    }
10836    
10837                    else {
10838                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10839                    }
10840    
10841                    String sql = query.toString();
10842    
10843                    Query q = session.createQuery(sql);
10844    
10845                    q.setFirstResult(0);
10846                    q.setMaxResults(2);
10847    
10848                    QueryPos qPos = QueryPos.getInstance(q);
10849    
10850                    qPos.add(groupId);
10851    
10852                    qPos.add(categoryId);
10853    
10854                    qPos.add(threadId);
10855    
10856                    if (orderByComparator != null) {
10857                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10858    
10859                            for (Object value : values) {
10860                                    qPos.add(value);
10861                            }
10862                    }
10863    
10864                    List<MBMessage> list = q.list();
10865    
10866                    if (list.size() == 2) {
10867                            return list.get(1);
10868                    }
10869                    else {
10870                            return null;
10871                    }
10872            }
10873    
10874            /**
10875             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10876             *
10877             * @param groupId the group ID
10878             * @param categoryId the category ID
10879             * @param threadId the thread ID
10880             * @return the matching message-boards messages that the user has permission to view
10881             * @throws SystemException if a system exception occurred
10882             */
10883            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10884                    long threadId) throws SystemException {
10885                    return filterFindByG_C_T(groupId, categoryId, threadId,
10886                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10887            }
10888    
10889            /**
10890             * 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;.
10891             *
10892             * <p>
10893             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10894             * </p>
10895             *
10896             * @param groupId the group ID
10897             * @param categoryId the category ID
10898             * @param threadId the thread ID
10899             * @param start the lower bound of the range of message-boards messages
10900             * @param end the upper bound of the range of message-boards messages (not inclusive)
10901             * @return the range of 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, int start, int end) throws SystemException {
10906                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
10907            }
10908    
10909            /**
10910             * 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;.
10911             *
10912             * <p>
10913             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10914             * </p>
10915             *
10916             * @param groupId the group ID
10917             * @param categoryId the category ID
10918             * @param threadId the thread ID
10919             * @param start the lower bound of the range of message-boards messages
10920             * @param end the upper bound of the range of message-boards messages (not inclusive)
10921             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10922             * @return the ordered 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, OrderByComparator orderByComparator)
10927                    throws SystemException {
10928                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10929                            return findByG_C_T(groupId, categoryId, threadId, start, end,
10930                                    orderByComparator);
10931                    }
10932    
10933                    StringBundler query = null;
10934    
10935                    if (orderByComparator != null) {
10936                            query = new StringBundler(5 +
10937                                            (orderByComparator.getOrderByFields().length * 3));
10938                    }
10939                    else {
10940                            query = new StringBundler(5);
10941                    }
10942    
10943                    if (getDB().isSupportsInlineDistinct()) {
10944                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10945                    }
10946                    else {
10947                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10948                    }
10949    
10950                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10951    
10952                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10953    
10954                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10955    
10956                    if (!getDB().isSupportsInlineDistinct()) {
10957                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10958                    }
10959    
10960                    if (orderByComparator != null) {
10961                            if (getDB().isSupportsInlineDistinct()) {
10962                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10963                                            orderByComparator);
10964                            }
10965                            else {
10966                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10967                                            orderByComparator);
10968                            }
10969                    }
10970    
10971                    else {
10972                            if (getDB().isSupportsInlineDistinct()) {
10973                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10974                            }
10975                            else {
10976                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10977                            }
10978                    }
10979    
10980                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10981                                    MBMessage.class.getName(),
10982                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10983    
10984                    Session session = null;
10985    
10986                    try {
10987                            session = openSession();
10988    
10989                            SQLQuery q = session.createSQLQuery(sql);
10990    
10991                            if (getDB().isSupportsInlineDistinct()) {
10992                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10993                            }
10994                            else {
10995                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10996                            }
10997    
10998                            QueryPos qPos = QueryPos.getInstance(q);
10999    
11000                            qPos.add(groupId);
11001    
11002                            qPos.add(categoryId);
11003    
11004                            qPos.add(threadId);
11005    
11006                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11007                    }
11008                    catch (Exception e) {
11009                            throw processException(e);
11010                    }
11011                    finally {
11012                            closeSession(session);
11013                    }
11014            }
11015    
11016            /**
11017             * 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;.
11018             *
11019             * @param messageId the primary key of the current message-boards message
11020             * @param groupId the group ID
11021             * @param categoryId the category ID
11022             * @param threadId the thread ID
11023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11024             * @return the previous, current, and next message-boards message
11025             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11026             * @throws SystemException if a system exception occurred
11027             */
11028            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
11029                    long groupId, long categoryId, long threadId,
11030                    OrderByComparator orderByComparator)
11031                    throws NoSuchMessageException, SystemException {
11032                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11033                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
11034                                    threadId, orderByComparator);
11035                    }
11036    
11037                    MBMessage mbMessage = findByPrimaryKey(messageId);
11038    
11039                    Session session = null;
11040    
11041                    try {
11042                            session = openSession();
11043    
11044                            MBMessage[] array = new MBMessageImpl[3];
11045    
11046                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
11047                                            groupId, categoryId, threadId, orderByComparator, true);
11048    
11049                            array[1] = mbMessage;
11050    
11051                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
11052                                            groupId, categoryId, threadId, orderByComparator, false);
11053    
11054                            return array;
11055                    }
11056                    catch (Exception e) {
11057                            throw processException(e);
11058                    }
11059                    finally {
11060                            closeSession(session);
11061                    }
11062            }
11063    
11064            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
11065                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
11066                    OrderByComparator orderByComparator, boolean previous) {
11067                    StringBundler query = null;
11068    
11069                    if (orderByComparator != null) {
11070                            query = new StringBundler(6 +
11071                                            (orderByComparator.getOrderByFields().length * 6));
11072                    }
11073                    else {
11074                            query = new StringBundler(3);
11075                    }
11076    
11077                    if (getDB().isSupportsInlineDistinct()) {
11078                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11079                    }
11080                    else {
11081                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11082                    }
11083    
11084                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11085    
11086                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11087    
11088                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11089    
11090                    if (!getDB().isSupportsInlineDistinct()) {
11091                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11092                    }
11093    
11094                    if (orderByComparator != null) {
11095                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11096    
11097                            if (orderByConditionFields.length > 0) {
11098                                    query.append(WHERE_AND);
11099                            }
11100    
11101                            for (int i = 0; i < orderByConditionFields.length; i++) {
11102                                    if (getDB().isSupportsInlineDistinct()) {
11103                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11104                                    }
11105                                    else {
11106                                            query.append(_ORDER_BY_ENTITY_TABLE);
11107                                    }
11108    
11109                                    query.append(orderByConditionFields[i]);
11110    
11111                                    if ((i + 1) < orderByConditionFields.length) {
11112                                            if (orderByComparator.isAscending() ^ previous) {
11113                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11114                                            }
11115                                            else {
11116                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11117                                            }
11118                                    }
11119                                    else {
11120                                            if (orderByComparator.isAscending() ^ previous) {
11121                                                    query.append(WHERE_GREATER_THAN);
11122                                            }
11123                                            else {
11124                                                    query.append(WHERE_LESSER_THAN);
11125                                            }
11126                                    }
11127                            }
11128    
11129                            query.append(ORDER_BY_CLAUSE);
11130    
11131                            String[] orderByFields = orderByComparator.getOrderByFields();
11132    
11133                            for (int i = 0; i < orderByFields.length; i++) {
11134                                    if (getDB().isSupportsInlineDistinct()) {
11135                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11136                                    }
11137                                    else {
11138                                            query.append(_ORDER_BY_ENTITY_TABLE);
11139                                    }
11140    
11141                                    query.append(orderByFields[i]);
11142    
11143                                    if ((i + 1) < orderByFields.length) {
11144                                            if (orderByComparator.isAscending() ^ previous) {
11145                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11146                                            }
11147                                            else {
11148                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11149                                            }
11150                                    }
11151                                    else {
11152                                            if (orderByComparator.isAscending() ^ previous) {
11153                                                    query.append(ORDER_BY_ASC);
11154                                            }
11155                                            else {
11156                                                    query.append(ORDER_BY_DESC);
11157                                            }
11158                                    }
11159                            }
11160                    }
11161    
11162                    else {
11163                            if (getDB().isSupportsInlineDistinct()) {
11164                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11165                            }
11166                            else {
11167                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11168                            }
11169                    }
11170    
11171                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11172                                    MBMessage.class.getName(),
11173                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11174    
11175                    SQLQuery q = session.createSQLQuery(sql);
11176    
11177                    q.setFirstResult(0);
11178                    q.setMaxResults(2);
11179    
11180                    if (getDB().isSupportsInlineDistinct()) {
11181                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11182                    }
11183                    else {
11184                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11185                    }
11186    
11187                    QueryPos qPos = QueryPos.getInstance(q);
11188    
11189                    qPos.add(groupId);
11190    
11191                    qPos.add(categoryId);
11192    
11193                    qPos.add(threadId);
11194    
11195                    if (orderByComparator != null) {
11196                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11197    
11198                            for (Object value : values) {
11199                                    qPos.add(value);
11200                            }
11201                    }
11202    
11203                    List<MBMessage> list = q.list();
11204    
11205                    if (list.size() == 2) {
11206                            return list.get(1);
11207                    }
11208                    else {
11209                            return null;
11210                    }
11211            }
11212    
11213            /**
11214             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11215             *
11216             * @param groupId the group ID
11217             * @param categoryId the category ID
11218             * @param status the status
11219             * @return the matching message-boards messages
11220             * @throws SystemException if a system exception occurred
11221             */
11222            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
11223                    throws SystemException {
11224                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
11225                            QueryUtil.ALL_POS, null);
11226            }
11227    
11228            /**
11229             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11230             *
11231             * <p>
11232             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11233             * </p>
11234             *
11235             * @param groupId the group ID
11236             * @param categoryId the category ID
11237             * @param status the status
11238             * @param start the lower bound of the range of message-boards messages
11239             * @param end the upper bound of the range of message-boards messages (not inclusive)
11240             * @return the range of matching message-boards messages
11241             * @throws SystemException if a system exception occurred
11242             */
11243            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
11244                    int status, int start, int end) throws SystemException {
11245                    return findByG_C_S(groupId, categoryId, status, start, end, null);
11246            }
11247    
11248            /**
11249             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11250             *
11251             * <p>
11252             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11253             * </p>
11254             *
11255             * @param groupId the group ID
11256             * @param categoryId the category ID
11257             * @param status the status
11258             * @param start the lower bound of the range of message-boards messages
11259             * @param end the upper bound of the range of message-boards messages (not inclusive)
11260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11261             * @return the ordered 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, OrderByComparator orderByComparator)
11266                    throws SystemException {
11267                    FinderPath finderPath = null;
11268                    Object[] finderArgs = null;
11269    
11270                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11271                                    (orderByComparator == null)) {
11272                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
11273                            finderArgs = new Object[] { groupId, categoryId, status };
11274                    }
11275                    else {
11276                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
11277                            finderArgs = new Object[] {
11278                                            groupId, categoryId, status,
11279                                            
11280                                            start, end, orderByComparator
11281                                    };
11282                    }
11283    
11284                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11285                                    finderArgs, this);
11286    
11287                    if ((list != null) && !list.isEmpty()) {
11288                            for (MBMessage mbMessage : list) {
11289                                    if ((groupId != mbMessage.getGroupId()) ||
11290                                                    (categoryId != mbMessage.getCategoryId()) ||
11291                                                    (status != mbMessage.getStatus())) {
11292                                            list = null;
11293    
11294                                            break;
11295                                    }
11296                            }
11297                    }
11298    
11299                    if (list == null) {
11300                            StringBundler query = null;
11301    
11302                            if (orderByComparator != null) {
11303                                    query = new StringBundler(5 +
11304                                                    (orderByComparator.getOrderByFields().length * 3));
11305                            }
11306                            else {
11307                                    query = new StringBundler(5);
11308                            }
11309    
11310                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11311    
11312                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11313    
11314                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11315    
11316                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11317    
11318                            if (orderByComparator != null) {
11319                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11320                                            orderByComparator);
11321                            }
11322    
11323                            else {
11324                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11325                            }
11326    
11327                            String sql = query.toString();
11328    
11329                            Session session = null;
11330    
11331                            try {
11332                                    session = openSession();
11333    
11334                                    Query q = session.createQuery(sql);
11335    
11336                                    QueryPos qPos = QueryPos.getInstance(q);
11337    
11338                                    qPos.add(groupId);
11339    
11340                                    qPos.add(categoryId);
11341    
11342                                    qPos.add(status);
11343    
11344                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11345                                                    end);
11346                            }
11347                            catch (Exception e) {
11348                                    throw processException(e);
11349                            }
11350                            finally {
11351                                    if (list == null) {
11352                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11353                                    }
11354                                    else {
11355                                            cacheResult(list);
11356    
11357                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11358                                    }
11359    
11360                                    closeSession(session);
11361                            }
11362                    }
11363    
11364                    return list;
11365            }
11366    
11367            /**
11368             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11369             *
11370             * @param groupId the group ID
11371             * @param categoryId the category ID
11372             * @param status the status
11373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11374             * @return the first matching message-boards message
11375             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11376             * @throws SystemException if a system exception occurred
11377             */
11378            public MBMessage findByG_C_S_First(long groupId, long categoryId,
11379                    int status, OrderByComparator orderByComparator)
11380                    throws NoSuchMessageException, SystemException {
11381                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
11382                                    orderByComparator);
11383    
11384                    if (mbMessage != null) {
11385                            return mbMessage;
11386                    }
11387    
11388                    StringBundler msg = new StringBundler(8);
11389    
11390                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11391    
11392                    msg.append("groupId=");
11393                    msg.append(groupId);
11394    
11395                    msg.append(", categoryId=");
11396                    msg.append(categoryId);
11397    
11398                    msg.append(", status=");
11399                    msg.append(status);
11400    
11401                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11402    
11403                    throw new NoSuchMessageException(msg.toString());
11404            }
11405    
11406            /**
11407             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11408             *
11409             * @param groupId the group ID
11410             * @param categoryId the category ID
11411             * @param status the status
11412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11413             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11414             * @throws SystemException if a system exception occurred
11415             */
11416            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
11417                    int status, OrderByComparator orderByComparator)
11418                    throws SystemException {
11419                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
11420                                    orderByComparator);
11421    
11422                    if (!list.isEmpty()) {
11423                            return list.get(0);
11424                    }
11425    
11426                    return null;
11427            }
11428    
11429            /**
11430             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11431             *
11432             * @param groupId the group ID
11433             * @param categoryId the category ID
11434             * @param status the status
11435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11436             * @return the last matching message-boards message
11437             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11438             * @throws SystemException if a system exception occurred
11439             */
11440            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
11441                    int status, OrderByComparator orderByComparator)
11442                    throws NoSuchMessageException, SystemException {
11443                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
11444                                    orderByComparator);
11445    
11446                    if (mbMessage != null) {
11447                            return mbMessage;
11448                    }
11449    
11450                    StringBundler msg = new StringBundler(8);
11451    
11452                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11453    
11454                    msg.append("groupId=");
11455                    msg.append(groupId);
11456    
11457                    msg.append(", categoryId=");
11458                    msg.append(categoryId);
11459    
11460                    msg.append(", status=");
11461                    msg.append(status);
11462    
11463                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11464    
11465                    throw new NoSuchMessageException(msg.toString());
11466            }
11467    
11468            /**
11469             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11470             *
11471             * @param groupId the group ID
11472             * @param categoryId the category ID
11473             * @param status the status
11474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11475             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11476             * @throws SystemException if a system exception occurred
11477             */
11478            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
11479                    int status, OrderByComparator orderByComparator)
11480                    throws SystemException {
11481                    int count = countByG_C_S(groupId, categoryId, status);
11482    
11483                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
11484                                    count - 1, count, orderByComparator);
11485    
11486                    if (!list.isEmpty()) {
11487                            return list.get(0);
11488                    }
11489    
11490                    return null;
11491            }
11492    
11493            /**
11494             * 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;.
11495             *
11496             * @param messageId the primary key of the current message-boards message
11497             * @param groupId the group ID
11498             * @param categoryId the category ID
11499             * @param status the status
11500             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11501             * @return the previous, current, and next message-boards message
11502             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11503             * @throws SystemException if a system exception occurred
11504             */
11505            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
11506                    long categoryId, int status, OrderByComparator orderByComparator)
11507                    throws NoSuchMessageException, SystemException {
11508                    MBMessage mbMessage = findByPrimaryKey(messageId);
11509    
11510                    Session session = null;
11511    
11512                    try {
11513                            session = openSession();
11514    
11515                            MBMessage[] array = new MBMessageImpl[3];
11516    
11517                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
11518                                            categoryId, status, orderByComparator, true);
11519    
11520                            array[1] = mbMessage;
11521    
11522                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
11523                                            categoryId, status, orderByComparator, false);
11524    
11525                            return array;
11526                    }
11527                    catch (Exception e) {
11528                            throw processException(e);
11529                    }
11530                    finally {
11531                            closeSession(session);
11532                    }
11533            }
11534    
11535            protected MBMessage getByG_C_S_PrevAndNext(Session session,
11536                    MBMessage mbMessage, long groupId, long categoryId, int status,
11537                    OrderByComparator orderByComparator, boolean previous) {
11538                    StringBundler query = null;
11539    
11540                    if (orderByComparator != null) {
11541                            query = new StringBundler(6 +
11542                                            (orderByComparator.getOrderByFields().length * 6));
11543                    }
11544                    else {
11545                            query = new StringBundler(3);
11546                    }
11547    
11548                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11549    
11550                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11551    
11552                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11553    
11554                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11555    
11556                    if (orderByComparator != null) {
11557                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11558    
11559                            if (orderByConditionFields.length > 0) {
11560                                    query.append(WHERE_AND);
11561                            }
11562    
11563                            for (int i = 0; i < orderByConditionFields.length; i++) {
11564                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11565                                    query.append(orderByConditionFields[i]);
11566    
11567                                    if ((i + 1) < orderByConditionFields.length) {
11568                                            if (orderByComparator.isAscending() ^ previous) {
11569                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11570                                            }
11571                                            else {
11572                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11573                                            }
11574                                    }
11575                                    else {
11576                                            if (orderByComparator.isAscending() ^ previous) {
11577                                                    query.append(WHERE_GREATER_THAN);
11578                                            }
11579                                            else {
11580                                                    query.append(WHERE_LESSER_THAN);
11581                                            }
11582                                    }
11583                            }
11584    
11585                            query.append(ORDER_BY_CLAUSE);
11586    
11587                            String[] orderByFields = orderByComparator.getOrderByFields();
11588    
11589                            for (int i = 0; i < orderByFields.length; i++) {
11590                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11591                                    query.append(orderByFields[i]);
11592    
11593                                    if ((i + 1) < orderByFields.length) {
11594                                            if (orderByComparator.isAscending() ^ previous) {
11595                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11596                                            }
11597                                            else {
11598                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11599                                            }
11600                                    }
11601                                    else {
11602                                            if (orderByComparator.isAscending() ^ previous) {
11603                                                    query.append(ORDER_BY_ASC);
11604                                            }
11605                                            else {
11606                                                    query.append(ORDER_BY_DESC);
11607                                            }
11608                                    }
11609                            }
11610                    }
11611    
11612                    else {
11613                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11614                    }
11615    
11616                    String sql = query.toString();
11617    
11618                    Query q = session.createQuery(sql);
11619    
11620                    q.setFirstResult(0);
11621                    q.setMaxResults(2);
11622    
11623                    QueryPos qPos = QueryPos.getInstance(q);
11624    
11625                    qPos.add(groupId);
11626    
11627                    qPos.add(categoryId);
11628    
11629                    qPos.add(status);
11630    
11631                    if (orderByComparator != null) {
11632                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11633    
11634                            for (Object value : values) {
11635                                    qPos.add(value);
11636                            }
11637                    }
11638    
11639                    List<MBMessage> list = q.list();
11640    
11641                    if (list.size() == 2) {
11642                            return list.get(1);
11643                    }
11644                    else {
11645                            return null;
11646                    }
11647            }
11648    
11649            /**
11650             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
11651             *
11652             * @param groupId the group ID
11653             * @param categoryId the category ID
11654             * @param status the status
11655             * @return the matching message-boards messages that the user has permission to view
11656             * @throws SystemException if a system exception occurred
11657             */
11658            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11659                    int status) throws SystemException {
11660                    return filterFindByG_C_S(groupId, categoryId, status,
11661                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11662            }
11663    
11664            /**
11665             * 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;.
11666             *
11667             * <p>
11668             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11669             * </p>
11670             *
11671             * @param groupId the group ID
11672             * @param categoryId the category ID
11673             * @param status the status
11674             * @param start the lower bound of the range of message-boards messages
11675             * @param end the upper bound of the range of message-boards messages (not inclusive)
11676             * @return the range of 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, int start, int end) throws SystemException {
11681                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
11682            }
11683    
11684            /**
11685             * 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;.
11686             *
11687             * <p>
11688             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11689             * </p>
11690             *
11691             * @param groupId the group ID
11692             * @param categoryId the category ID
11693             * @param status the status
11694             * @param start the lower bound of the range of message-boards messages
11695             * @param end the upper bound of the range of message-boards messages (not inclusive)
11696             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11697             * @return the ordered 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, OrderByComparator orderByComparator)
11702                    throws SystemException {
11703                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11704                            return findByG_C_S(groupId, categoryId, status, start, end,
11705                                    orderByComparator);
11706                    }
11707    
11708                    StringBundler query = null;
11709    
11710                    if (orderByComparator != null) {
11711                            query = new StringBundler(5 +
11712                                            (orderByComparator.getOrderByFields().length * 3));
11713                    }
11714                    else {
11715                            query = new StringBundler(5);
11716                    }
11717    
11718                    if (getDB().isSupportsInlineDistinct()) {
11719                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11720                    }
11721                    else {
11722                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11723                    }
11724    
11725                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11726    
11727                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11728    
11729                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11730    
11731                    if (!getDB().isSupportsInlineDistinct()) {
11732                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11733                    }
11734    
11735                    if (orderByComparator != null) {
11736                            if (getDB().isSupportsInlineDistinct()) {
11737                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11738                                            orderByComparator);
11739                            }
11740                            else {
11741                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11742                                            orderByComparator);
11743                            }
11744                    }
11745    
11746                    else {
11747                            if (getDB().isSupportsInlineDistinct()) {
11748                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11749                            }
11750                            else {
11751                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11752                            }
11753                    }
11754    
11755                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11756                                    MBMessage.class.getName(),
11757                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11758    
11759                    Session session = null;
11760    
11761                    try {
11762                            session = openSession();
11763    
11764                            SQLQuery q = session.createSQLQuery(sql);
11765    
11766                            if (getDB().isSupportsInlineDistinct()) {
11767                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11768                            }
11769                            else {
11770                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11771                            }
11772    
11773                            QueryPos qPos = QueryPos.getInstance(q);
11774    
11775                            qPos.add(groupId);
11776    
11777                            qPos.add(categoryId);
11778    
11779                            qPos.add(status);
11780    
11781                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11782                    }
11783                    catch (Exception e) {
11784                            throw processException(e);
11785                    }
11786                    finally {
11787                            closeSession(session);
11788                    }
11789            }
11790    
11791            /**
11792             * 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;.
11793             *
11794             * @param messageId the primary key of the current message-boards message
11795             * @param groupId the group ID
11796             * @param categoryId the category ID
11797             * @param status the status
11798             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11799             * @return the previous, current, and next message-boards message
11800             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11801             * @throws SystemException if a system exception occurred
11802             */
11803            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
11804                    long groupId, long categoryId, int status,
11805                    OrderByComparator orderByComparator)
11806                    throws NoSuchMessageException, SystemException {
11807                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11808                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
11809                                    status, orderByComparator);
11810                    }
11811    
11812                    MBMessage mbMessage = findByPrimaryKey(messageId);
11813    
11814                    Session session = null;
11815    
11816                    try {
11817                            session = openSession();
11818    
11819                            MBMessage[] array = new MBMessageImpl[3];
11820    
11821                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11822                                            groupId, categoryId, status, orderByComparator, true);
11823    
11824                            array[1] = mbMessage;
11825    
11826                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11827                                            groupId, categoryId, status, orderByComparator, false);
11828    
11829                            return array;
11830                    }
11831                    catch (Exception e) {
11832                            throw processException(e);
11833                    }
11834                    finally {
11835                            closeSession(session);
11836                    }
11837            }
11838    
11839            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
11840                    MBMessage mbMessage, long groupId, long categoryId, int status,
11841                    OrderByComparator orderByComparator, boolean previous) {
11842                    StringBundler query = null;
11843    
11844                    if (orderByComparator != null) {
11845                            query = new StringBundler(6 +
11846                                            (orderByComparator.getOrderByFields().length * 6));
11847                    }
11848                    else {
11849                            query = new StringBundler(3);
11850                    }
11851    
11852                    if (getDB().isSupportsInlineDistinct()) {
11853                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11854                    }
11855                    else {
11856                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11857                    }
11858    
11859                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11860    
11861                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11862    
11863                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11864    
11865                    if (!getDB().isSupportsInlineDistinct()) {
11866                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11867                    }
11868    
11869                    if (orderByComparator != null) {
11870                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11871    
11872                            if (orderByConditionFields.length > 0) {
11873                                    query.append(WHERE_AND);
11874                            }
11875    
11876                            for (int i = 0; i < orderByConditionFields.length; i++) {
11877                                    if (getDB().isSupportsInlineDistinct()) {
11878                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11879                                    }
11880                                    else {
11881                                            query.append(_ORDER_BY_ENTITY_TABLE);
11882                                    }
11883    
11884                                    query.append(orderByConditionFields[i]);
11885    
11886                                    if ((i + 1) < orderByConditionFields.length) {
11887                                            if (orderByComparator.isAscending() ^ previous) {
11888                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11889                                            }
11890                                            else {
11891                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11892                                            }
11893                                    }
11894                                    else {
11895                                            if (orderByComparator.isAscending() ^ previous) {
11896                                                    query.append(WHERE_GREATER_THAN);
11897                                            }
11898                                            else {
11899                                                    query.append(WHERE_LESSER_THAN);
11900                                            }
11901                                    }
11902                            }
11903    
11904                            query.append(ORDER_BY_CLAUSE);
11905    
11906                            String[] orderByFields = orderByComparator.getOrderByFields();
11907    
11908                            for (int i = 0; i < orderByFields.length; i++) {
11909                                    if (getDB().isSupportsInlineDistinct()) {
11910                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11911                                    }
11912                                    else {
11913                                            query.append(_ORDER_BY_ENTITY_TABLE);
11914                                    }
11915    
11916                                    query.append(orderByFields[i]);
11917    
11918                                    if ((i + 1) < orderByFields.length) {
11919                                            if (orderByComparator.isAscending() ^ previous) {
11920                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11921                                            }
11922                                            else {
11923                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11924                                            }
11925                                    }
11926                                    else {
11927                                            if (orderByComparator.isAscending() ^ previous) {
11928                                                    query.append(ORDER_BY_ASC);
11929                                            }
11930                                            else {
11931                                                    query.append(ORDER_BY_DESC);
11932                                            }
11933                                    }
11934                            }
11935                    }
11936    
11937                    else {
11938                            if (getDB().isSupportsInlineDistinct()) {
11939                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11940                            }
11941                            else {
11942                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11943                            }
11944                    }
11945    
11946                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11947                                    MBMessage.class.getName(),
11948                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11949    
11950                    SQLQuery q = session.createSQLQuery(sql);
11951    
11952                    q.setFirstResult(0);
11953                    q.setMaxResults(2);
11954    
11955                    if (getDB().isSupportsInlineDistinct()) {
11956                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11957                    }
11958                    else {
11959                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11960                    }
11961    
11962                    QueryPos qPos = QueryPos.getInstance(q);
11963    
11964                    qPos.add(groupId);
11965    
11966                    qPos.add(categoryId);
11967    
11968                    qPos.add(status);
11969    
11970                    if (orderByComparator != null) {
11971                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11972    
11973                            for (Object value : values) {
11974                                    qPos.add(value);
11975                            }
11976                    }
11977    
11978                    List<MBMessage> list = q.list();
11979    
11980                    if (list.size() == 2) {
11981                            return list.get(1);
11982                    }
11983                    else {
11984                            return null;
11985                    }
11986            }
11987    
11988            /**
11989             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11990             *
11991             * @param userId the user ID
11992             * @param classNameId the class name ID
11993             * @param classPK the class p k
11994             * @return the matching message-boards messages
11995             * @throws SystemException if a system exception occurred
11996             */
11997            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11998                    long classPK) throws SystemException {
11999                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
12000                            QueryUtil.ALL_POS, null);
12001            }
12002    
12003            /**
12004             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12005             *
12006             * <p>
12007             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12008             * </p>
12009             *
12010             * @param userId the user ID
12011             * @param classNameId the class name ID
12012             * @param classPK the class p k
12013             * @param start the lower bound of the range of message-boards messages
12014             * @param end the upper bound of the range of message-boards messages (not inclusive)
12015             * @return the range of 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, int start, int end) throws SystemException {
12020                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
12021            }
12022    
12023            /**
12024             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12025             *
12026             * <p>
12027             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12028             * </p>
12029             *
12030             * @param userId the user ID
12031             * @param classNameId the class name ID
12032             * @param classPK the class p k
12033             * @param start the lower bound of the range of message-boards messages
12034             * @param end the upper bound of the range of message-boards messages (not inclusive)
12035             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12036             * @return the ordered 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, OrderByComparator orderByComparator)
12041                    throws SystemException {
12042                    FinderPath finderPath = null;
12043                    Object[] finderArgs = null;
12044    
12045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12046                                    (orderByComparator == null)) {
12047                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
12048                            finderArgs = new Object[] { userId, classNameId, classPK };
12049                    }
12050                    else {
12051                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
12052                            finderArgs = new Object[] {
12053                                            userId, classNameId, classPK,
12054                                            
12055                                            start, end, orderByComparator
12056                                    };
12057                    }
12058    
12059                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12060                                    finderArgs, this);
12061    
12062                    if ((list != null) && !list.isEmpty()) {
12063                            for (MBMessage mbMessage : list) {
12064                                    if ((userId != mbMessage.getUserId()) ||
12065                                                    (classNameId != mbMessage.getClassNameId()) ||
12066                                                    (classPK != mbMessage.getClassPK())) {
12067                                            list = null;
12068    
12069                                            break;
12070                                    }
12071                            }
12072                    }
12073    
12074                    if (list == null) {
12075                            StringBundler query = null;
12076    
12077                            if (orderByComparator != null) {
12078                                    query = new StringBundler(5 +
12079                                                    (orderByComparator.getOrderByFields().length * 3));
12080                            }
12081                            else {
12082                                    query = new StringBundler(5);
12083                            }
12084    
12085                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12086    
12087                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
12088    
12089                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
12090    
12091                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
12092    
12093                            if (orderByComparator != null) {
12094                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12095                                            orderByComparator);
12096                            }
12097    
12098                            else {
12099                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12100                            }
12101    
12102                            String sql = query.toString();
12103    
12104                            Session session = null;
12105    
12106                            try {
12107                                    session = openSession();
12108    
12109                                    Query q = session.createQuery(sql);
12110    
12111                                    QueryPos qPos = QueryPos.getInstance(q);
12112    
12113                                    qPos.add(userId);
12114    
12115                                    qPos.add(classNameId);
12116    
12117                                    qPos.add(classPK);
12118    
12119                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12120                                                    end);
12121                            }
12122                            catch (Exception e) {
12123                                    throw processException(e);
12124                            }
12125                            finally {
12126                                    if (list == null) {
12127                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12128                                    }
12129                                    else {
12130                                            cacheResult(list);
12131    
12132                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12133                                    }
12134    
12135                                    closeSession(session);
12136                            }
12137                    }
12138    
12139                    return list;
12140            }
12141    
12142            /**
12143             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12144             *
12145             * @param userId the user ID
12146             * @param classNameId the class name ID
12147             * @param classPK the class p k
12148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12149             * @return the first matching message-boards message
12150             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12151             * @throws SystemException if a system exception occurred
12152             */
12153            public MBMessage findByU_C_C_First(long userId, long classNameId,
12154                    long classPK, OrderByComparator orderByComparator)
12155                    throws NoSuchMessageException, SystemException {
12156                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
12157                                    orderByComparator);
12158    
12159                    if (mbMessage != null) {
12160                            return mbMessage;
12161                    }
12162    
12163                    StringBundler msg = new StringBundler(8);
12164    
12165                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12166    
12167                    msg.append("userId=");
12168                    msg.append(userId);
12169    
12170                    msg.append(", classNameId=");
12171                    msg.append(classNameId);
12172    
12173                    msg.append(", classPK=");
12174                    msg.append(classPK);
12175    
12176                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12177    
12178                    throw new NoSuchMessageException(msg.toString());
12179            }
12180    
12181            /**
12182             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12183             *
12184             * @param userId the user ID
12185             * @param classNameId the class name ID
12186             * @param classPK the class p k
12187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12188             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12189             * @throws SystemException if a system exception occurred
12190             */
12191            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
12192                    long classPK, OrderByComparator orderByComparator)
12193                    throws SystemException {
12194                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
12195                                    orderByComparator);
12196    
12197                    if (!list.isEmpty()) {
12198                            return list.get(0);
12199                    }
12200    
12201                    return null;
12202            }
12203    
12204            /**
12205             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12206             *
12207             * @param userId the user ID
12208             * @param classNameId the class name ID
12209             * @param classPK the class p k
12210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12211             * @return the last matching message-boards message
12212             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12213             * @throws SystemException if a system exception occurred
12214             */
12215            public MBMessage findByU_C_C_Last(long userId, long classNameId,
12216                    long classPK, OrderByComparator orderByComparator)
12217                    throws NoSuchMessageException, SystemException {
12218                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
12219                                    orderByComparator);
12220    
12221                    if (mbMessage != null) {
12222                            return mbMessage;
12223                    }
12224    
12225                    StringBundler msg = new StringBundler(8);
12226    
12227                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12228    
12229                    msg.append("userId=");
12230                    msg.append(userId);
12231    
12232                    msg.append(", classNameId=");
12233                    msg.append(classNameId);
12234    
12235                    msg.append(", classPK=");
12236                    msg.append(classPK);
12237    
12238                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12239    
12240                    throw new NoSuchMessageException(msg.toString());
12241            }
12242    
12243            /**
12244             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12245             *
12246             * @param userId the user ID
12247             * @param classNameId the class name ID
12248             * @param classPK the class p k
12249             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12250             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12251             * @throws SystemException if a system exception occurred
12252             */
12253            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
12254                    long classPK, OrderByComparator orderByComparator)
12255                    throws SystemException {
12256                    int count = countByU_C_C(userId, classNameId, classPK);
12257    
12258                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
12259                                    count - 1, count, orderByComparator);
12260    
12261                    if (!list.isEmpty()) {
12262                            return list.get(0);
12263                    }
12264    
12265                    return null;
12266            }
12267    
12268            /**
12269             * 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;.
12270             *
12271             * @param messageId the primary key of the current message-boards message
12272             * @param userId the user ID
12273             * @param classNameId the class name ID
12274             * @param classPK the class p k
12275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12276             * @return the previous, current, and next message-boards message
12277             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12278             * @throws SystemException if a system exception occurred
12279             */
12280            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
12281                    long classNameId, long classPK, OrderByComparator orderByComparator)
12282                    throws NoSuchMessageException, SystemException {
12283                    MBMessage mbMessage = findByPrimaryKey(messageId);
12284    
12285                    Session session = null;
12286    
12287                    try {
12288                            session = openSession();
12289    
12290                            MBMessage[] array = new MBMessageImpl[3];
12291    
12292                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
12293                                            classNameId, classPK, orderByComparator, true);
12294    
12295                            array[1] = mbMessage;
12296    
12297                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
12298                                            classNameId, classPK, orderByComparator, false);
12299    
12300                            return array;
12301                    }
12302                    catch (Exception e) {
12303                            throw processException(e);
12304                    }
12305                    finally {
12306                            closeSession(session);
12307                    }
12308            }
12309    
12310            protected MBMessage getByU_C_C_PrevAndNext(Session session,
12311                    MBMessage mbMessage, long userId, long classNameId, long classPK,
12312                    OrderByComparator orderByComparator, boolean previous) {
12313                    StringBundler query = null;
12314    
12315                    if (orderByComparator != null) {
12316                            query = new StringBundler(6 +
12317                                            (orderByComparator.getOrderByFields().length * 6));
12318                    }
12319                    else {
12320                            query = new StringBundler(3);
12321                    }
12322    
12323                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12324    
12325                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
12326    
12327                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
12328    
12329                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
12330    
12331                    if (orderByComparator != null) {
12332                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12333    
12334                            if (orderByConditionFields.length > 0) {
12335                                    query.append(WHERE_AND);
12336                            }
12337    
12338                            for (int i = 0; i < orderByConditionFields.length; i++) {
12339                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12340                                    query.append(orderByConditionFields[i]);
12341    
12342                                    if ((i + 1) < orderByConditionFields.length) {
12343                                            if (orderByComparator.isAscending() ^ previous) {
12344                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12345                                            }
12346                                            else {
12347                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12348                                            }
12349                                    }
12350                                    else {
12351                                            if (orderByComparator.isAscending() ^ previous) {
12352                                                    query.append(WHERE_GREATER_THAN);
12353                                            }
12354                                            else {
12355                                                    query.append(WHERE_LESSER_THAN);
12356                                            }
12357                                    }
12358                            }
12359    
12360                            query.append(ORDER_BY_CLAUSE);
12361    
12362                            String[] orderByFields = orderByComparator.getOrderByFields();
12363    
12364                            for (int i = 0; i < orderByFields.length; i++) {
12365                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12366                                    query.append(orderByFields[i]);
12367    
12368                                    if ((i + 1) < orderByFields.length) {
12369                                            if (orderByComparator.isAscending() ^ previous) {
12370                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12371                                            }
12372                                            else {
12373                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12374                                            }
12375                                    }
12376                                    else {
12377                                            if (orderByComparator.isAscending() ^ previous) {
12378                                                    query.append(ORDER_BY_ASC);
12379                                            }
12380                                            else {
12381                                                    query.append(ORDER_BY_DESC);
12382                                            }
12383                                    }
12384                            }
12385                    }
12386    
12387                    else {
12388                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12389                    }
12390    
12391                    String sql = query.toString();
12392    
12393                    Query q = session.createQuery(sql);
12394    
12395                    q.setFirstResult(0);
12396                    q.setMaxResults(2);
12397    
12398                    QueryPos qPos = QueryPos.getInstance(q);
12399    
12400                    qPos.add(userId);
12401    
12402                    qPos.add(classNameId);
12403    
12404                    qPos.add(classPK);
12405    
12406                    if (orderByComparator != null) {
12407                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12408    
12409                            for (Object value : values) {
12410                                    qPos.add(value);
12411                            }
12412                    }
12413    
12414                    List<MBMessage> list = q.list();
12415    
12416                    if (list.size() == 2) {
12417                            return list.get(1);
12418                    }
12419                    else {
12420                            return null;
12421                    }
12422            }
12423    
12424            /**
12425             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12426             *
12427             * @param userId the user ID
12428             * @param classNameId the class name ID
12429             * @param status the status
12430             * @return the matching message-boards messages
12431             * @throws SystemException if a system exception occurred
12432             */
12433            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
12434                    throws SystemException {
12435                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
12436                            QueryUtil.ALL_POS, null);
12437            }
12438    
12439            /**
12440             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12441             *
12442             * <p>
12443             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12444             * </p>
12445             *
12446             * @param userId the user ID
12447             * @param classNameId the class name ID
12448             * @param status the status
12449             * @param start the lower bound of the range of message-boards messages
12450             * @param end the upper bound of the range of message-boards messages (not inclusive)
12451             * @return the range of matching message-boards messages
12452             * @throws SystemException if a system exception occurred
12453             */
12454            public List<MBMessage> findByU_C_S(long userId, long classNameId,
12455                    int status, int start, int end) throws SystemException {
12456                    return findByU_C_S(userId, classNameId, status, start, end, null);
12457            }
12458    
12459            /**
12460             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12461             *
12462             * <p>
12463             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12464             * </p>
12465             *
12466             * @param userId the user ID
12467             * @param classNameId the class name ID
12468             * @param status the status
12469             * @param start the lower bound of the range of message-boards messages
12470             * @param end the upper bound of the range of message-boards messages (not inclusive)
12471             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12472             * @return the ordered 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, OrderByComparator orderByComparator)
12477                    throws SystemException {
12478                    FinderPath finderPath = null;
12479                    Object[] finderArgs = null;
12480    
12481                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12482                                    (orderByComparator == null)) {
12483                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
12484                            finderArgs = new Object[] { userId, classNameId, status };
12485                    }
12486                    else {
12487                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12488                            finderArgs = new Object[] {
12489                                            userId, classNameId, status,
12490                                            
12491                                            start, end, orderByComparator
12492                                    };
12493                    }
12494    
12495                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12496                                    finderArgs, this);
12497    
12498                    if ((list != null) && !list.isEmpty()) {
12499                            for (MBMessage mbMessage : list) {
12500                                    if ((userId != mbMessage.getUserId()) ||
12501                                                    (classNameId != mbMessage.getClassNameId()) ||
12502                                                    (status != mbMessage.getStatus())) {
12503                                            list = null;
12504    
12505                                            break;
12506                                    }
12507                            }
12508                    }
12509    
12510                    if (list == null) {
12511                            StringBundler query = null;
12512    
12513                            if (orderByComparator != null) {
12514                                    query = new StringBundler(5 +
12515                                                    (orderByComparator.getOrderByFields().length * 3));
12516                            }
12517                            else {
12518                                    query = new StringBundler(5);
12519                            }
12520    
12521                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12522    
12523                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
12524    
12525                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
12526    
12527                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
12528    
12529                            if (orderByComparator != null) {
12530                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12531                                            orderByComparator);
12532                            }
12533    
12534                            else {
12535                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12536                            }
12537    
12538                            String sql = query.toString();
12539    
12540                            Session session = null;
12541    
12542                            try {
12543                                    session = openSession();
12544    
12545                                    Query q = session.createQuery(sql);
12546    
12547                                    QueryPos qPos = QueryPos.getInstance(q);
12548    
12549                                    qPos.add(userId);
12550    
12551                                    qPos.add(classNameId);
12552    
12553                                    qPos.add(status);
12554    
12555                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12556                                                    end);
12557                            }
12558                            catch (Exception e) {
12559                                    throw processException(e);
12560                            }
12561                            finally {
12562                                    if (list == null) {
12563                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12564                                    }
12565                                    else {
12566                                            cacheResult(list);
12567    
12568                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12569                                    }
12570    
12571                                    closeSession(session);
12572                            }
12573                    }
12574    
12575                    return list;
12576            }
12577    
12578            /**
12579             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12580             *
12581             * @param userId the user ID
12582             * @param classNameId the class name ID
12583             * @param status the status
12584             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12585             * @return the first matching message-boards message
12586             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12587             * @throws SystemException if a system exception occurred
12588             */
12589            public MBMessage findByU_C_S_First(long userId, long classNameId,
12590                    int status, OrderByComparator orderByComparator)
12591                    throws NoSuchMessageException, SystemException {
12592                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
12593                                    orderByComparator);
12594    
12595                    if (mbMessage != null) {
12596                            return mbMessage;
12597                    }
12598    
12599                    StringBundler msg = new StringBundler(8);
12600    
12601                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12602    
12603                    msg.append("userId=");
12604                    msg.append(userId);
12605    
12606                    msg.append(", classNameId=");
12607                    msg.append(classNameId);
12608    
12609                    msg.append(", status=");
12610                    msg.append(status);
12611    
12612                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12613    
12614                    throw new NoSuchMessageException(msg.toString());
12615            }
12616    
12617            /**
12618             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12619             *
12620             * @param userId the user ID
12621             * @param classNameId the class name ID
12622             * @param status the status
12623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12624             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12625             * @throws SystemException if a system exception occurred
12626             */
12627            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
12628                    int status, OrderByComparator orderByComparator)
12629                    throws SystemException {
12630                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
12631                                    orderByComparator);
12632    
12633                    if (!list.isEmpty()) {
12634                            return list.get(0);
12635                    }
12636    
12637                    return null;
12638            }
12639    
12640            /**
12641             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12642             *
12643             * @param userId the user ID
12644             * @param classNameId the class name ID
12645             * @param status the status
12646             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12647             * @return the last matching message-boards message
12648             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12649             * @throws SystemException if a system exception occurred
12650             */
12651            public MBMessage findByU_C_S_Last(long userId, long classNameId,
12652                    int status, OrderByComparator orderByComparator)
12653                    throws NoSuchMessageException, SystemException {
12654                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
12655                                    orderByComparator);
12656    
12657                    if (mbMessage != null) {
12658                            return mbMessage;
12659                    }
12660    
12661                    StringBundler msg = new StringBundler(8);
12662    
12663                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12664    
12665                    msg.append("userId=");
12666                    msg.append(userId);
12667    
12668                    msg.append(", classNameId=");
12669                    msg.append(classNameId);
12670    
12671                    msg.append(", status=");
12672                    msg.append(status);
12673    
12674                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12675    
12676                    throw new NoSuchMessageException(msg.toString());
12677            }
12678    
12679            /**
12680             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12681             *
12682             * @param userId the user ID
12683             * @param classNameId the class name ID
12684             * @param status the status
12685             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12686             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12687             * @throws SystemException if a system exception occurred
12688             */
12689            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
12690                    int status, OrderByComparator orderByComparator)
12691                    throws SystemException {
12692                    int count = countByU_C_S(userId, classNameId, status);
12693    
12694                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
12695                                    count - 1, count, orderByComparator);
12696    
12697                    if (!list.isEmpty()) {
12698                            return list.get(0);
12699                    }
12700    
12701                    return null;
12702            }
12703    
12704            /**
12705             * 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;.
12706             *
12707             * @param messageId the primary key of the current message-boards message
12708             * @param userId the user ID
12709             * @param classNameId the class name ID
12710             * @param status the status
12711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12712             * @return the previous, current, and next message-boards message
12713             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12714             * @throws SystemException if a system exception occurred
12715             */
12716            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
12717                    long classNameId, int status, OrderByComparator orderByComparator)
12718                    throws NoSuchMessageException, SystemException {
12719                    MBMessage mbMessage = findByPrimaryKey(messageId);
12720    
12721                    Session session = null;
12722    
12723                    try {
12724                            session = openSession();
12725    
12726                            MBMessage[] array = new MBMessageImpl[3];
12727    
12728                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
12729                                            classNameId, status, orderByComparator, true);
12730    
12731                            array[1] = mbMessage;
12732    
12733                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
12734                                            classNameId, status, orderByComparator, false);
12735    
12736                            return array;
12737                    }
12738                    catch (Exception e) {
12739                            throw processException(e);
12740                    }
12741                    finally {
12742                            closeSession(session);
12743                    }
12744            }
12745    
12746            protected MBMessage getByU_C_S_PrevAndNext(Session session,
12747                    MBMessage mbMessage, long userId, long classNameId, int status,
12748                    OrderByComparator orderByComparator, boolean previous) {
12749                    StringBundler query = null;
12750    
12751                    if (orderByComparator != null) {
12752                            query = new StringBundler(6 +
12753                                            (orderByComparator.getOrderByFields().length * 6));
12754                    }
12755                    else {
12756                            query = new StringBundler(3);
12757                    }
12758    
12759                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12760    
12761                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
12762    
12763                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
12764    
12765                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
12766    
12767                    if (orderByComparator != null) {
12768                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12769    
12770                            if (orderByConditionFields.length > 0) {
12771                                    query.append(WHERE_AND);
12772                            }
12773    
12774                            for (int i = 0; i < orderByConditionFields.length; i++) {
12775                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12776                                    query.append(orderByConditionFields[i]);
12777    
12778                                    if ((i + 1) < orderByConditionFields.length) {
12779                                            if (orderByComparator.isAscending() ^ previous) {
12780                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12781                                            }
12782                                            else {
12783                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12784                                            }
12785                                    }
12786                                    else {
12787                                            if (orderByComparator.isAscending() ^ previous) {
12788                                                    query.append(WHERE_GREATER_THAN);
12789                                            }
12790                                            else {
12791                                                    query.append(WHERE_LESSER_THAN);
12792                                            }
12793                                    }
12794                            }
12795    
12796                            query.append(ORDER_BY_CLAUSE);
12797    
12798                            String[] orderByFields = orderByComparator.getOrderByFields();
12799    
12800                            for (int i = 0; i < orderByFields.length; i++) {
12801                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12802                                    query.append(orderByFields[i]);
12803    
12804                                    if ((i + 1) < orderByFields.length) {
12805                                            if (orderByComparator.isAscending() ^ previous) {
12806                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12807                                            }
12808                                            else {
12809                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12810                                            }
12811                                    }
12812                                    else {
12813                                            if (orderByComparator.isAscending() ^ previous) {
12814                                                    query.append(ORDER_BY_ASC);
12815                                            }
12816                                            else {
12817                                                    query.append(ORDER_BY_DESC);
12818                                            }
12819                                    }
12820                            }
12821                    }
12822    
12823                    else {
12824                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12825                    }
12826    
12827                    String sql = query.toString();
12828    
12829                    Query q = session.createQuery(sql);
12830    
12831                    q.setFirstResult(0);
12832                    q.setMaxResults(2);
12833    
12834                    QueryPos qPos = QueryPos.getInstance(q);
12835    
12836                    qPos.add(userId);
12837    
12838                    qPos.add(classNameId);
12839    
12840                    qPos.add(status);
12841    
12842                    if (orderByComparator != null) {
12843                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12844    
12845                            for (Object value : values) {
12846                                    qPos.add(value);
12847                            }
12848                    }
12849    
12850                    List<MBMessage> list = q.list();
12851    
12852                    if (list.size() == 2) {
12853                            return list.get(1);
12854                    }
12855                    else {
12856                            return null;
12857                    }
12858            }
12859    
12860            /**
12861             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12862             *
12863             * <p>
12864             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12865             * </p>
12866             *
12867             * @param userId the user ID
12868             * @param classNameIds the class name IDs
12869             * @param status the status
12870             * @return the matching message-boards messages
12871             * @throws SystemException if a system exception occurred
12872             */
12873            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12874                    int status) throws SystemException {
12875                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
12876                            QueryUtil.ALL_POS, null);
12877            }
12878    
12879            /**
12880             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12881             *
12882             * <p>
12883             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12884             * </p>
12885             *
12886             * @param userId the user ID
12887             * @param classNameIds the class name IDs
12888             * @param status the status
12889             * @param start the lower bound of the range of message-boards messages
12890             * @param end the upper bound of the range of message-boards messages (not inclusive)
12891             * @return the range of 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, int start, int end) throws SystemException {
12896                    return findByU_C_S(userId, classNameIds, status, start, end, null);
12897            }
12898    
12899            /**
12900             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12901             *
12902             * <p>
12903             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12904             * </p>
12905             *
12906             * @param userId the user ID
12907             * @param classNameIds the class name IDs
12908             * @param status the status
12909             * @param start the lower bound of the range of message-boards messages
12910             * @param end the upper bound of the range of message-boards messages (not inclusive)
12911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12912             * @return the ordered 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, OrderByComparator orderByComparator)
12917                    throws SystemException {
12918                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12919                    Object[] finderArgs = null;
12920    
12921                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12922                                    (orderByComparator == null)) {
12923                            finderArgs = new Object[] {
12924                                            userId, StringUtil.merge(classNameIds), status
12925                                    };
12926                    }
12927                    else {
12928                            finderArgs = new Object[] {
12929                                            userId, StringUtil.merge(classNameIds), status,
12930                                            
12931                                            start, end, orderByComparator
12932                                    };
12933                    }
12934    
12935                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12936                                    finderArgs, this);
12937    
12938                    if ((list != null) && !list.isEmpty()) {
12939                            for (MBMessage mbMessage : list) {
12940                                    if ((userId != mbMessage.getUserId()) ||
12941                                                    !ArrayUtil.contains(classNameIds,
12942                                                            mbMessage.getClassNameId()) ||
12943                                                    (status != mbMessage.getStatus())) {
12944                                            list = null;
12945    
12946                                            break;
12947                                    }
12948                            }
12949                    }
12950    
12951                    if (list == null) {
12952                            StringBundler query = new StringBundler();
12953    
12954                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12955    
12956                            boolean conjunctionable = false;
12957    
12958                            if (conjunctionable) {
12959                                    query.append(WHERE_AND);
12960                            }
12961    
12962                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
12963    
12964                            conjunctionable = true;
12965    
12966                            if ((classNameIds == null) || (classNameIds.length > 0)) {
12967                                    if (conjunctionable) {
12968                                            query.append(WHERE_AND);
12969                                    }
12970    
12971                                    query.append(StringPool.OPEN_PARENTHESIS);
12972    
12973                                    for (int i = 0; i < classNameIds.length; i++) {
12974                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
12975    
12976                                            if ((i + 1) < classNameIds.length) {
12977                                                    query.append(WHERE_OR);
12978                                            }
12979                                    }
12980    
12981                                    query.append(StringPool.CLOSE_PARENTHESIS);
12982    
12983                                    conjunctionable = true;
12984                            }
12985    
12986                            if (conjunctionable) {
12987                                    query.append(WHERE_AND);
12988                            }
12989    
12990                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
12991    
12992                            conjunctionable = true;
12993    
12994                            if (orderByComparator != null) {
12995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12996                                            orderByComparator);
12997                            }
12998    
12999                            else {
13000                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13001                            }
13002    
13003                            String sql = query.toString();
13004    
13005                            Session session = null;
13006    
13007                            try {
13008                                    session = openSession();
13009    
13010                                    Query q = session.createQuery(sql);
13011    
13012                                    QueryPos qPos = QueryPos.getInstance(q);
13013    
13014                                    qPos.add(userId);
13015    
13016                                    if (classNameIds != null) {
13017                                            qPos.add(classNameIds);
13018                                    }
13019    
13020                                    qPos.add(status);
13021    
13022                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13023                                                    end);
13024                            }
13025                            catch (Exception e) {
13026                                    throw processException(e);
13027                            }
13028                            finally {
13029                                    if (list == null) {
13030                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13031                                    }
13032                                    else {
13033                                            cacheResult(list);
13034    
13035                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13036                                    }
13037    
13038                                    closeSession(session);
13039                            }
13040                    }
13041    
13042                    return list;
13043            }
13044    
13045            /**
13046             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13047             *
13048             * @param classNameId the class name ID
13049             * @param classPK the class p k
13050             * @param status the status
13051             * @return the matching message-boards messages
13052             * @throws SystemException if a system exception occurred
13053             */
13054            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13055                    int status) throws SystemException {
13056                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
13057                            QueryUtil.ALL_POS, null);
13058            }
13059    
13060            /**
13061             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13062             *
13063             * <p>
13064             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13065             * </p>
13066             *
13067             * @param classNameId the class name ID
13068             * @param classPK the class p k
13069             * @param status the status
13070             * @param start the lower bound of the range of message-boards messages
13071             * @param end the upper bound of the range of message-boards messages (not inclusive)
13072             * @return the range of 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, int start, int end) throws SystemException {
13077                    return findByC_C_S(classNameId, classPK, status, start, end, null);
13078            }
13079    
13080            /**
13081             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13082             *
13083             * <p>
13084             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13085             * </p>
13086             *
13087             * @param classNameId the class name ID
13088             * @param classPK the class p k
13089             * @param status the status
13090             * @param start the lower bound of the range of message-boards messages
13091             * @param end the upper bound of the range of message-boards messages (not inclusive)
13092             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13093             * @return the ordered 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, OrderByComparator orderByComparator)
13098                    throws SystemException {
13099                    FinderPath finderPath = null;
13100                    Object[] finderArgs = null;
13101    
13102                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13103                                    (orderByComparator == null)) {
13104                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
13105                            finderArgs = new Object[] { classNameId, classPK, status };
13106                    }
13107                    else {
13108                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
13109                            finderArgs = new Object[] {
13110                                            classNameId, classPK, status,
13111                                            
13112                                            start, end, orderByComparator
13113                                    };
13114                    }
13115    
13116                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13117                                    finderArgs, this);
13118    
13119                    if ((list != null) && !list.isEmpty()) {
13120                            for (MBMessage mbMessage : list) {
13121                                    if ((classNameId != mbMessage.getClassNameId()) ||
13122                                                    (classPK != mbMessage.getClassPK()) ||
13123                                                    (status != mbMessage.getStatus())) {
13124                                            list = null;
13125    
13126                                            break;
13127                                    }
13128                            }
13129                    }
13130    
13131                    if (list == null) {
13132                            StringBundler query = null;
13133    
13134                            if (orderByComparator != null) {
13135                                    query = new StringBundler(5 +
13136                                                    (orderByComparator.getOrderByFields().length * 3));
13137                            }
13138                            else {
13139                                    query = new StringBundler(5);
13140                            }
13141    
13142                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13143    
13144                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
13145    
13146                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
13147    
13148                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
13149    
13150                            if (orderByComparator != null) {
13151                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13152                                            orderByComparator);
13153                            }
13154    
13155                            else {
13156                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13157                            }
13158    
13159                            String sql = query.toString();
13160    
13161                            Session session = null;
13162    
13163                            try {
13164                                    session = openSession();
13165    
13166                                    Query q = session.createQuery(sql);
13167    
13168                                    QueryPos qPos = QueryPos.getInstance(q);
13169    
13170                                    qPos.add(classNameId);
13171    
13172                                    qPos.add(classPK);
13173    
13174                                    qPos.add(status);
13175    
13176                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13177                                                    end);
13178                            }
13179                            catch (Exception e) {
13180                                    throw processException(e);
13181                            }
13182                            finally {
13183                                    if (list == null) {
13184                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13185                                    }
13186                                    else {
13187                                            cacheResult(list);
13188    
13189                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13190                                    }
13191    
13192                                    closeSession(session);
13193                            }
13194                    }
13195    
13196                    return list;
13197            }
13198    
13199            /**
13200             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13201             *
13202             * @param classNameId the class name ID
13203             * @param classPK the class p k
13204             * @param status the status
13205             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13206             * @return the first matching message-boards message
13207             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13208             * @throws SystemException if a system exception occurred
13209             */
13210            public MBMessage findByC_C_S_First(long classNameId, long classPK,
13211                    int status, OrderByComparator orderByComparator)
13212                    throws NoSuchMessageException, SystemException {
13213                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
13214                                    orderByComparator);
13215    
13216                    if (mbMessage != null) {
13217                            return mbMessage;
13218                    }
13219    
13220                    StringBundler msg = new StringBundler(8);
13221    
13222                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13223    
13224                    msg.append("classNameId=");
13225                    msg.append(classNameId);
13226    
13227                    msg.append(", classPK=");
13228                    msg.append(classPK);
13229    
13230                    msg.append(", status=");
13231                    msg.append(status);
13232    
13233                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13234    
13235                    throw new NoSuchMessageException(msg.toString());
13236            }
13237    
13238            /**
13239             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13240             *
13241             * @param classNameId the class name ID
13242             * @param classPK the class p k
13243             * @param status the status
13244             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13245             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13246             * @throws SystemException if a system exception occurred
13247             */
13248            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
13249                    int status, OrderByComparator orderByComparator)
13250                    throws SystemException {
13251                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
13252                                    orderByComparator);
13253    
13254                    if (!list.isEmpty()) {
13255                            return list.get(0);
13256                    }
13257    
13258                    return null;
13259            }
13260    
13261            /**
13262             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13263             *
13264             * @param classNameId the class name ID
13265             * @param classPK the class p k
13266             * @param status the status
13267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13268             * @return the last matching message-boards message
13269             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13270             * @throws SystemException if a system exception occurred
13271             */
13272            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
13273                    int status, OrderByComparator orderByComparator)
13274                    throws NoSuchMessageException, SystemException {
13275                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
13276                                    orderByComparator);
13277    
13278                    if (mbMessage != null) {
13279                            return mbMessage;
13280                    }
13281    
13282                    StringBundler msg = new StringBundler(8);
13283    
13284                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13285    
13286                    msg.append("classNameId=");
13287                    msg.append(classNameId);
13288    
13289                    msg.append(", classPK=");
13290                    msg.append(classPK);
13291    
13292                    msg.append(", status=");
13293                    msg.append(status);
13294    
13295                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13296    
13297                    throw new NoSuchMessageException(msg.toString());
13298            }
13299    
13300            /**
13301             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13302             *
13303             * @param classNameId the class name ID
13304             * @param classPK the class p k
13305             * @param status the status
13306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13307             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13308             * @throws SystemException if a system exception occurred
13309             */
13310            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
13311                    int status, OrderByComparator orderByComparator)
13312                    throws SystemException {
13313                    int count = countByC_C_S(classNameId, classPK, status);
13314    
13315                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
13316                                    count - 1, count, orderByComparator);
13317    
13318                    if (!list.isEmpty()) {
13319                            return list.get(0);
13320                    }
13321    
13322                    return null;
13323            }
13324    
13325            /**
13326             * 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;.
13327             *
13328             * @param messageId the primary key of the current message-boards message
13329             * @param classNameId the class name ID
13330             * @param classPK the class p k
13331             * @param status the status
13332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13333             * @return the previous, current, and next message-boards message
13334             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13335             * @throws SystemException if a system exception occurred
13336             */
13337            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
13338                    long classNameId, long classPK, int status,
13339                    OrderByComparator orderByComparator)
13340                    throws NoSuchMessageException, SystemException {
13341                    MBMessage mbMessage = findByPrimaryKey(messageId);
13342    
13343                    Session session = null;
13344    
13345                    try {
13346                            session = openSession();
13347    
13348                            MBMessage[] array = new MBMessageImpl[3];
13349    
13350                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
13351                                            classPK, status, orderByComparator, true);
13352    
13353                            array[1] = mbMessage;
13354    
13355                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
13356                                            classPK, status, orderByComparator, false);
13357    
13358                            return array;
13359                    }
13360                    catch (Exception e) {
13361                            throw processException(e);
13362                    }
13363                    finally {
13364                            closeSession(session);
13365                    }
13366            }
13367    
13368            protected MBMessage getByC_C_S_PrevAndNext(Session session,
13369                    MBMessage mbMessage, long classNameId, long classPK, int status,
13370                    OrderByComparator orderByComparator, boolean previous) {
13371                    StringBundler query = null;
13372    
13373                    if (orderByComparator != null) {
13374                            query = new StringBundler(6 +
13375                                            (orderByComparator.getOrderByFields().length * 6));
13376                    }
13377                    else {
13378                            query = new StringBundler(3);
13379                    }
13380    
13381                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13382    
13383                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
13384    
13385                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
13386    
13387                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
13388    
13389                    if (orderByComparator != null) {
13390                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13391    
13392                            if (orderByConditionFields.length > 0) {
13393                                    query.append(WHERE_AND);
13394                            }
13395    
13396                            for (int i = 0; i < orderByConditionFields.length; i++) {
13397                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13398                                    query.append(orderByConditionFields[i]);
13399    
13400                                    if ((i + 1) < orderByConditionFields.length) {
13401                                            if (orderByComparator.isAscending() ^ previous) {
13402                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13403                                            }
13404                                            else {
13405                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13406                                            }
13407                                    }
13408                                    else {
13409                                            if (orderByComparator.isAscending() ^ previous) {
13410                                                    query.append(WHERE_GREATER_THAN);
13411                                            }
13412                                            else {
13413                                                    query.append(WHERE_LESSER_THAN);
13414                                            }
13415                                    }
13416                            }
13417    
13418                            query.append(ORDER_BY_CLAUSE);
13419    
13420                            String[] orderByFields = orderByComparator.getOrderByFields();
13421    
13422                            for (int i = 0; i < orderByFields.length; i++) {
13423                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13424                                    query.append(orderByFields[i]);
13425    
13426                                    if ((i + 1) < orderByFields.length) {
13427                                            if (orderByComparator.isAscending() ^ previous) {
13428                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13429                                            }
13430                                            else {
13431                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13432                                            }
13433                                    }
13434                                    else {
13435                                            if (orderByComparator.isAscending() ^ previous) {
13436                                                    query.append(ORDER_BY_ASC);
13437                                            }
13438                                            else {
13439                                                    query.append(ORDER_BY_DESC);
13440                                            }
13441                                    }
13442                            }
13443                    }
13444    
13445                    else {
13446                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13447                    }
13448    
13449                    String sql = query.toString();
13450    
13451                    Query q = session.createQuery(sql);
13452    
13453                    q.setFirstResult(0);
13454                    q.setMaxResults(2);
13455    
13456                    QueryPos qPos = QueryPos.getInstance(q);
13457    
13458                    qPos.add(classNameId);
13459    
13460                    qPos.add(classPK);
13461    
13462                    qPos.add(status);
13463    
13464                    if (orderByComparator != null) {
13465                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13466    
13467                            for (Object value : values) {
13468                                    qPos.add(value);
13469                            }
13470                    }
13471    
13472                    List<MBMessage> list = q.list();
13473    
13474                    if (list.size() == 2) {
13475                            return list.get(1);
13476                    }
13477                    else {
13478                            return null;
13479                    }
13480            }
13481    
13482            /**
13483             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13484             *
13485             * @param groupId the group ID
13486             * @param categoryId the category ID
13487             * @param threadId the thread ID
13488             * @param answer the answer
13489             * @return the matching message-boards messages
13490             * @throws SystemException if a system exception occurred
13491             */
13492            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13493                    long threadId, boolean answer) throws SystemException {
13494                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
13495                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13496            }
13497    
13498            /**
13499             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13500             *
13501             * <p>
13502             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13503             * </p>
13504             *
13505             * @param groupId the group ID
13506             * @param categoryId the category ID
13507             * @param threadId the thread ID
13508             * @param answer the answer
13509             * @param start the lower bound of the range of message-boards messages
13510             * @param end the upper bound of the range of message-boards messages (not inclusive)
13511             * @return the range of matching message-boards messages
13512             * @throws SystemException if a system exception occurred
13513             */
13514            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13515                    long threadId, boolean answer, int start, int end)
13516                    throws SystemException {
13517                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
13518                            null);
13519            }
13520    
13521            /**
13522             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13523             *
13524             * <p>
13525             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13526             * </p>
13527             *
13528             * @param groupId the group ID
13529             * @param categoryId the category ID
13530             * @param threadId the thread ID
13531             * @param answer the answer
13532             * @param start the lower bound of the range of message-boards messages
13533             * @param end the upper bound of the range of message-boards messages (not inclusive)
13534             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13535             * @return the ordered range of matching message-boards messages
13536             * @throws SystemException if a system exception occurred
13537             */
13538            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13539                    long threadId, boolean answer, int start, int end,
13540                    OrderByComparator orderByComparator) throws SystemException {
13541                    FinderPath finderPath = null;
13542                    Object[] finderArgs = null;
13543    
13544                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13545                                    (orderByComparator == null)) {
13546                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
13547                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
13548                    }
13549                    else {
13550                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
13551                            finderArgs = new Object[] {
13552                                            groupId, categoryId, threadId, answer,
13553                                            
13554                                            start, end, orderByComparator
13555                                    };
13556                    }
13557    
13558                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13559                                    finderArgs, this);
13560    
13561                    if ((list != null) && !list.isEmpty()) {
13562                            for (MBMessage mbMessage : list) {
13563                                    if ((groupId != mbMessage.getGroupId()) ||
13564                                                    (categoryId != mbMessage.getCategoryId()) ||
13565                                                    (threadId != mbMessage.getThreadId()) ||
13566                                                    (answer != mbMessage.getAnswer())) {
13567                                            list = null;
13568    
13569                                            break;
13570                                    }
13571                            }
13572                    }
13573    
13574                    if (list == null) {
13575                            StringBundler query = null;
13576    
13577                            if (orderByComparator != null) {
13578                                    query = new StringBundler(6 +
13579                                                    (orderByComparator.getOrderByFields().length * 3));
13580                            }
13581                            else {
13582                                    query = new StringBundler(6);
13583                            }
13584    
13585                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13586    
13587                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13588    
13589                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13590    
13591                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13592    
13593                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13594    
13595                            if (orderByComparator != null) {
13596                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13597                                            orderByComparator);
13598                            }
13599    
13600                            else {
13601                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13602                            }
13603    
13604                            String sql = query.toString();
13605    
13606                            Session session = null;
13607    
13608                            try {
13609                                    session = openSession();
13610    
13611                                    Query q = session.createQuery(sql);
13612    
13613                                    QueryPos qPos = QueryPos.getInstance(q);
13614    
13615                                    qPos.add(groupId);
13616    
13617                                    qPos.add(categoryId);
13618    
13619                                    qPos.add(threadId);
13620    
13621                                    qPos.add(answer);
13622    
13623                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13624                                                    end);
13625                            }
13626                            catch (Exception e) {
13627                                    throw processException(e);
13628                            }
13629                            finally {
13630                                    if (list == null) {
13631                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13632                                    }
13633                                    else {
13634                                            cacheResult(list);
13635    
13636                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13637                                    }
13638    
13639                                    closeSession(session);
13640                            }
13641                    }
13642    
13643                    return list;
13644            }
13645    
13646            /**
13647             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13648             *
13649             * @param groupId the group ID
13650             * @param categoryId the category ID
13651             * @param threadId the thread ID
13652             * @param answer the answer
13653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13654             * @return the first matching message-boards message
13655             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13656             * @throws SystemException if a system exception occurred
13657             */
13658            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
13659                    long threadId, boolean answer, OrderByComparator orderByComparator)
13660                    throws NoSuchMessageException, SystemException {
13661                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
13662                                    threadId, answer, orderByComparator);
13663    
13664                    if (mbMessage != null) {
13665                            return mbMessage;
13666                    }
13667    
13668                    StringBundler msg = new StringBundler(10);
13669    
13670                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13671    
13672                    msg.append("groupId=");
13673                    msg.append(groupId);
13674    
13675                    msg.append(", categoryId=");
13676                    msg.append(categoryId);
13677    
13678                    msg.append(", threadId=");
13679                    msg.append(threadId);
13680    
13681                    msg.append(", answer=");
13682                    msg.append(answer);
13683    
13684                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13685    
13686                    throw new NoSuchMessageException(msg.toString());
13687            }
13688    
13689            /**
13690             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13691             *
13692             * @param groupId the group ID
13693             * @param categoryId the category ID
13694             * @param threadId the thread ID
13695             * @param answer the answer
13696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13697             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13698             * @throws SystemException if a system exception occurred
13699             */
13700            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
13701                    long threadId, boolean answer, OrderByComparator orderByComparator)
13702                    throws SystemException {
13703                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
13704                                    answer, 0, 1, orderByComparator);
13705    
13706                    if (!list.isEmpty()) {
13707                            return list.get(0);
13708                    }
13709    
13710                    return null;
13711            }
13712    
13713            /**
13714             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13715             *
13716             * @param groupId the group ID
13717             * @param categoryId the category ID
13718             * @param threadId the thread ID
13719             * @param answer the answer
13720             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13721             * @return the last matching message-boards message
13722             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13723             * @throws SystemException if a system exception occurred
13724             */
13725            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
13726                    long threadId, boolean answer, OrderByComparator orderByComparator)
13727                    throws NoSuchMessageException, SystemException {
13728                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
13729                                    threadId, answer, orderByComparator);
13730    
13731                    if (mbMessage != null) {
13732                            return mbMessage;
13733                    }
13734    
13735                    StringBundler msg = new StringBundler(10);
13736    
13737                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13738    
13739                    msg.append("groupId=");
13740                    msg.append(groupId);
13741    
13742                    msg.append(", categoryId=");
13743                    msg.append(categoryId);
13744    
13745                    msg.append(", threadId=");
13746                    msg.append(threadId);
13747    
13748                    msg.append(", answer=");
13749                    msg.append(answer);
13750    
13751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13752    
13753                    throw new NoSuchMessageException(msg.toString());
13754            }
13755    
13756            /**
13757             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13758             *
13759             * @param groupId the group ID
13760             * @param categoryId the category ID
13761             * @param threadId the thread ID
13762             * @param answer the answer
13763             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13764             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13765             * @throws SystemException if a system exception occurred
13766             */
13767            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
13768                    long threadId, boolean answer, OrderByComparator orderByComparator)
13769                    throws SystemException {
13770                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
13771    
13772                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
13773                                    answer, count - 1, count, orderByComparator);
13774    
13775                    if (!list.isEmpty()) {
13776                            return list.get(0);
13777                    }
13778    
13779                    return null;
13780            }
13781    
13782            /**
13783             * 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;.
13784             *
13785             * @param messageId the primary key of the current message-boards message
13786             * @param groupId the group ID
13787             * @param categoryId the category ID
13788             * @param threadId the thread ID
13789             * @param answer the answer
13790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13791             * @return the previous, current, and next message-boards message
13792             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13793             * @throws SystemException if a system exception occurred
13794             */
13795            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
13796                    long categoryId, long threadId, boolean answer,
13797                    OrderByComparator orderByComparator)
13798                    throws NoSuchMessageException, SystemException {
13799                    MBMessage mbMessage = findByPrimaryKey(messageId);
13800    
13801                    Session session = null;
13802    
13803                    try {
13804                            session = openSession();
13805    
13806                            MBMessage[] array = new MBMessageImpl[3];
13807    
13808                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
13809                                            categoryId, threadId, answer, orderByComparator, true);
13810    
13811                            array[1] = mbMessage;
13812    
13813                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
13814                                            categoryId, threadId, answer, orderByComparator, false);
13815    
13816                            return array;
13817                    }
13818                    catch (Exception e) {
13819                            throw processException(e);
13820                    }
13821                    finally {
13822                            closeSession(session);
13823                    }
13824            }
13825    
13826            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
13827                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13828                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
13829                    StringBundler query = null;
13830    
13831                    if (orderByComparator != null) {
13832                            query = new StringBundler(6 +
13833                                            (orderByComparator.getOrderByFields().length * 6));
13834                    }
13835                    else {
13836                            query = new StringBundler(3);
13837                    }
13838    
13839                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13840    
13841                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13842    
13843                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13844    
13845                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13846    
13847                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13848    
13849                    if (orderByComparator != null) {
13850                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13851    
13852                            if (orderByConditionFields.length > 0) {
13853                                    query.append(WHERE_AND);
13854                            }
13855    
13856                            for (int i = 0; i < orderByConditionFields.length; i++) {
13857                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13858                                    query.append(orderByConditionFields[i]);
13859    
13860                                    if ((i + 1) < orderByConditionFields.length) {
13861                                            if (orderByComparator.isAscending() ^ previous) {
13862                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13863                                            }
13864                                            else {
13865                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13866                                            }
13867                                    }
13868                                    else {
13869                                            if (orderByComparator.isAscending() ^ previous) {
13870                                                    query.append(WHERE_GREATER_THAN);
13871                                            }
13872                                            else {
13873                                                    query.append(WHERE_LESSER_THAN);
13874                                            }
13875                                    }
13876                            }
13877    
13878                            query.append(ORDER_BY_CLAUSE);
13879    
13880                            String[] orderByFields = orderByComparator.getOrderByFields();
13881    
13882                            for (int i = 0; i < orderByFields.length; i++) {
13883                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13884                                    query.append(orderByFields[i]);
13885    
13886                                    if ((i + 1) < orderByFields.length) {
13887                                            if (orderByComparator.isAscending() ^ previous) {
13888                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13889                                            }
13890                                            else {
13891                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13892                                            }
13893                                    }
13894                                    else {
13895                                            if (orderByComparator.isAscending() ^ previous) {
13896                                                    query.append(ORDER_BY_ASC);
13897                                            }
13898                                            else {
13899                                                    query.append(ORDER_BY_DESC);
13900                                            }
13901                                    }
13902                            }
13903                    }
13904    
13905                    else {
13906                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13907                    }
13908    
13909                    String sql = query.toString();
13910    
13911                    Query q = session.createQuery(sql);
13912    
13913                    q.setFirstResult(0);
13914                    q.setMaxResults(2);
13915    
13916                    QueryPos qPos = QueryPos.getInstance(q);
13917    
13918                    qPos.add(groupId);
13919    
13920                    qPos.add(categoryId);
13921    
13922                    qPos.add(threadId);
13923    
13924                    qPos.add(answer);
13925    
13926                    if (orderByComparator != null) {
13927                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13928    
13929                            for (Object value : values) {
13930                                    qPos.add(value);
13931                            }
13932                    }
13933    
13934                    List<MBMessage> list = q.list();
13935    
13936                    if (list.size() == 2) {
13937                            return list.get(1);
13938                    }
13939                    else {
13940                            return null;
13941                    }
13942            }
13943    
13944            /**
13945             * 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;.
13946             *
13947             * @param groupId the group ID
13948             * @param categoryId the category ID
13949             * @param threadId the thread ID
13950             * @param answer the answer
13951             * @return the matching message-boards messages that the user has permission to view
13952             * @throws SystemException if a system exception occurred
13953             */
13954            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13955                    long threadId, boolean answer) throws SystemException {
13956                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13957                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13958            }
13959    
13960            /**
13961             * 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;.
13962             *
13963             * <p>
13964             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13965             * </p>
13966             *
13967             * @param groupId the group ID
13968             * @param categoryId the category ID
13969             * @param threadId the thread ID
13970             * @param answer the answer
13971             * @param start the lower bound of the range of message-boards messages
13972             * @param end the upper bound of the range of message-boards messages (not inclusive)
13973             * @return the range of matching message-boards messages that the user has permission to view
13974             * @throws SystemException if a system exception occurred
13975             */
13976            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13977                    long threadId, boolean answer, int start, int end)
13978                    throws SystemException {
13979                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13980                            start, end, null);
13981            }
13982    
13983            /**
13984             * 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;.
13985             *
13986             * <p>
13987             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13988             * </p>
13989             *
13990             * @param groupId the group ID
13991             * @param categoryId the category ID
13992             * @param threadId the thread ID
13993             * @param answer the answer
13994             * @param start the lower bound of the range of message-boards messages
13995             * @param end the upper bound of the range of message-boards messages (not inclusive)
13996             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13997             * @return the ordered range of matching message-boards messages that the user has permission to view
13998             * @throws SystemException if a system exception occurred
13999             */
14000            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
14001                    long threadId, boolean answer, int start, int end,
14002                    OrderByComparator orderByComparator) throws SystemException {
14003                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14004                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
14005                                    end, orderByComparator);
14006                    }
14007    
14008                    StringBundler query = null;
14009    
14010                    if (orderByComparator != null) {
14011                            query = new StringBundler(6 +
14012                                            (orderByComparator.getOrderByFields().length * 3));
14013                    }
14014                    else {
14015                            query = new StringBundler(6);
14016                    }
14017    
14018                    if (getDB().isSupportsInlineDistinct()) {
14019                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14020                    }
14021                    else {
14022                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14023                    }
14024    
14025                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14026    
14027                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14028    
14029                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14030    
14031                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14032    
14033                    if (!getDB().isSupportsInlineDistinct()) {
14034                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14035                    }
14036    
14037                    if (orderByComparator != null) {
14038                            if (getDB().isSupportsInlineDistinct()) {
14039                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14040                                            orderByComparator);
14041                            }
14042                            else {
14043                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14044                                            orderByComparator);
14045                            }
14046                    }
14047    
14048                    else {
14049                            if (getDB().isSupportsInlineDistinct()) {
14050                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14051                            }
14052                            else {
14053                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14054                            }
14055                    }
14056    
14057                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14058                                    MBMessage.class.getName(),
14059                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14060    
14061                    Session session = null;
14062    
14063                    try {
14064                            session = openSession();
14065    
14066                            SQLQuery q = session.createSQLQuery(sql);
14067    
14068                            if (getDB().isSupportsInlineDistinct()) {
14069                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14070                            }
14071                            else {
14072                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14073                            }
14074    
14075                            QueryPos qPos = QueryPos.getInstance(q);
14076    
14077                            qPos.add(groupId);
14078    
14079                            qPos.add(categoryId);
14080    
14081                            qPos.add(threadId);
14082    
14083                            qPos.add(answer);
14084    
14085                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
14086                    }
14087                    catch (Exception e) {
14088                            throw processException(e);
14089                    }
14090                    finally {
14091                            closeSession(session);
14092                    }
14093            }
14094    
14095            /**
14096             * 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;.
14097             *
14098             * @param messageId the primary key of the current message-boards message
14099             * @param groupId the group ID
14100             * @param categoryId the category ID
14101             * @param threadId the thread ID
14102             * @param answer the answer
14103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14104             * @return the previous, current, and next message-boards message
14105             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14106             * @throws SystemException if a system exception occurred
14107             */
14108            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
14109                    long groupId, long categoryId, long threadId, boolean answer,
14110                    OrderByComparator orderByComparator)
14111                    throws NoSuchMessageException, SystemException {
14112                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14113                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
14114                                    threadId, answer, orderByComparator);
14115                    }
14116    
14117                    MBMessage mbMessage = findByPrimaryKey(messageId);
14118    
14119                    Session session = null;
14120    
14121                    try {
14122                            session = openSession();
14123    
14124                            MBMessage[] array = new MBMessageImpl[3];
14125    
14126                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
14127                                            groupId, categoryId, threadId, answer, orderByComparator,
14128                                            true);
14129    
14130                            array[1] = mbMessage;
14131    
14132                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
14133                                            groupId, categoryId, threadId, answer, orderByComparator,
14134                                            false);
14135    
14136                            return array;
14137                    }
14138                    catch (Exception e) {
14139                            throw processException(e);
14140                    }
14141                    finally {
14142                            closeSession(session);
14143                    }
14144            }
14145    
14146            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
14147                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14148                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
14149                    StringBundler query = null;
14150    
14151                    if (orderByComparator != null) {
14152                            query = new StringBundler(6 +
14153                                            (orderByComparator.getOrderByFields().length * 6));
14154                    }
14155                    else {
14156                            query = new StringBundler(3);
14157                    }
14158    
14159                    if (getDB().isSupportsInlineDistinct()) {
14160                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14161                    }
14162                    else {
14163                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14164                    }
14165    
14166                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14167    
14168                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14169    
14170                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14171    
14172                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14173    
14174                    if (!getDB().isSupportsInlineDistinct()) {
14175                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14176                    }
14177    
14178                    if (orderByComparator != null) {
14179                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14180    
14181                            if (orderByConditionFields.length > 0) {
14182                                    query.append(WHERE_AND);
14183                            }
14184    
14185                            for (int i = 0; i < orderByConditionFields.length; i++) {
14186                                    if (getDB().isSupportsInlineDistinct()) {
14187                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14188                                    }
14189                                    else {
14190                                            query.append(_ORDER_BY_ENTITY_TABLE);
14191                                    }
14192    
14193                                    query.append(orderByConditionFields[i]);
14194    
14195                                    if ((i + 1) < orderByConditionFields.length) {
14196                                            if (orderByComparator.isAscending() ^ previous) {
14197                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14198                                            }
14199                                            else {
14200                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14201                                            }
14202                                    }
14203                                    else {
14204                                            if (orderByComparator.isAscending() ^ previous) {
14205                                                    query.append(WHERE_GREATER_THAN);
14206                                            }
14207                                            else {
14208                                                    query.append(WHERE_LESSER_THAN);
14209                                            }
14210                                    }
14211                            }
14212    
14213                            query.append(ORDER_BY_CLAUSE);
14214    
14215                            String[] orderByFields = orderByComparator.getOrderByFields();
14216    
14217                            for (int i = 0; i < orderByFields.length; i++) {
14218                                    if (getDB().isSupportsInlineDistinct()) {
14219                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14220                                    }
14221                                    else {
14222                                            query.append(_ORDER_BY_ENTITY_TABLE);
14223                                    }
14224    
14225                                    query.append(orderByFields[i]);
14226    
14227                                    if ((i + 1) < orderByFields.length) {
14228                                            if (orderByComparator.isAscending() ^ previous) {
14229                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14230                                            }
14231                                            else {
14232                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14233                                            }
14234                                    }
14235                                    else {
14236                                            if (orderByComparator.isAscending() ^ previous) {
14237                                                    query.append(ORDER_BY_ASC);
14238                                            }
14239                                            else {
14240                                                    query.append(ORDER_BY_DESC);
14241                                            }
14242                                    }
14243                            }
14244                    }
14245    
14246                    else {
14247                            if (getDB().isSupportsInlineDistinct()) {
14248                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14249                            }
14250                            else {
14251                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14252                            }
14253                    }
14254    
14255                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14256                                    MBMessage.class.getName(),
14257                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14258    
14259                    SQLQuery q = session.createSQLQuery(sql);
14260    
14261                    q.setFirstResult(0);
14262                    q.setMaxResults(2);
14263    
14264                    if (getDB().isSupportsInlineDistinct()) {
14265                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14266                    }
14267                    else {
14268                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14269                    }
14270    
14271                    QueryPos qPos = QueryPos.getInstance(q);
14272    
14273                    qPos.add(groupId);
14274    
14275                    qPos.add(categoryId);
14276    
14277                    qPos.add(threadId);
14278    
14279                    qPos.add(answer);
14280    
14281                    if (orderByComparator != null) {
14282                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14283    
14284                            for (Object value : values) {
14285                                    qPos.add(value);
14286                            }
14287                    }
14288    
14289                    List<MBMessage> list = q.list();
14290    
14291                    if (list.size() == 2) {
14292                            return list.get(1);
14293                    }
14294                    else {
14295                            return null;
14296                    }
14297            }
14298    
14299            /**
14300             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14301             *
14302             * @param groupId the group ID
14303             * @param categoryId the category ID
14304             * @param threadId the thread ID
14305             * @param status the status
14306             * @return the matching message-boards messages
14307             * @throws SystemException if a system exception occurred
14308             */
14309            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14310                    long threadId, int status) throws SystemException {
14311                    return findByG_C_T_S(groupId, categoryId, threadId, status,
14312                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14313            }
14314    
14315            /**
14316             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14317             *
14318             * <p>
14319             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14320             * </p>
14321             *
14322             * @param groupId the group ID
14323             * @param categoryId the category ID
14324             * @param threadId the thread ID
14325             * @param status the status
14326             * @param start the lower bound of the range of message-boards messages
14327             * @param end the upper bound of the range of message-boards messages (not inclusive)
14328             * @return the range of matching message-boards messages
14329             * @throws SystemException if a system exception occurred
14330             */
14331            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14332                    long threadId, int status, int start, int end)
14333                    throws SystemException {
14334                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
14335                            null);
14336            }
14337    
14338            /**
14339             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14340             *
14341             * <p>
14342             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14343             * </p>
14344             *
14345             * @param groupId the group ID
14346             * @param categoryId the category ID
14347             * @param threadId the thread ID
14348             * @param status the status
14349             * @param start the lower bound of the range of message-boards messages
14350             * @param end the upper bound of the range of message-boards messages (not inclusive)
14351             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14352             * @return the ordered range of matching message-boards messages
14353             * @throws SystemException if a system exception occurred
14354             */
14355            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14356                    long threadId, int status, int start, int end,
14357                    OrderByComparator orderByComparator) throws SystemException {
14358                    FinderPath finderPath = null;
14359                    Object[] finderArgs = null;
14360    
14361                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14362                                    (orderByComparator == null)) {
14363                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
14364                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
14365                    }
14366                    else {
14367                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
14368                            finderArgs = new Object[] {
14369                                            groupId, categoryId, threadId, status,
14370                                            
14371                                            start, end, orderByComparator
14372                                    };
14373                    }
14374    
14375                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14376                                    finderArgs, this);
14377    
14378                    if ((list != null) && !list.isEmpty()) {
14379                            for (MBMessage mbMessage : list) {
14380                                    if ((groupId != mbMessage.getGroupId()) ||
14381                                                    (categoryId != mbMessage.getCategoryId()) ||
14382                                                    (threadId != mbMessage.getThreadId()) ||
14383                                                    (status != mbMessage.getStatus())) {
14384                                            list = null;
14385    
14386                                            break;
14387                                    }
14388                            }
14389                    }
14390    
14391                    if (list == null) {
14392                            StringBundler query = null;
14393    
14394                            if (orderByComparator != null) {
14395                                    query = new StringBundler(6 +
14396                                                    (orderByComparator.getOrderByFields().length * 3));
14397                            }
14398                            else {
14399                                    query = new StringBundler(6);
14400                            }
14401    
14402                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14403    
14404                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14405    
14406                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14407    
14408                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14409    
14410                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14411    
14412                            if (orderByComparator != null) {
14413                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14414                                            orderByComparator);
14415                            }
14416    
14417                            else {
14418                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14419                            }
14420    
14421                            String sql = query.toString();
14422    
14423                            Session session = null;
14424    
14425                            try {
14426                                    session = openSession();
14427    
14428                                    Query q = session.createQuery(sql);
14429    
14430                                    QueryPos qPos = QueryPos.getInstance(q);
14431    
14432                                    qPos.add(groupId);
14433    
14434                                    qPos.add(categoryId);
14435    
14436                                    qPos.add(threadId);
14437    
14438                                    qPos.add(status);
14439    
14440                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
14441                                                    end);
14442                            }
14443                            catch (Exception e) {
14444                                    throw processException(e);
14445                            }
14446                            finally {
14447                                    if (list == null) {
14448                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14449                                    }
14450                                    else {
14451                                            cacheResult(list);
14452    
14453                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14454                                    }
14455    
14456                                    closeSession(session);
14457                            }
14458                    }
14459    
14460                    return list;
14461            }
14462    
14463            /**
14464             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14465             *
14466             * @param groupId the group ID
14467             * @param categoryId the category ID
14468             * @param threadId the thread ID
14469             * @param status the status
14470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14471             * @return the first matching message-boards message
14472             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14473             * @throws SystemException if a system exception occurred
14474             */
14475            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
14476                    long threadId, int status, OrderByComparator orderByComparator)
14477                    throws NoSuchMessageException, SystemException {
14478                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
14479                                    threadId, status, orderByComparator);
14480    
14481                    if (mbMessage != null) {
14482                            return mbMessage;
14483                    }
14484    
14485                    StringBundler msg = new StringBundler(10);
14486    
14487                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14488    
14489                    msg.append("groupId=");
14490                    msg.append(groupId);
14491    
14492                    msg.append(", categoryId=");
14493                    msg.append(categoryId);
14494    
14495                    msg.append(", threadId=");
14496                    msg.append(threadId);
14497    
14498                    msg.append(", status=");
14499                    msg.append(status);
14500    
14501                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14502    
14503                    throw new NoSuchMessageException(msg.toString());
14504            }
14505    
14506            /**
14507             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14508             *
14509             * @param groupId the group ID
14510             * @param categoryId the category ID
14511             * @param threadId the thread ID
14512             * @param status the status
14513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14514             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14515             * @throws SystemException if a system exception occurred
14516             */
14517            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
14518                    long threadId, int status, OrderByComparator orderByComparator)
14519                    throws SystemException {
14520                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
14521                                    status, 0, 1, orderByComparator);
14522    
14523                    if (!list.isEmpty()) {
14524                            return list.get(0);
14525                    }
14526    
14527                    return null;
14528            }
14529    
14530            /**
14531             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14532             *
14533             * @param groupId the group ID
14534             * @param categoryId the category ID
14535             * @param threadId the thread ID
14536             * @param status the status
14537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14538             * @return the last matching message-boards message
14539             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14540             * @throws SystemException if a system exception occurred
14541             */
14542            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
14543                    long threadId, int status, OrderByComparator orderByComparator)
14544                    throws NoSuchMessageException, SystemException {
14545                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
14546                                    threadId, status, orderByComparator);
14547    
14548                    if (mbMessage != null) {
14549                            return mbMessage;
14550                    }
14551    
14552                    StringBundler msg = new StringBundler(10);
14553    
14554                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14555    
14556                    msg.append("groupId=");
14557                    msg.append(groupId);
14558    
14559                    msg.append(", categoryId=");
14560                    msg.append(categoryId);
14561    
14562                    msg.append(", threadId=");
14563                    msg.append(threadId);
14564    
14565                    msg.append(", status=");
14566                    msg.append(status);
14567    
14568                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14569    
14570                    throw new NoSuchMessageException(msg.toString());
14571            }
14572    
14573            /**
14574             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14575             *
14576             * @param groupId the group ID
14577             * @param categoryId the category ID
14578             * @param threadId the thread ID
14579             * @param status the status
14580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14581             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14582             * @throws SystemException if a system exception occurred
14583             */
14584            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
14585                    long threadId, int status, OrderByComparator orderByComparator)
14586                    throws SystemException {
14587                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
14588    
14589                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
14590                                    status, count - 1, count, orderByComparator);
14591    
14592                    if (!list.isEmpty()) {
14593                            return list.get(0);
14594                    }
14595    
14596                    return null;
14597            }
14598    
14599            /**
14600             * 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;.
14601             *
14602             * @param messageId the primary key of the current message-boards message
14603             * @param groupId the group ID
14604             * @param categoryId the category ID
14605             * @param threadId the thread ID
14606             * @param status the status
14607             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14608             * @return the previous, current, and next message-boards message
14609             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14610             * @throws SystemException if a system exception occurred
14611             */
14612            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
14613                    long categoryId, long threadId, int status,
14614                    OrderByComparator orderByComparator)
14615                    throws NoSuchMessageException, SystemException {
14616                    MBMessage mbMessage = findByPrimaryKey(messageId);
14617    
14618                    Session session = null;
14619    
14620                    try {
14621                            session = openSession();
14622    
14623                            MBMessage[] array = new MBMessageImpl[3];
14624    
14625                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
14626                                            categoryId, threadId, status, orderByComparator, true);
14627    
14628                            array[1] = mbMessage;
14629    
14630                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
14631                                            categoryId, threadId, status, orderByComparator, false);
14632    
14633                            return array;
14634                    }
14635                    catch (Exception e) {
14636                            throw processException(e);
14637                    }
14638                    finally {
14639                            closeSession(session);
14640                    }
14641            }
14642    
14643            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
14644                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14645                    int status, OrderByComparator orderByComparator, boolean previous) {
14646                    StringBundler query = null;
14647    
14648                    if (orderByComparator != null) {
14649                            query = new StringBundler(6 +
14650                                            (orderByComparator.getOrderByFields().length * 6));
14651                    }
14652                    else {
14653                            query = new StringBundler(3);
14654                    }
14655    
14656                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14657    
14658                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14659    
14660                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14661    
14662                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14663    
14664                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14665    
14666                    if (orderByComparator != null) {
14667                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14668    
14669                            if (orderByConditionFields.length > 0) {
14670                                    query.append(WHERE_AND);
14671                            }
14672    
14673                            for (int i = 0; i < orderByConditionFields.length; i++) {
14674                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14675                                    query.append(orderByConditionFields[i]);
14676    
14677                                    if ((i + 1) < orderByConditionFields.length) {
14678                                            if (orderByComparator.isAscending() ^ previous) {
14679                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14680                                            }
14681                                            else {
14682                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14683                                            }
14684                                    }
14685                                    else {
14686                                            if (orderByComparator.isAscending() ^ previous) {
14687                                                    query.append(WHERE_GREATER_THAN);
14688                                            }
14689                                            else {
14690                                                    query.append(WHERE_LESSER_THAN);
14691                                            }
14692                                    }
14693                            }
14694    
14695                            query.append(ORDER_BY_CLAUSE);
14696    
14697                            String[] orderByFields = orderByComparator.getOrderByFields();
14698    
14699                            for (int i = 0; i < orderByFields.length; i++) {
14700                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14701                                    query.append(orderByFields[i]);
14702    
14703                                    if ((i + 1) < orderByFields.length) {
14704                                            if (orderByComparator.isAscending() ^ previous) {
14705                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14706                                            }
14707                                            else {
14708                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14709                                            }
14710                                    }
14711                                    else {
14712                                            if (orderByComparator.isAscending() ^ previous) {
14713                                                    query.append(ORDER_BY_ASC);
14714                                            }
14715                                            else {
14716                                                    query.append(ORDER_BY_DESC);
14717                                            }
14718                                    }
14719                            }
14720                    }
14721    
14722                    else {
14723                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14724                    }
14725    
14726                    String sql = query.toString();
14727    
14728                    Query q = session.createQuery(sql);
14729    
14730                    q.setFirstResult(0);
14731                    q.setMaxResults(2);
14732    
14733                    QueryPos qPos = QueryPos.getInstance(q);
14734    
14735                    qPos.add(groupId);
14736    
14737                    qPos.add(categoryId);
14738    
14739                    qPos.add(threadId);
14740    
14741                    qPos.add(status);
14742    
14743                    if (orderByComparator != null) {
14744                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14745    
14746                            for (Object value : values) {
14747                                    qPos.add(value);
14748                            }
14749                    }
14750    
14751                    List<MBMessage> list = q.list();
14752    
14753                    if (list.size() == 2) {
14754                            return list.get(1);
14755                    }
14756                    else {
14757                            return null;
14758                    }
14759            }
14760    
14761            /**
14762             * 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;.
14763             *
14764             * @param groupId the group ID
14765             * @param categoryId the category ID
14766             * @param threadId the thread ID
14767             * @param status the status
14768             * @return the matching message-boards messages that the user has permission to view
14769             * @throws SystemException if a system exception occurred
14770             */
14771            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14772                    long threadId, int status) throws SystemException {
14773                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
14774                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14775            }
14776    
14777            /**
14778             * 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;.
14779             *
14780             * <p>
14781             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14782             * </p>
14783             *
14784             * @param groupId the group ID
14785             * @param categoryId the category ID
14786             * @param threadId the thread ID
14787             * @param status the status
14788             * @param start the lower bound of the range of message-boards messages
14789             * @param end the upper bound of the range of message-boards messages (not inclusive)
14790             * @return the range of matching message-boards messages that the user has permission to view
14791             * @throws SystemException if a system exception occurred
14792             */
14793            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14794                    long threadId, int status, int start, int end)
14795                    throws SystemException {
14796                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
14797                            start, end, null);
14798            }
14799    
14800            /**
14801             * 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;.
14802             *
14803             * <p>
14804             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14805             * </p>
14806             *
14807             * @param groupId the group ID
14808             * @param categoryId the category ID
14809             * @param threadId the thread ID
14810             * @param status the status
14811             * @param start the lower bound of the range of message-boards messages
14812             * @param end the upper bound of the range of message-boards messages (not inclusive)
14813             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14814             * @return the ordered range of matching message-boards messages that the user has permission to view
14815             * @throws SystemException if a system exception occurred
14816             */
14817            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14818                    long threadId, int status, int start, int end,
14819                    OrderByComparator orderByComparator) throws SystemException {
14820                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14821                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
14822                                    end, orderByComparator);
14823                    }
14824    
14825                    StringBundler query = null;
14826    
14827                    if (orderByComparator != null) {
14828                            query = new StringBundler(6 +
14829                                            (orderByComparator.getOrderByFields().length * 3));
14830                    }
14831                    else {
14832                            query = new StringBundler(6);
14833                    }
14834    
14835                    if (getDB().isSupportsInlineDistinct()) {
14836                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14837                    }
14838                    else {
14839                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14840                    }
14841    
14842                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14843    
14844                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14845    
14846                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14847    
14848                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14849    
14850                    if (!getDB().isSupportsInlineDistinct()) {
14851                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14852                    }
14853    
14854                    if (orderByComparator != null) {
14855                            if (getDB().isSupportsInlineDistinct()) {
14856                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14857                                            orderByComparator);
14858                            }
14859                            else {
14860                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14861                                            orderByComparator);
14862                            }
14863                    }
14864    
14865                    else {
14866                            if (getDB().isSupportsInlineDistinct()) {
14867                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14868                            }
14869                            else {
14870                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14871                            }
14872                    }
14873    
14874                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14875                                    MBMessage.class.getName(),
14876                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14877    
14878                    Session session = null;
14879    
14880                    try {
14881                            session = openSession();
14882    
14883                            SQLQuery q = session.createSQLQuery(sql);
14884    
14885                            if (getDB().isSupportsInlineDistinct()) {
14886                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14887                            }
14888                            else {
14889                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14890                            }
14891    
14892                            QueryPos qPos = QueryPos.getInstance(q);
14893    
14894                            qPos.add(groupId);
14895    
14896                            qPos.add(categoryId);
14897    
14898                            qPos.add(threadId);
14899    
14900                            qPos.add(status);
14901    
14902                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
14903                    }
14904                    catch (Exception e) {
14905                            throw processException(e);
14906                    }
14907                    finally {
14908                            closeSession(session);
14909                    }
14910            }
14911    
14912            /**
14913             * 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;.
14914             *
14915             * @param messageId the primary key of the current message-boards message
14916             * @param groupId the group ID
14917             * @param categoryId the category ID
14918             * @param threadId the thread ID
14919             * @param status the status
14920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14921             * @return the previous, current, and next message-boards message
14922             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14923             * @throws SystemException if a system exception occurred
14924             */
14925            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
14926                    long groupId, long categoryId, long threadId, int status,
14927                    OrderByComparator orderByComparator)
14928                    throws NoSuchMessageException, SystemException {
14929                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14930                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
14931                                    threadId, status, orderByComparator);
14932                    }
14933    
14934                    MBMessage mbMessage = findByPrimaryKey(messageId);
14935    
14936                    Session session = null;
14937    
14938                    try {
14939                            session = openSession();
14940    
14941                            MBMessage[] array = new MBMessageImpl[3];
14942    
14943                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
14944                                            groupId, categoryId, threadId, status, orderByComparator,
14945                                            true);
14946    
14947                            array[1] = mbMessage;
14948    
14949                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
14950                                            groupId, categoryId, threadId, status, orderByComparator,
14951                                            false);
14952    
14953                            return array;
14954                    }
14955                    catch (Exception e) {
14956                            throw processException(e);
14957                    }
14958                    finally {
14959                            closeSession(session);
14960                    }
14961            }
14962    
14963            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
14964                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14965                    int status, OrderByComparator orderByComparator, boolean previous) {
14966                    StringBundler query = null;
14967    
14968                    if (orderByComparator != null) {
14969                            query = new StringBundler(6 +
14970                                            (orderByComparator.getOrderByFields().length * 6));
14971                    }
14972                    else {
14973                            query = new StringBundler(3);
14974                    }
14975    
14976                    if (getDB().isSupportsInlineDistinct()) {
14977                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14978                    }
14979                    else {
14980                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14981                    }
14982    
14983                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14984    
14985                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14986    
14987                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14988    
14989                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14990    
14991                    if (!getDB().isSupportsInlineDistinct()) {
14992                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14993                    }
14994    
14995                    if (orderByComparator != null) {
14996                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14997    
14998                            if (orderByConditionFields.length > 0) {
14999                                    query.append(WHERE_AND);
15000                            }
15001    
15002                            for (int i = 0; i < orderByConditionFields.length; i++) {
15003                                    if (getDB().isSupportsInlineDistinct()) {
15004                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15005                                    }
15006                                    else {
15007                                            query.append(_ORDER_BY_ENTITY_TABLE);
15008                                    }
15009    
15010                                    query.append(orderByConditionFields[i]);
15011    
15012                                    if ((i + 1) < orderByConditionFields.length) {
15013                                            if (orderByComparator.isAscending() ^ previous) {
15014                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15015                                            }
15016                                            else {
15017                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15018                                            }
15019                                    }
15020                                    else {
15021                                            if (orderByComparator.isAscending() ^ previous) {
15022                                                    query.append(WHERE_GREATER_THAN);
15023                                            }
15024                                            else {
15025                                                    query.append(WHERE_LESSER_THAN);
15026                                            }
15027                                    }
15028                            }
15029    
15030                            query.append(ORDER_BY_CLAUSE);
15031    
15032                            String[] orderByFields = orderByComparator.getOrderByFields();
15033    
15034                            for (int i = 0; i < orderByFields.length; i++) {
15035                                    if (getDB().isSupportsInlineDistinct()) {
15036                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15037                                    }
15038                                    else {
15039                                            query.append(_ORDER_BY_ENTITY_TABLE);
15040                                    }
15041    
15042                                    query.append(orderByFields[i]);
15043    
15044                                    if ((i + 1) < orderByFields.length) {
15045                                            if (orderByComparator.isAscending() ^ previous) {
15046                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15047                                            }
15048                                            else {
15049                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15050                                            }
15051                                    }
15052                                    else {
15053                                            if (orderByComparator.isAscending() ^ previous) {
15054                                                    query.append(ORDER_BY_ASC);
15055                                            }
15056                                            else {
15057                                                    query.append(ORDER_BY_DESC);
15058                                            }
15059                                    }
15060                            }
15061                    }
15062    
15063                    else {
15064                            if (getDB().isSupportsInlineDistinct()) {
15065                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15066                            }
15067                            else {
15068                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
15069                            }
15070                    }
15071    
15072                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15073                                    MBMessage.class.getName(),
15074                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15075    
15076                    SQLQuery q = session.createSQLQuery(sql);
15077    
15078                    q.setFirstResult(0);
15079                    q.setMaxResults(2);
15080    
15081                    if (getDB().isSupportsInlineDistinct()) {
15082                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
15083                    }
15084                    else {
15085                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
15086                    }
15087    
15088                    QueryPos qPos = QueryPos.getInstance(q);
15089    
15090                    qPos.add(groupId);
15091    
15092                    qPos.add(categoryId);
15093    
15094                    qPos.add(threadId);
15095    
15096                    qPos.add(status);
15097    
15098                    if (orderByComparator != null) {
15099                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15100    
15101                            for (Object value : values) {
15102                                    qPos.add(value);
15103                            }
15104                    }
15105    
15106                    List<MBMessage> list = q.list();
15107    
15108                    if (list.size() == 2) {
15109                            return list.get(1);
15110                    }
15111                    else {
15112                            return null;
15113                    }
15114            }
15115    
15116            /**
15117             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15118             *
15119             * @param userId the user ID
15120             * @param classNameId the class name ID
15121             * @param classPK the class p k
15122             * @param status the status
15123             * @return the matching message-boards messages
15124             * @throws SystemException if a system exception occurred
15125             */
15126            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15127                    long classPK, int status) throws SystemException {
15128                    return findByU_C_C_S(userId, classNameId, classPK, status,
15129                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15130            }
15131    
15132            /**
15133             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15134             *
15135             * <p>
15136             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15137             * </p>
15138             *
15139             * @param userId the user ID
15140             * @param classNameId the class name ID
15141             * @param classPK the class p k
15142             * @param status the status
15143             * @param start the lower bound of the range of message-boards messages
15144             * @param end the upper bound of the range of message-boards messages (not inclusive)
15145             * @return the range of matching message-boards messages
15146             * @throws SystemException if a system exception occurred
15147             */
15148            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15149                    long classPK, int status, int start, int end) throws SystemException {
15150                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
15151                            null);
15152            }
15153    
15154            /**
15155             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15156             *
15157             * <p>
15158             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15159             * </p>
15160             *
15161             * @param userId the user ID
15162             * @param classNameId the class name ID
15163             * @param classPK the class p k
15164             * @param status the status
15165             * @param start the lower bound of the range of message-boards messages
15166             * @param end the upper bound of the range of message-boards messages (not inclusive)
15167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15168             * @return the ordered range of matching message-boards messages
15169             * @throws SystemException if a system exception occurred
15170             */
15171            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15172                    long classPK, int status, int start, int end,
15173                    OrderByComparator orderByComparator) throws SystemException {
15174                    FinderPath finderPath = null;
15175                    Object[] finderArgs = null;
15176    
15177                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15178                                    (orderByComparator == null)) {
15179                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
15180                            finderArgs = new Object[] { userId, classNameId, classPK, status };
15181                    }
15182                    else {
15183                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
15184                            finderArgs = new Object[] {
15185                                            userId, classNameId, classPK, status,
15186                                            
15187                                            start, end, orderByComparator
15188                                    };
15189                    }
15190    
15191                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15192                                    finderArgs, this);
15193    
15194                    if ((list != null) && !list.isEmpty()) {
15195                            for (MBMessage mbMessage : list) {
15196                                    if ((userId != mbMessage.getUserId()) ||
15197                                                    (classNameId != mbMessage.getClassNameId()) ||
15198                                                    (classPK != mbMessage.getClassPK()) ||
15199                                                    (status != mbMessage.getStatus())) {
15200                                            list = null;
15201    
15202                                            break;
15203                                    }
15204                            }
15205                    }
15206    
15207                    if (list == null) {
15208                            StringBundler query = null;
15209    
15210                            if (orderByComparator != null) {
15211                                    query = new StringBundler(6 +
15212                                                    (orderByComparator.getOrderByFields().length * 3));
15213                            }
15214                            else {
15215                                    query = new StringBundler(6);
15216                            }
15217    
15218                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15219    
15220                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
15221    
15222                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
15223    
15224                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
15225    
15226                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
15227    
15228                            if (orderByComparator != null) {
15229                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15230                                            orderByComparator);
15231                            }
15232    
15233                            else {
15234                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15235                            }
15236    
15237                            String sql = query.toString();
15238    
15239                            Session session = null;
15240    
15241                            try {
15242                                    session = openSession();
15243    
15244                                    Query q = session.createQuery(sql);
15245    
15246                                    QueryPos qPos = QueryPos.getInstance(q);
15247    
15248                                    qPos.add(userId);
15249    
15250                                    qPos.add(classNameId);
15251    
15252                                    qPos.add(classPK);
15253    
15254                                    qPos.add(status);
15255    
15256                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
15257                                                    end);
15258                            }
15259                            catch (Exception e) {
15260                                    throw processException(e);
15261                            }
15262                            finally {
15263                                    if (list == null) {
15264                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
15265                                    }
15266                                    else {
15267                                            cacheResult(list);
15268    
15269                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
15270                                    }
15271    
15272                                    closeSession(session);
15273                            }
15274                    }
15275    
15276                    return list;
15277            }
15278    
15279            /**
15280             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15281             *
15282             * @param userId the user ID
15283             * @param classNameId the class name ID
15284             * @param classPK the class p k
15285             * @param status the status
15286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15287             * @return the first matching message-boards message
15288             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15289             * @throws SystemException if a system exception occurred
15290             */
15291            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
15292                    long classPK, int status, OrderByComparator orderByComparator)
15293                    throws NoSuchMessageException, SystemException {
15294                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
15295                                    classPK, status, orderByComparator);
15296    
15297                    if (mbMessage != null) {
15298                            return mbMessage;
15299                    }
15300    
15301                    StringBundler msg = new StringBundler(10);
15302    
15303                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15304    
15305                    msg.append("userId=");
15306                    msg.append(userId);
15307    
15308                    msg.append(", classNameId=");
15309                    msg.append(classNameId);
15310    
15311                    msg.append(", classPK=");
15312                    msg.append(classPK);
15313    
15314                    msg.append(", status=");
15315                    msg.append(status);
15316    
15317                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15318    
15319                    throw new NoSuchMessageException(msg.toString());
15320            }
15321    
15322            /**
15323             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15324             *
15325             * @param userId the user ID
15326             * @param classNameId the class name ID
15327             * @param classPK the class p k
15328             * @param status the status
15329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15330             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15331             * @throws SystemException if a system exception occurred
15332             */
15333            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
15334                    long classPK, int status, OrderByComparator orderByComparator)
15335                    throws SystemException {
15336                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
15337                                    status, 0, 1, orderByComparator);
15338    
15339                    if (!list.isEmpty()) {
15340                            return list.get(0);
15341                    }
15342    
15343                    return null;
15344            }
15345    
15346            /**
15347             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15348             *
15349             * @param userId the user ID
15350             * @param classNameId the class name ID
15351             * @param classPK the class p k
15352             * @param status the status
15353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15354             * @return the last matching message-boards message
15355             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15356             * @throws SystemException if a system exception occurred
15357             */
15358            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
15359                    long classPK, int status, OrderByComparator orderByComparator)
15360                    throws NoSuchMessageException, SystemException {
15361                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
15362                                    status, orderByComparator);
15363    
15364                    if (mbMessage != null) {
15365                            return mbMessage;
15366                    }
15367    
15368                    StringBundler msg = new StringBundler(10);
15369    
15370                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15371    
15372                    msg.append("userId=");
15373                    msg.append(userId);
15374    
15375                    msg.append(", classNameId=");
15376                    msg.append(classNameId);
15377    
15378                    msg.append(", classPK=");
15379                    msg.append(classPK);
15380    
15381                    msg.append(", status=");
15382                    msg.append(status);
15383    
15384                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15385    
15386                    throw new NoSuchMessageException(msg.toString());
15387            }
15388    
15389            /**
15390             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15391             *
15392             * @param userId the user ID
15393             * @param classNameId the class name ID
15394             * @param classPK the class p k
15395             * @param status the status
15396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15397             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15398             * @throws SystemException if a system exception occurred
15399             */
15400            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
15401                    long classPK, int status, OrderByComparator orderByComparator)
15402                    throws SystemException {
15403                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
15404    
15405                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
15406                                    status, count - 1, count, orderByComparator);
15407    
15408                    if (!list.isEmpty()) {
15409                            return list.get(0);
15410                    }
15411    
15412                    return null;
15413            }
15414    
15415            /**
15416             * 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;.
15417             *
15418             * @param messageId the primary key of the current message-boards message
15419             * @param userId the user ID
15420             * @param classNameId the class name ID
15421             * @param classPK the class p k
15422             * @param status the status
15423             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15424             * @return the previous, current, and next message-boards message
15425             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15426             * @throws SystemException if a system exception occurred
15427             */
15428            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
15429                    long classNameId, long classPK, int status,
15430                    OrderByComparator orderByComparator)
15431                    throws NoSuchMessageException, SystemException {
15432                    MBMessage mbMessage = findByPrimaryKey(messageId);
15433    
15434                    Session session = null;
15435    
15436                    try {
15437                            session = openSession();
15438    
15439                            MBMessage[] array = new MBMessageImpl[3];
15440    
15441                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
15442                                            classNameId, classPK, status, orderByComparator, true);
15443    
15444                            array[1] = mbMessage;
15445    
15446                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
15447                                            classNameId, classPK, status, orderByComparator, false);
15448    
15449                            return array;
15450                    }
15451                    catch (Exception e) {
15452                            throw processException(e);
15453                    }
15454                    finally {
15455                            closeSession(session);
15456                    }
15457            }
15458    
15459            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
15460                    MBMessage mbMessage, long userId, long classNameId, long classPK,
15461                    int status, OrderByComparator orderByComparator, boolean previous) {
15462                    StringBundler query = null;
15463    
15464                    if (orderByComparator != null) {
15465                            query = new StringBundler(6 +
15466                                            (orderByComparator.getOrderByFields().length * 6));
15467                    }
15468                    else {
15469                            query = new StringBundler(3);
15470                    }
15471    
15472                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15473    
15474                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
15475    
15476                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
15477    
15478                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
15479    
15480                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
15481    
15482                    if (orderByComparator != null) {
15483                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15484    
15485                            if (orderByConditionFields.length > 0) {
15486                                    query.append(WHERE_AND);
15487                            }
15488    
15489                            for (int i = 0; i < orderByConditionFields.length; i++) {
15490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15491                                    query.append(orderByConditionFields[i]);
15492    
15493                                    if ((i + 1) < orderByConditionFields.length) {
15494                                            if (orderByComparator.isAscending() ^ previous) {
15495                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15496                                            }
15497                                            else {
15498                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15499                                            }
15500                                    }
15501                                    else {
15502                                            if (orderByComparator.isAscending() ^ previous) {
15503                                                    query.append(WHERE_GREATER_THAN);
15504                                            }
15505                                            else {
15506                                                    query.append(WHERE_LESSER_THAN);
15507                                            }
15508                                    }
15509                            }
15510    
15511                            query.append(ORDER_BY_CLAUSE);
15512    
15513                            String[] orderByFields = orderByComparator.getOrderByFields();
15514    
15515                            for (int i = 0; i < orderByFields.length; i++) {
15516                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15517                                    query.append(orderByFields[i]);
15518    
15519                                    if ((i + 1) < orderByFields.length) {
15520                                            if (orderByComparator.isAscending() ^ previous) {
15521                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15522                                            }
15523                                            else {
15524                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15525                                            }
15526                                    }
15527                                    else {
15528                                            if (orderByComparator.isAscending() ^ previous) {
15529                                                    query.append(ORDER_BY_ASC);
15530                                            }
15531                                            else {
15532                                                    query.append(ORDER_BY_DESC);
15533                                            }
15534                                    }
15535                            }
15536                    }
15537    
15538                    else {
15539                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15540                    }
15541    
15542                    String sql = query.toString();
15543    
15544                    Query q = session.createQuery(sql);
15545    
15546                    q.setFirstResult(0);
15547                    q.setMaxResults(2);
15548    
15549                    QueryPos qPos = QueryPos.getInstance(q);
15550    
15551                    qPos.add(userId);
15552    
15553                    qPos.add(classNameId);
15554    
15555                    qPos.add(classPK);
15556    
15557                    qPos.add(status);
15558    
15559                    if (orderByComparator != null) {
15560                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15561    
15562                            for (Object value : values) {
15563                                    qPos.add(value);
15564                            }
15565                    }
15566    
15567                    List<MBMessage> list = q.list();
15568    
15569                    if (list.size() == 2) {
15570                            return list.get(1);
15571                    }
15572                    else {
15573                            return null;
15574                    }
15575            }
15576    
15577            /**
15578             * Returns all the message-boards messages.
15579             *
15580             * @return the message-boards messages
15581             * @throws SystemException if a system exception occurred
15582             */
15583            public List<MBMessage> findAll() throws SystemException {
15584                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15585            }
15586    
15587            /**
15588             * Returns a range of all the message-boards messages.
15589             *
15590             * <p>
15591             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15592             * </p>
15593             *
15594             * @param start the lower bound of the range of message-boards messages
15595             * @param end the upper bound of the range of message-boards messages (not inclusive)
15596             * @return the range of message-boards messages
15597             * @throws SystemException if a system exception occurred
15598             */
15599            public List<MBMessage> findAll(int start, int end)
15600                    throws SystemException {
15601                    return findAll(start, end, null);
15602            }
15603    
15604            /**
15605             * Returns an ordered range of all the message-boards messages.
15606             *
15607             * <p>
15608             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15609             * </p>
15610             *
15611             * @param start the lower bound of the range of message-boards messages
15612             * @param end the upper bound of the range of message-boards messages (not inclusive)
15613             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15614             * @return the ordered range of message-boards messages
15615             * @throws SystemException if a system exception occurred
15616             */
15617            public List<MBMessage> findAll(int start, int end,
15618                    OrderByComparator orderByComparator) throws SystemException {
15619                    FinderPath finderPath = null;
15620                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
15621    
15622                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15623                                    (orderByComparator == null)) {
15624                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
15625                            finderArgs = FINDER_ARGS_EMPTY;
15626                    }
15627                    else {
15628                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
15629                            finderArgs = new Object[] { start, end, orderByComparator };
15630                    }
15631    
15632                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15633                                    finderArgs, this);
15634    
15635                    if (list == null) {
15636                            StringBundler query = null;
15637                            String sql = null;
15638    
15639                            if (orderByComparator != null) {
15640                                    query = new StringBundler(2 +
15641                                                    (orderByComparator.getOrderByFields().length * 3));
15642    
15643                                    query.append(_SQL_SELECT_MBMESSAGE);
15644    
15645                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15646                                            orderByComparator);
15647    
15648                                    sql = query.toString();
15649                            }
15650                            else {
15651                                    sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
15652                            }
15653    
15654                            Session session = null;
15655    
15656                            try {
15657                                    session = openSession();
15658    
15659                                    Query q = session.createQuery(sql);
15660    
15661                                    if (orderByComparator == null) {
15662                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15663                                                            start, end, false);
15664    
15665                                            Collections.sort(list);
15666                                    }
15667                                    else {
15668                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15669                                                            start, end);
15670                                    }
15671                            }
15672                            catch (Exception e) {
15673                                    throw processException(e);
15674                            }
15675                            finally {
15676                                    if (list == null) {
15677                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
15678                                    }
15679                                    else {
15680                                            cacheResult(list);
15681    
15682                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
15683                                    }
15684    
15685                                    closeSession(session);
15686                            }
15687                    }
15688    
15689                    return list;
15690            }
15691    
15692            /**
15693             * Removes all the message-boards messages where uuid = &#63; from the database.
15694             *
15695             * @param uuid the uuid
15696             * @throws SystemException if a system exception occurred
15697             */
15698            public void removeByUuid(String uuid) throws SystemException {
15699                    for (MBMessage mbMessage : findByUuid(uuid)) {
15700                            remove(mbMessage);
15701                    }
15702            }
15703    
15704            /**
15705             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
15706             *
15707             * @param uuid the uuid
15708             * @param groupId the group ID
15709             * @return the message-boards message that was removed
15710             * @throws SystemException if a system exception occurred
15711             */
15712            public MBMessage removeByUUID_G(String uuid, long groupId)
15713                    throws NoSuchMessageException, SystemException {
15714                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
15715    
15716                    return remove(mbMessage);
15717            }
15718    
15719            /**
15720             * Removes all the message-boards messages where groupId = &#63; from the database.
15721             *
15722             * @param groupId the group ID
15723             * @throws SystemException if a system exception occurred
15724             */
15725            public void removeByGroupId(long groupId) throws SystemException {
15726                    for (MBMessage mbMessage : findByGroupId(groupId)) {
15727                            remove(mbMessage);
15728                    }
15729            }
15730    
15731            /**
15732             * Removes all the message-boards messages where companyId = &#63; from the database.
15733             *
15734             * @param companyId the company ID
15735             * @throws SystemException if a system exception occurred
15736             */
15737            public void removeByCompanyId(long companyId) throws SystemException {
15738                    for (MBMessage mbMessage : findByCompanyId(companyId)) {
15739                            remove(mbMessage);
15740                    }
15741            }
15742    
15743            /**
15744             * Removes all the message-boards messages where threadId = &#63; from the database.
15745             *
15746             * @param threadId the thread ID
15747             * @throws SystemException if a system exception occurred
15748             */
15749            public void removeByThreadId(long threadId) throws SystemException {
15750                    for (MBMessage mbMessage : findByThreadId(threadId)) {
15751                            remove(mbMessage);
15752                    }
15753            }
15754    
15755            /**
15756             * Removes all the message-boards messages where threadId = &#63; from the database.
15757             *
15758             * @param threadId the thread ID
15759             * @throws SystemException if a system exception occurred
15760             */
15761            public void removeByThreadReplies(long threadId) throws SystemException {
15762                    for (MBMessage mbMessage : findByThreadReplies(threadId)) {
15763                            remove(mbMessage);
15764                    }
15765            }
15766    
15767            /**
15768             * Removes all the message-boards messages where userId = &#63; from the database.
15769             *
15770             * @param userId the user ID
15771             * @throws SystemException if a system exception occurred
15772             */
15773            public void removeByUserId(long userId) throws SystemException {
15774                    for (MBMessage mbMessage : findByUserId(userId)) {
15775                            remove(mbMessage);
15776                    }
15777            }
15778    
15779            /**
15780             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
15781             *
15782             * @param groupId the group ID
15783             * @param userId the user ID
15784             * @throws SystemException if a system exception occurred
15785             */
15786            public void removeByG_U(long groupId, long userId)
15787                    throws SystemException {
15788                    for (MBMessage mbMessage : findByG_U(groupId, userId)) {
15789                            remove(mbMessage);
15790                    }
15791            }
15792    
15793            /**
15794             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
15795             *
15796             * @param groupId the group ID
15797             * @param categoryId the category ID
15798             * @throws SystemException if a system exception occurred
15799             */
15800            public void removeByG_C(long groupId, long categoryId)
15801                    throws SystemException {
15802                    for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
15803                            remove(mbMessage);
15804                    }
15805            }
15806    
15807            /**
15808             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
15809             *
15810             * @param groupId the group ID
15811             * @param status the status
15812             * @throws SystemException if a system exception occurred
15813             */
15814            public void removeByG_S(long groupId, int status) throws SystemException {
15815                    for (MBMessage mbMessage : findByG_S(groupId, status)) {
15816                            remove(mbMessage);
15817                    }
15818            }
15819    
15820            /**
15821             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
15822             *
15823             * @param companyId the company ID
15824             * @param status the status
15825             * @throws SystemException if a system exception occurred
15826             */
15827            public void removeByC_S(long companyId, int status)
15828                    throws SystemException {
15829                    for (MBMessage mbMessage : findByC_S(companyId, status)) {
15830                            remove(mbMessage);
15831                    }
15832            }
15833    
15834            /**
15835             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
15836             *
15837             * @param userId the user ID
15838             * @param classNameId the class name ID
15839             * @throws SystemException if a system exception occurred
15840             */
15841            public void removeByU_C(long userId, long classNameId)
15842                    throws SystemException {
15843                    for (MBMessage mbMessage : findByU_C(userId, classNameId)) {
15844                            remove(mbMessage);
15845                    }
15846            }
15847    
15848            /**
15849             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
15850             *
15851             * @param classNameId the class name ID
15852             * @param classPK the class p k
15853             * @throws SystemException if a system exception occurred
15854             */
15855            public void removeByC_C(long classNameId, long classPK)
15856                    throws SystemException {
15857                    for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
15858                            remove(mbMessage);
15859                    }
15860            }
15861    
15862            /**
15863             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
15864             *
15865             * @param threadId the thread ID
15866             * @param parentMessageId the parent message ID
15867             * @throws SystemException if a system exception occurred
15868             */
15869            public void removeByT_P(long threadId, long parentMessageId)
15870                    throws SystemException {
15871                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
15872                            remove(mbMessage);
15873                    }
15874            }
15875    
15876            /**
15877             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
15878             *
15879             * @param threadId the thread ID
15880             * @param answer the answer
15881             * @throws SystemException if a system exception occurred
15882             */
15883            public void removeByT_A(long threadId, boolean answer)
15884                    throws SystemException {
15885                    for (MBMessage mbMessage : findByT_A(threadId, answer)) {
15886                            remove(mbMessage);
15887                    }
15888            }
15889    
15890            /**
15891             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
15892             *
15893             * @param threadId the thread ID
15894             * @param status the status
15895             * @throws SystemException if a system exception occurred
15896             */
15897            public void removeByT_S(long threadId, int status)
15898                    throws SystemException {
15899                    for (MBMessage mbMessage : findByT_S(threadId, status)) {
15900                            remove(mbMessage);
15901                    }
15902            }
15903    
15904            /**
15905             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
15906             *
15907             * @param threadId the thread ID
15908             * @param status the status
15909             * @throws SystemException if a system exception occurred
15910             */
15911            public void removeByTR_S(long threadId, int status)
15912                    throws SystemException {
15913                    for (MBMessage mbMessage : findByTR_S(threadId, status)) {
15914                            remove(mbMessage);
15915                    }
15916            }
15917    
15918            /**
15919             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
15920             *
15921             * @param groupId the group ID
15922             * @param userId the user ID
15923             * @param status the status
15924             * @throws SystemException if a system exception occurred
15925             */
15926            public void removeByG_U_S(long groupId, long userId, int status)
15927                    throws SystemException {
15928                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
15929                            remove(mbMessage);
15930                    }
15931            }
15932    
15933            /**
15934             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
15935             *
15936             * @param groupId the group ID
15937             * @param categoryId the category ID
15938             * @param threadId the thread ID
15939             * @throws SystemException if a system exception occurred
15940             */
15941            public void removeByG_C_T(long groupId, long categoryId, long threadId)
15942                    throws SystemException {
15943                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
15944                            remove(mbMessage);
15945                    }
15946            }
15947    
15948            /**
15949             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
15950             *
15951             * @param groupId the group ID
15952             * @param categoryId the category ID
15953             * @param status the status
15954             * @throws SystemException if a system exception occurred
15955             */
15956            public void removeByG_C_S(long groupId, long categoryId, int status)
15957                    throws SystemException {
15958                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
15959                            remove(mbMessage);
15960                    }
15961            }
15962    
15963            /**
15964             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
15965             *
15966             * @param userId the user ID
15967             * @param classNameId the class name ID
15968             * @param classPK the class p k
15969             * @throws SystemException if a system exception occurred
15970             */
15971            public void removeByU_C_C(long userId, long classNameId, long classPK)
15972                    throws SystemException {
15973                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK)) {
15974                            remove(mbMessage);
15975                    }
15976            }
15977    
15978            /**
15979             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15980             *
15981             * @param userId the user ID
15982             * @param classNameId the class name ID
15983             * @param status the status
15984             * @throws SystemException if a system exception occurred
15985             */
15986            public void removeByU_C_S(long userId, long classNameId, int status)
15987                    throws SystemException {
15988                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status)) {
15989                            remove(mbMessage);
15990                    }
15991            }
15992    
15993            /**
15994             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15995             *
15996             * @param classNameId the class name ID
15997             * @param classPK the class p k
15998             * @param status the status
15999             * @throws SystemException if a system exception occurred
16000             */
16001            public void removeByC_C_S(long classNameId, long classPK, int status)
16002                    throws SystemException {
16003                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
16004                            remove(mbMessage);
16005                    }
16006            }
16007    
16008            /**
16009             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16010             *
16011             * @param groupId the group ID
16012             * @param categoryId the category ID
16013             * @param threadId the thread ID
16014             * @param answer the answer
16015             * @throws SystemException if a system exception occurred
16016             */
16017            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16018                    boolean answer) throws SystemException {
16019                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16020                                    answer)) {
16021                            remove(mbMessage);
16022                    }
16023            }
16024    
16025            /**
16026             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
16027             *
16028             * @param groupId the group ID
16029             * @param categoryId the category ID
16030             * @param threadId the thread ID
16031             * @param status the status
16032             * @throws SystemException if a system exception occurred
16033             */
16034            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
16035                    int status) throws SystemException {
16036                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
16037                                    status)) {
16038                            remove(mbMessage);
16039                    }
16040            }
16041    
16042            /**
16043             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16044             *
16045             * @param userId the user ID
16046             * @param classNameId the class name ID
16047             * @param classPK the class p k
16048             * @param status the status
16049             * @throws SystemException if a system exception occurred
16050             */
16051            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
16052                    int status) throws SystemException {
16053                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
16054                                    status)) {
16055                            remove(mbMessage);
16056                    }
16057            }
16058    
16059            /**
16060             * Removes all the message-boards messages from the database.
16061             *
16062             * @throws SystemException if a system exception occurred
16063             */
16064            public void removeAll() throws SystemException {
16065                    for (MBMessage mbMessage : findAll()) {
16066                            remove(mbMessage);
16067                    }
16068            }
16069    
16070            /**
16071             * Returns the number of message-boards messages where uuid = &#63;.
16072             *
16073             * @param uuid the uuid
16074             * @return the number of matching message-boards messages
16075             * @throws SystemException if a system exception occurred
16076             */
16077            public int countByUuid(String uuid) throws SystemException {
16078                    Object[] finderArgs = new Object[] { uuid };
16079    
16080                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
16081                                    finderArgs, this);
16082    
16083                    if (count == null) {
16084                            StringBundler query = new StringBundler(2);
16085    
16086                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16087    
16088                            if (uuid == null) {
16089                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
16090                            }
16091                            else {
16092                                    if (uuid.equals(StringPool.BLANK)) {
16093                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
16094                                    }
16095                                    else {
16096                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
16097                                    }
16098                            }
16099    
16100                            String sql = query.toString();
16101    
16102                            Session session = null;
16103    
16104                            try {
16105                                    session = openSession();
16106    
16107                                    Query q = session.createQuery(sql);
16108    
16109                                    QueryPos qPos = QueryPos.getInstance(q);
16110    
16111                                    if (uuid != null) {
16112                                            qPos.add(uuid);
16113                                    }
16114    
16115                                    count = (Long)q.uniqueResult();
16116                            }
16117                            catch (Exception e) {
16118                                    throw processException(e);
16119                            }
16120                            finally {
16121                                    if (count == null) {
16122                                            count = Long.valueOf(0);
16123                                    }
16124    
16125                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
16126                                            finderArgs, count);
16127    
16128                                    closeSession(session);
16129                            }
16130                    }
16131    
16132                    return count.intValue();
16133            }
16134    
16135            /**
16136             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
16137             *
16138             * @param uuid the uuid
16139             * @param groupId the group ID
16140             * @return the number of matching message-boards messages
16141             * @throws SystemException if a system exception occurred
16142             */
16143            public int countByUUID_G(String uuid, long groupId)
16144                    throws SystemException {
16145                    Object[] finderArgs = new Object[] { uuid, groupId };
16146    
16147                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
16148                                    finderArgs, this);
16149    
16150                    if (count == null) {
16151                            StringBundler query = new StringBundler(3);
16152    
16153                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16154    
16155                            if (uuid == null) {
16156                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
16157                            }
16158                            else {
16159                                    if (uuid.equals(StringPool.BLANK)) {
16160                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
16161                                    }
16162                                    else {
16163                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
16164                                    }
16165                            }
16166    
16167                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
16168    
16169                            String sql = query.toString();
16170    
16171                            Session session = null;
16172    
16173                            try {
16174                                    session = openSession();
16175    
16176                                    Query q = session.createQuery(sql);
16177    
16178                                    QueryPos qPos = QueryPos.getInstance(q);
16179    
16180                                    if (uuid != null) {
16181                                            qPos.add(uuid);
16182                                    }
16183    
16184                                    qPos.add(groupId);
16185    
16186                                    count = (Long)q.uniqueResult();
16187                            }
16188                            catch (Exception e) {
16189                                    throw processException(e);
16190                            }
16191                            finally {
16192                                    if (count == null) {
16193                                            count = Long.valueOf(0);
16194                                    }
16195    
16196                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
16197                                            finderArgs, count);
16198    
16199                                    closeSession(session);
16200                            }
16201                    }
16202    
16203                    return count.intValue();
16204            }
16205    
16206            /**
16207             * Returns the number of message-boards messages where groupId = &#63;.
16208             *
16209             * @param groupId the group ID
16210             * @return the number of matching message-boards messages
16211             * @throws SystemException if a system exception occurred
16212             */
16213            public int countByGroupId(long groupId) throws SystemException {
16214                    Object[] finderArgs = new Object[] { groupId };
16215    
16216                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
16217                                    finderArgs, this);
16218    
16219                    if (count == null) {
16220                            StringBundler query = new StringBundler(2);
16221    
16222                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16223    
16224                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
16225    
16226                            String sql = query.toString();
16227    
16228                            Session session = null;
16229    
16230                            try {
16231                                    session = openSession();
16232    
16233                                    Query q = session.createQuery(sql);
16234    
16235                                    QueryPos qPos = QueryPos.getInstance(q);
16236    
16237                                    qPos.add(groupId);
16238    
16239                                    count = (Long)q.uniqueResult();
16240                            }
16241                            catch (Exception e) {
16242                                    throw processException(e);
16243                            }
16244                            finally {
16245                                    if (count == null) {
16246                                            count = Long.valueOf(0);
16247                                    }
16248    
16249                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
16250                                            finderArgs, count);
16251    
16252                                    closeSession(session);
16253                            }
16254                    }
16255    
16256                    return count.intValue();
16257            }
16258    
16259            /**
16260             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
16261             *
16262             * @param groupId the group ID
16263             * @return the number of matching message-boards messages that the user has permission to view
16264             * @throws SystemException if a system exception occurred
16265             */
16266            public int filterCountByGroupId(long groupId) throws SystemException {
16267                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16268                            return countByGroupId(groupId);
16269                    }
16270    
16271                    StringBundler query = new StringBundler(2);
16272    
16273                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16274    
16275                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
16276    
16277                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16278                                    MBMessage.class.getName(),
16279                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16280    
16281                    Session session = null;
16282    
16283                    try {
16284                            session = openSession();
16285    
16286                            SQLQuery q = session.createSQLQuery(sql);
16287    
16288                            q.addScalar(COUNT_COLUMN_NAME,
16289                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16290    
16291                            QueryPos qPos = QueryPos.getInstance(q);
16292    
16293                            qPos.add(groupId);
16294    
16295                            Long count = (Long)q.uniqueResult();
16296    
16297                            return count.intValue();
16298                    }
16299                    catch (Exception e) {
16300                            throw processException(e);
16301                    }
16302                    finally {
16303                            closeSession(session);
16304                    }
16305            }
16306    
16307            /**
16308             * Returns the number of message-boards messages where companyId = &#63;.
16309             *
16310             * @param companyId the company ID
16311             * @return the number of matching message-boards messages
16312             * @throws SystemException if a system exception occurred
16313             */
16314            public int countByCompanyId(long companyId) throws SystemException {
16315                    Object[] finderArgs = new Object[] { companyId };
16316    
16317                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
16318                                    finderArgs, this);
16319    
16320                    if (count == null) {
16321                            StringBundler query = new StringBundler(2);
16322    
16323                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16324    
16325                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
16326    
16327                            String sql = query.toString();
16328    
16329                            Session session = null;
16330    
16331                            try {
16332                                    session = openSession();
16333    
16334                                    Query q = session.createQuery(sql);
16335    
16336                                    QueryPos qPos = QueryPos.getInstance(q);
16337    
16338                                    qPos.add(companyId);
16339    
16340                                    count = (Long)q.uniqueResult();
16341                            }
16342                            catch (Exception e) {
16343                                    throw processException(e);
16344                            }
16345                            finally {
16346                                    if (count == null) {
16347                                            count = Long.valueOf(0);
16348                                    }
16349    
16350                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
16351                                            finderArgs, count);
16352    
16353                                    closeSession(session);
16354                            }
16355                    }
16356    
16357                    return count.intValue();
16358            }
16359    
16360            /**
16361             * Returns the number of message-boards messages where threadId = &#63;.
16362             *
16363             * @param threadId the thread ID
16364             * @return the number of matching message-boards messages
16365             * @throws SystemException if a system exception occurred
16366             */
16367            public int countByThreadId(long threadId) throws SystemException {
16368                    Object[] finderArgs = new Object[] { threadId };
16369    
16370                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
16371                                    finderArgs, this);
16372    
16373                    if (count == null) {
16374                            StringBundler query = new StringBundler(2);
16375    
16376                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16377    
16378                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
16379    
16380                            String sql = query.toString();
16381    
16382                            Session session = null;
16383    
16384                            try {
16385                                    session = openSession();
16386    
16387                                    Query q = session.createQuery(sql);
16388    
16389                                    QueryPos qPos = QueryPos.getInstance(q);
16390    
16391                                    qPos.add(threadId);
16392    
16393                                    count = (Long)q.uniqueResult();
16394                            }
16395                            catch (Exception e) {
16396                                    throw processException(e);
16397                            }
16398                            finally {
16399                                    if (count == null) {
16400                                            count = Long.valueOf(0);
16401                                    }
16402    
16403                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
16404                                            finderArgs, count);
16405    
16406                                    closeSession(session);
16407                            }
16408                    }
16409    
16410                    return count.intValue();
16411            }
16412    
16413            /**
16414             * Returns the number of message-boards messages where threadId = &#63;.
16415             *
16416             * @param threadId the thread ID
16417             * @return the number of matching message-boards messages
16418             * @throws SystemException if a system exception occurred
16419             */
16420            public int countByThreadReplies(long threadId) throws SystemException {
16421                    Object[] finderArgs = new Object[] { threadId };
16422    
16423                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
16424                                    finderArgs, this);
16425    
16426                    if (count == null) {
16427                            StringBundler query = new StringBundler(2);
16428    
16429                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16430    
16431                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
16432    
16433                            String sql = query.toString();
16434    
16435                            Session session = null;
16436    
16437                            try {
16438                                    session = openSession();
16439    
16440                                    Query q = session.createQuery(sql);
16441    
16442                                    QueryPos qPos = QueryPos.getInstance(q);
16443    
16444                                    qPos.add(threadId);
16445    
16446                                    count = (Long)q.uniqueResult();
16447                            }
16448                            catch (Exception e) {
16449                                    throw processException(e);
16450                            }
16451                            finally {
16452                                    if (count == null) {
16453                                            count = Long.valueOf(0);
16454                                    }
16455    
16456                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
16457                                            finderArgs, count);
16458    
16459                                    closeSession(session);
16460                            }
16461                    }
16462    
16463                    return count.intValue();
16464            }
16465    
16466            /**
16467             * Returns the number of message-boards messages where userId = &#63;.
16468             *
16469             * @param userId the user ID
16470             * @return the number of matching message-boards messages
16471             * @throws SystemException if a system exception occurred
16472             */
16473            public int countByUserId(long userId) throws SystemException {
16474                    Object[] finderArgs = new Object[] { userId };
16475    
16476                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
16477                                    finderArgs, this);
16478    
16479                    if (count == null) {
16480                            StringBundler query = new StringBundler(2);
16481    
16482                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16483    
16484                            query.append(_FINDER_COLUMN_USERID_USERID_2);
16485    
16486                            String sql = query.toString();
16487    
16488                            Session session = null;
16489    
16490                            try {
16491                                    session = openSession();
16492    
16493                                    Query q = session.createQuery(sql);
16494    
16495                                    QueryPos qPos = QueryPos.getInstance(q);
16496    
16497                                    qPos.add(userId);
16498    
16499                                    count = (Long)q.uniqueResult();
16500                            }
16501                            catch (Exception e) {
16502                                    throw processException(e);
16503                            }
16504                            finally {
16505                                    if (count == null) {
16506                                            count = Long.valueOf(0);
16507                                    }
16508    
16509                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
16510                                            finderArgs, count);
16511    
16512                                    closeSession(session);
16513                            }
16514                    }
16515    
16516                    return count.intValue();
16517            }
16518    
16519            /**
16520             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
16521             *
16522             * @param groupId the group ID
16523             * @param userId the user ID
16524             * @return the number of matching message-boards messages
16525             * @throws SystemException if a system exception occurred
16526             */
16527            public int countByG_U(long groupId, long userId) throws SystemException {
16528                    Object[] finderArgs = new Object[] { groupId, userId };
16529    
16530                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
16531                                    finderArgs, this);
16532    
16533                    if (count == null) {
16534                            StringBundler query = new StringBundler(3);
16535    
16536                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16537    
16538                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
16539    
16540                            query.append(_FINDER_COLUMN_G_U_USERID_2);
16541    
16542                            String sql = query.toString();
16543    
16544                            Session session = null;
16545    
16546                            try {
16547                                    session = openSession();
16548    
16549                                    Query q = session.createQuery(sql);
16550    
16551                                    QueryPos qPos = QueryPos.getInstance(q);
16552    
16553                                    qPos.add(groupId);
16554    
16555                                    qPos.add(userId);
16556    
16557                                    count = (Long)q.uniqueResult();
16558                            }
16559                            catch (Exception e) {
16560                                    throw processException(e);
16561                            }
16562                            finally {
16563                                    if (count == null) {
16564                                            count = Long.valueOf(0);
16565                                    }
16566    
16567                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
16568                                            count);
16569    
16570                                    closeSession(session);
16571                            }
16572                    }
16573    
16574                    return count.intValue();
16575            }
16576    
16577            /**
16578             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
16579             *
16580             * @param groupId the group ID
16581             * @param userId the user ID
16582             * @return the number of matching message-boards messages that the user has permission to view
16583             * @throws SystemException if a system exception occurred
16584             */
16585            public int filterCountByG_U(long groupId, long userId)
16586                    throws SystemException {
16587                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16588                            return countByG_U(groupId, userId);
16589                    }
16590    
16591                    StringBundler query = new StringBundler(3);
16592    
16593                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16594    
16595                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
16596    
16597                    query.append(_FINDER_COLUMN_G_U_USERID_2);
16598    
16599                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16600                                    MBMessage.class.getName(),
16601                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16602    
16603                    Session session = null;
16604    
16605                    try {
16606                            session = openSession();
16607    
16608                            SQLQuery q = session.createSQLQuery(sql);
16609    
16610                            q.addScalar(COUNT_COLUMN_NAME,
16611                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16612    
16613                            QueryPos qPos = QueryPos.getInstance(q);
16614    
16615                            qPos.add(groupId);
16616    
16617                            qPos.add(userId);
16618    
16619                            Long count = (Long)q.uniqueResult();
16620    
16621                            return count.intValue();
16622                    }
16623                    catch (Exception e) {
16624                            throw processException(e);
16625                    }
16626                    finally {
16627                            closeSession(session);
16628                    }
16629            }
16630    
16631            /**
16632             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
16633             *
16634             * @param groupId the group ID
16635             * @param categoryId the category ID
16636             * @return the number of matching message-boards messages
16637             * @throws SystemException if a system exception occurred
16638             */
16639            public int countByG_C(long groupId, long categoryId)
16640                    throws SystemException {
16641                    Object[] finderArgs = new Object[] { groupId, categoryId };
16642    
16643                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
16644                                    finderArgs, this);
16645    
16646                    if (count == null) {
16647                            StringBundler query = new StringBundler(3);
16648    
16649                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16650    
16651                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
16652    
16653                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
16654    
16655                            String sql = query.toString();
16656    
16657                            Session session = null;
16658    
16659                            try {
16660                                    session = openSession();
16661    
16662                                    Query q = session.createQuery(sql);
16663    
16664                                    QueryPos qPos = QueryPos.getInstance(q);
16665    
16666                                    qPos.add(groupId);
16667    
16668                                    qPos.add(categoryId);
16669    
16670                                    count = (Long)q.uniqueResult();
16671                            }
16672                            catch (Exception e) {
16673                                    throw processException(e);
16674                            }
16675                            finally {
16676                                    if (count == null) {
16677                                            count = Long.valueOf(0);
16678                                    }
16679    
16680                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
16681                                            count);
16682    
16683                                    closeSession(session);
16684                            }
16685                    }
16686    
16687                    return count.intValue();
16688            }
16689    
16690            /**
16691             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
16692             *
16693             * @param groupId the group ID
16694             * @param categoryId the category ID
16695             * @return the number of matching message-boards messages that the user has permission to view
16696             * @throws SystemException if a system exception occurred
16697             */
16698            public int filterCountByG_C(long groupId, long categoryId)
16699                    throws SystemException {
16700                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16701                            return countByG_C(groupId, categoryId);
16702                    }
16703    
16704                    StringBundler query = new StringBundler(3);
16705    
16706                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16707    
16708                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
16709    
16710                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
16711    
16712                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16713                                    MBMessage.class.getName(),
16714                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16715    
16716                    Session session = null;
16717    
16718                    try {
16719                            session = openSession();
16720    
16721                            SQLQuery q = session.createSQLQuery(sql);
16722    
16723                            q.addScalar(COUNT_COLUMN_NAME,
16724                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16725    
16726                            QueryPos qPos = QueryPos.getInstance(q);
16727    
16728                            qPos.add(groupId);
16729    
16730                            qPos.add(categoryId);
16731    
16732                            Long count = (Long)q.uniqueResult();
16733    
16734                            return count.intValue();
16735                    }
16736                    catch (Exception e) {
16737                            throw processException(e);
16738                    }
16739                    finally {
16740                            closeSession(session);
16741                    }
16742            }
16743    
16744            /**
16745             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
16746             *
16747             * @param groupId the group ID
16748             * @param status the status
16749             * @return the number of matching message-boards messages
16750             * @throws SystemException if a system exception occurred
16751             */
16752            public int countByG_S(long groupId, int status) throws SystemException {
16753                    Object[] finderArgs = new Object[] { groupId, status };
16754    
16755                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
16756                                    finderArgs, this);
16757    
16758                    if (count == null) {
16759                            StringBundler query = new StringBundler(3);
16760    
16761                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16762    
16763                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
16764    
16765                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
16766    
16767                            String sql = query.toString();
16768    
16769                            Session session = null;
16770    
16771                            try {
16772                                    session = openSession();
16773    
16774                                    Query q = session.createQuery(sql);
16775    
16776                                    QueryPos qPos = QueryPos.getInstance(q);
16777    
16778                                    qPos.add(groupId);
16779    
16780                                    qPos.add(status);
16781    
16782                                    count = (Long)q.uniqueResult();
16783                            }
16784                            catch (Exception e) {
16785                                    throw processException(e);
16786                            }
16787                            finally {
16788                                    if (count == null) {
16789                                            count = Long.valueOf(0);
16790                                    }
16791    
16792                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
16793                                            count);
16794    
16795                                    closeSession(session);
16796                            }
16797                    }
16798    
16799                    return count.intValue();
16800            }
16801    
16802            /**
16803             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
16804             *
16805             * @param groupId the group ID
16806             * @param status the status
16807             * @return the number of matching message-boards messages that the user has permission to view
16808             * @throws SystemException if a system exception occurred
16809             */
16810            public int filterCountByG_S(long groupId, int status)
16811                    throws SystemException {
16812                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16813                            return countByG_S(groupId, status);
16814                    }
16815    
16816                    StringBundler query = new StringBundler(3);
16817    
16818                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16819    
16820                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
16821    
16822                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
16823    
16824                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16825                                    MBMessage.class.getName(),
16826                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16827    
16828                    Session session = null;
16829    
16830                    try {
16831                            session = openSession();
16832    
16833                            SQLQuery q = session.createSQLQuery(sql);
16834    
16835                            q.addScalar(COUNT_COLUMN_NAME,
16836                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16837    
16838                            QueryPos qPos = QueryPos.getInstance(q);
16839    
16840                            qPos.add(groupId);
16841    
16842                            qPos.add(status);
16843    
16844                            Long count = (Long)q.uniqueResult();
16845    
16846                            return count.intValue();
16847                    }
16848                    catch (Exception e) {
16849                            throw processException(e);
16850                    }
16851                    finally {
16852                            closeSession(session);
16853                    }
16854            }
16855    
16856            /**
16857             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
16858             *
16859             * @param companyId the company ID
16860             * @param status the status
16861             * @return the number of matching message-boards messages
16862             * @throws SystemException if a system exception occurred
16863             */
16864            public int countByC_S(long companyId, int status) throws SystemException {
16865                    Object[] finderArgs = new Object[] { companyId, status };
16866    
16867                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
16868                                    finderArgs, this);
16869    
16870                    if (count == null) {
16871                            StringBundler query = new StringBundler(3);
16872    
16873                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16874    
16875                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
16876    
16877                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
16878    
16879                            String sql = query.toString();
16880    
16881                            Session session = null;
16882    
16883                            try {
16884                                    session = openSession();
16885    
16886                                    Query q = session.createQuery(sql);
16887    
16888                                    QueryPos qPos = QueryPos.getInstance(q);
16889    
16890                                    qPos.add(companyId);
16891    
16892                                    qPos.add(status);
16893    
16894                                    count = (Long)q.uniqueResult();
16895                            }
16896                            catch (Exception e) {
16897                                    throw processException(e);
16898                            }
16899                            finally {
16900                                    if (count == null) {
16901                                            count = Long.valueOf(0);
16902                                    }
16903    
16904                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
16905                                            count);
16906    
16907                                    closeSession(session);
16908                            }
16909                    }
16910    
16911                    return count.intValue();
16912            }
16913    
16914            /**
16915             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
16916             *
16917             * @param userId the user ID
16918             * @param classNameId the class name ID
16919             * @return the number of matching message-boards messages
16920             * @throws SystemException if a system exception occurred
16921             */
16922            public int countByU_C(long userId, long classNameId)
16923                    throws SystemException {
16924                    Object[] finderArgs = new Object[] { userId, classNameId };
16925    
16926                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
16927                                    finderArgs, this);
16928    
16929                    if (count == null) {
16930                            StringBundler query = new StringBundler(3);
16931    
16932                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16933    
16934                            query.append(_FINDER_COLUMN_U_C_USERID_2);
16935    
16936                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
16937    
16938                            String sql = query.toString();
16939    
16940                            Session session = null;
16941    
16942                            try {
16943                                    session = openSession();
16944    
16945                                    Query q = session.createQuery(sql);
16946    
16947                                    QueryPos qPos = QueryPos.getInstance(q);
16948    
16949                                    qPos.add(userId);
16950    
16951                                    qPos.add(classNameId);
16952    
16953                                    count = (Long)q.uniqueResult();
16954                            }
16955                            catch (Exception e) {
16956                                    throw processException(e);
16957                            }
16958                            finally {
16959                                    if (count == null) {
16960                                            count = Long.valueOf(0);
16961                                    }
16962    
16963                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
16964                                            count);
16965    
16966                                    closeSession(session);
16967                            }
16968                    }
16969    
16970                    return count.intValue();
16971            }
16972    
16973            /**
16974             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
16975             *
16976             * @param userId the user ID
16977             * @param classNameIds the class name IDs
16978             * @return the number of matching message-boards messages
16979             * @throws SystemException if a system exception occurred
16980             */
16981            public int countByU_C(long userId, long[] classNameIds)
16982                    throws SystemException {
16983                    Object[] finderArgs = new Object[] {
16984                                    userId, StringUtil.merge(classNameIds)
16985                            };
16986    
16987                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
16988                                    finderArgs, this);
16989    
16990                    if (count == null) {
16991                            StringBundler query = new StringBundler();
16992    
16993                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16994    
16995                            boolean conjunctionable = false;
16996    
16997                            if (conjunctionable) {
16998                                    query.append(WHERE_AND);
16999                            }
17000    
17001                            query.append(_FINDER_COLUMN_U_C_USERID_5);
17002    
17003                            conjunctionable = true;
17004    
17005                            if ((classNameIds == null) || (classNameIds.length > 0)) {
17006                                    if (conjunctionable) {
17007                                            query.append(WHERE_AND);
17008                                    }
17009    
17010                                    query.append(StringPool.OPEN_PARENTHESIS);
17011    
17012                                    for (int i = 0; i < classNameIds.length; i++) {
17013                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
17014    
17015                                            if ((i + 1) < classNameIds.length) {
17016                                                    query.append(WHERE_OR);
17017                                            }
17018                                    }
17019    
17020                                    query.append(StringPool.CLOSE_PARENTHESIS);
17021    
17022                                    conjunctionable = true;
17023                            }
17024    
17025                            String sql = query.toString();
17026    
17027                            Session session = null;
17028    
17029                            try {
17030                                    session = openSession();
17031    
17032                                    Query q = session.createQuery(sql);
17033    
17034                                    QueryPos qPos = QueryPos.getInstance(q);
17035    
17036                                    qPos.add(userId);
17037    
17038                                    if (classNameIds != null) {
17039                                            qPos.add(classNameIds);
17040                                    }
17041    
17042                                    count = (Long)q.uniqueResult();
17043                            }
17044                            catch (Exception e) {
17045                                    throw processException(e);
17046                            }
17047                            finally {
17048                                    if (count == null) {
17049                                            count = Long.valueOf(0);
17050                                    }
17051    
17052                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
17053                                            finderArgs, count);
17054    
17055                                    closeSession(session);
17056                            }
17057                    }
17058    
17059                    return count.intValue();
17060            }
17061    
17062            /**
17063             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
17064             *
17065             * @param classNameId the class name ID
17066             * @param classPK the class p k
17067             * @return the number of matching message-boards messages
17068             * @throws SystemException if a system exception occurred
17069             */
17070            public int countByC_C(long classNameId, long classPK)
17071                    throws SystemException {
17072                    Object[] finderArgs = new Object[] { classNameId, classPK };
17073    
17074                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
17075                                    finderArgs, this);
17076    
17077                    if (count == null) {
17078                            StringBundler query = new StringBundler(3);
17079    
17080                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17081    
17082                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
17083    
17084                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
17085    
17086                            String sql = query.toString();
17087    
17088                            Session session = null;
17089    
17090                            try {
17091                                    session = openSession();
17092    
17093                                    Query q = session.createQuery(sql);
17094    
17095                                    QueryPos qPos = QueryPos.getInstance(q);
17096    
17097                                    qPos.add(classNameId);
17098    
17099                                    qPos.add(classPK);
17100    
17101                                    count = (Long)q.uniqueResult();
17102                            }
17103                            catch (Exception e) {
17104                                    throw processException(e);
17105                            }
17106                            finally {
17107                                    if (count == null) {
17108                                            count = Long.valueOf(0);
17109                                    }
17110    
17111                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
17112                                            count);
17113    
17114                                    closeSession(session);
17115                            }
17116                    }
17117    
17118                    return count.intValue();
17119            }
17120    
17121            /**
17122             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
17123             *
17124             * @param threadId the thread ID
17125             * @param parentMessageId the parent message ID
17126             * @return the number of matching message-boards messages
17127             * @throws SystemException if a system exception occurred
17128             */
17129            public int countByT_P(long threadId, long parentMessageId)
17130                    throws SystemException {
17131                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
17132    
17133                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
17134                                    finderArgs, this);
17135    
17136                    if (count == null) {
17137                            StringBundler query = new StringBundler(3);
17138    
17139                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17140    
17141                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
17142    
17143                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
17144    
17145                            String sql = query.toString();
17146    
17147                            Session session = null;
17148    
17149                            try {
17150                                    session = openSession();
17151    
17152                                    Query q = session.createQuery(sql);
17153    
17154                                    QueryPos qPos = QueryPos.getInstance(q);
17155    
17156                                    qPos.add(threadId);
17157    
17158                                    qPos.add(parentMessageId);
17159    
17160                                    count = (Long)q.uniqueResult();
17161                            }
17162                            catch (Exception e) {
17163                                    throw processException(e);
17164                            }
17165                            finally {
17166                                    if (count == null) {
17167                                            count = Long.valueOf(0);
17168                                    }
17169    
17170                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
17171                                            count);
17172    
17173                                    closeSession(session);
17174                            }
17175                    }
17176    
17177                    return count.intValue();
17178            }
17179    
17180            /**
17181             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
17182             *
17183             * @param threadId the thread ID
17184             * @param answer the answer
17185             * @return the number of matching message-boards messages
17186             * @throws SystemException if a system exception occurred
17187             */
17188            public int countByT_A(long threadId, boolean answer)
17189                    throws SystemException {
17190                    Object[] finderArgs = new Object[] { threadId, answer };
17191    
17192                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_A,
17193                                    finderArgs, this);
17194    
17195                    if (count == null) {
17196                            StringBundler query = new StringBundler(3);
17197    
17198                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17199    
17200                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
17201    
17202                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
17203    
17204                            String sql = query.toString();
17205    
17206                            Session session = null;
17207    
17208                            try {
17209                                    session = openSession();
17210    
17211                                    Query q = session.createQuery(sql);
17212    
17213                                    QueryPos qPos = QueryPos.getInstance(q);
17214    
17215                                    qPos.add(threadId);
17216    
17217                                    qPos.add(answer);
17218    
17219                                    count = (Long)q.uniqueResult();
17220                            }
17221                            catch (Exception e) {
17222                                    throw processException(e);
17223                            }
17224                            finally {
17225                                    if (count == null) {
17226                                            count = Long.valueOf(0);
17227                                    }
17228    
17229                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_A, finderArgs,
17230                                            count);
17231    
17232                                    closeSession(session);
17233                            }
17234                    }
17235    
17236                    return count.intValue();
17237            }
17238    
17239            /**
17240             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
17241             *
17242             * @param threadId the thread ID
17243             * @param status the status
17244             * @return the number of matching message-boards messages
17245             * @throws SystemException if a system exception occurred
17246             */
17247            public int countByT_S(long threadId, int status) throws SystemException {
17248                    Object[] finderArgs = new Object[] { threadId, status };
17249    
17250                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
17251                                    finderArgs, this);
17252    
17253                    if (count == null) {
17254                            StringBundler query = new StringBundler(3);
17255    
17256                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17257    
17258                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
17259    
17260                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
17261    
17262                            String sql = query.toString();
17263    
17264                            Session session = null;
17265    
17266                            try {
17267                                    session = openSession();
17268    
17269                                    Query q = session.createQuery(sql);
17270    
17271                                    QueryPos qPos = QueryPos.getInstance(q);
17272    
17273                                    qPos.add(threadId);
17274    
17275                                    qPos.add(status);
17276    
17277                                    count = (Long)q.uniqueResult();
17278                            }
17279                            catch (Exception e) {
17280                                    throw processException(e);
17281                            }
17282                            finally {
17283                                    if (count == null) {
17284                                            count = Long.valueOf(0);
17285                                    }
17286    
17287                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
17288                                            count);
17289    
17290                                    closeSession(session);
17291                            }
17292                    }
17293    
17294                    return count.intValue();
17295            }
17296    
17297            /**
17298             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
17299             *
17300             * @param threadId the thread ID
17301             * @param status the status
17302             * @return the number of matching message-boards messages
17303             * @throws SystemException if a system exception occurred
17304             */
17305            public int countByTR_S(long threadId, int status) throws SystemException {
17306                    Object[] finderArgs = new Object[] { threadId, status };
17307    
17308                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
17309                                    finderArgs, this);
17310    
17311                    if (count == null) {
17312                            StringBundler query = new StringBundler(3);
17313    
17314                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17315    
17316                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
17317    
17318                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
17319    
17320                            String sql = query.toString();
17321    
17322                            Session session = null;
17323    
17324                            try {
17325                                    session = openSession();
17326    
17327                                    Query q = session.createQuery(sql);
17328    
17329                                    QueryPos qPos = QueryPos.getInstance(q);
17330    
17331                                    qPos.add(threadId);
17332    
17333                                    qPos.add(status);
17334    
17335                                    count = (Long)q.uniqueResult();
17336                            }
17337                            catch (Exception e) {
17338                                    throw processException(e);
17339                            }
17340                            finally {
17341                                    if (count == null) {
17342                                            count = Long.valueOf(0);
17343                                    }
17344    
17345                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
17346                                            finderArgs, count);
17347    
17348                                    closeSession(session);
17349                            }
17350                    }
17351    
17352                    return count.intValue();
17353            }
17354    
17355            /**
17356             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
17357             *
17358             * @param groupId the group ID
17359             * @param userId the user ID
17360             * @param status the status
17361             * @return the number of matching message-boards messages
17362             * @throws SystemException if a system exception occurred
17363             */
17364            public int countByG_U_S(long groupId, long userId, int status)
17365                    throws SystemException {
17366                    Object[] finderArgs = new Object[] { groupId, userId, status };
17367    
17368                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
17369                                    finderArgs, this);
17370    
17371                    if (count == null) {
17372                            StringBundler query = new StringBundler(4);
17373    
17374                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17375    
17376                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
17377    
17378                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
17379    
17380                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
17381    
17382                            String sql = query.toString();
17383    
17384                            Session session = null;
17385    
17386                            try {
17387                                    session = openSession();
17388    
17389                                    Query q = session.createQuery(sql);
17390    
17391                                    QueryPos qPos = QueryPos.getInstance(q);
17392    
17393                                    qPos.add(groupId);
17394    
17395                                    qPos.add(userId);
17396    
17397                                    qPos.add(status);
17398    
17399                                    count = (Long)q.uniqueResult();
17400                            }
17401                            catch (Exception e) {
17402                                    throw processException(e);
17403                            }
17404                            finally {
17405                                    if (count == null) {
17406                                            count = Long.valueOf(0);
17407                                    }
17408    
17409                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
17410                                            finderArgs, count);
17411    
17412                                    closeSession(session);
17413                            }
17414                    }
17415    
17416                    return count.intValue();
17417            }
17418    
17419            /**
17420             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
17421             *
17422             * @param groupId the group ID
17423             * @param userId the user ID
17424             * @param status the status
17425             * @return the number of matching message-boards messages that the user has permission to view
17426             * @throws SystemException if a system exception occurred
17427             */
17428            public int filterCountByG_U_S(long groupId, long userId, int status)
17429                    throws SystemException {
17430                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17431                            return countByG_U_S(groupId, userId, status);
17432                    }
17433    
17434                    StringBundler query = new StringBundler(4);
17435    
17436                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17437    
17438                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
17439    
17440                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
17441    
17442                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
17443    
17444                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17445                                    MBMessage.class.getName(),
17446                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17447    
17448                    Session session = null;
17449    
17450                    try {
17451                            session = openSession();
17452    
17453                            SQLQuery q = session.createSQLQuery(sql);
17454    
17455                            q.addScalar(COUNT_COLUMN_NAME,
17456                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17457    
17458                            QueryPos qPos = QueryPos.getInstance(q);
17459    
17460                            qPos.add(groupId);
17461    
17462                            qPos.add(userId);
17463    
17464                            qPos.add(status);
17465    
17466                            Long count = (Long)q.uniqueResult();
17467    
17468                            return count.intValue();
17469                    }
17470                    catch (Exception e) {
17471                            throw processException(e);
17472                    }
17473                    finally {
17474                            closeSession(session);
17475                    }
17476            }
17477    
17478            /**
17479             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
17480             *
17481             * @param groupId the group ID
17482             * @param categoryId the category ID
17483             * @param threadId the thread ID
17484             * @return the number of matching message-boards messages
17485             * @throws SystemException if a system exception occurred
17486             */
17487            public int countByG_C_T(long groupId, long categoryId, long threadId)
17488                    throws SystemException {
17489                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
17490    
17491                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
17492                                    finderArgs, this);
17493    
17494                    if (count == null) {
17495                            StringBundler query = new StringBundler(4);
17496    
17497                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17498    
17499                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
17500    
17501                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
17502    
17503                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
17504    
17505                            String sql = query.toString();
17506    
17507                            Session session = null;
17508    
17509                            try {
17510                                    session = openSession();
17511    
17512                                    Query q = session.createQuery(sql);
17513    
17514                                    QueryPos qPos = QueryPos.getInstance(q);
17515    
17516                                    qPos.add(groupId);
17517    
17518                                    qPos.add(categoryId);
17519    
17520                                    qPos.add(threadId);
17521    
17522                                    count = (Long)q.uniqueResult();
17523                            }
17524                            catch (Exception e) {
17525                                    throw processException(e);
17526                            }
17527                            finally {
17528                                    if (count == null) {
17529                                            count = Long.valueOf(0);
17530                                    }
17531    
17532                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
17533                                            finderArgs, count);
17534    
17535                                    closeSession(session);
17536                            }
17537                    }
17538    
17539                    return count.intValue();
17540            }
17541    
17542            /**
17543             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
17544             *
17545             * @param groupId the group ID
17546             * @param categoryId the category ID
17547             * @param threadId the thread ID
17548             * @return the number of matching message-boards messages that the user has permission to view
17549             * @throws SystemException if a system exception occurred
17550             */
17551            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
17552                    throws SystemException {
17553                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17554                            return countByG_C_T(groupId, categoryId, threadId);
17555                    }
17556    
17557                    StringBundler query = new StringBundler(4);
17558    
17559                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17560    
17561                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
17562    
17563                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
17564    
17565                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
17566    
17567                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17568                                    MBMessage.class.getName(),
17569                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17570    
17571                    Session session = null;
17572    
17573                    try {
17574                            session = openSession();
17575    
17576                            SQLQuery q = session.createSQLQuery(sql);
17577    
17578                            q.addScalar(COUNT_COLUMN_NAME,
17579                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17580    
17581                            QueryPos qPos = QueryPos.getInstance(q);
17582    
17583                            qPos.add(groupId);
17584    
17585                            qPos.add(categoryId);
17586    
17587                            qPos.add(threadId);
17588    
17589                            Long count = (Long)q.uniqueResult();
17590    
17591                            return count.intValue();
17592                    }
17593                    catch (Exception e) {
17594                            throw processException(e);
17595                    }
17596                    finally {
17597                            closeSession(session);
17598                    }
17599            }
17600    
17601            /**
17602             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
17603             *
17604             * @param groupId the group ID
17605             * @param categoryId the category ID
17606             * @param status the status
17607             * @return the number of matching message-boards messages
17608             * @throws SystemException if a system exception occurred
17609             */
17610            public int countByG_C_S(long groupId, long categoryId, int status)
17611                    throws SystemException {
17612                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
17613    
17614                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
17615                                    finderArgs, this);
17616    
17617                    if (count == null) {
17618                            StringBundler query = new StringBundler(4);
17619    
17620                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17621    
17622                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
17623    
17624                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
17625    
17626                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
17627    
17628                            String sql = query.toString();
17629    
17630                            Session session = null;
17631    
17632                            try {
17633                                    session = openSession();
17634    
17635                                    Query q = session.createQuery(sql);
17636    
17637                                    QueryPos qPos = QueryPos.getInstance(q);
17638    
17639                                    qPos.add(groupId);
17640    
17641                                    qPos.add(categoryId);
17642    
17643                                    qPos.add(status);
17644    
17645                                    count = (Long)q.uniqueResult();
17646                            }
17647                            catch (Exception e) {
17648                                    throw processException(e);
17649                            }
17650                            finally {
17651                                    if (count == null) {
17652                                            count = Long.valueOf(0);
17653                                    }
17654    
17655                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
17656                                            finderArgs, count);
17657    
17658                                    closeSession(session);
17659                            }
17660                    }
17661    
17662                    return count.intValue();
17663            }
17664    
17665            /**
17666             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
17667             *
17668             * @param groupId the group ID
17669             * @param categoryId the category ID
17670             * @param status the status
17671             * @return the number of matching message-boards messages that the user has permission to view
17672             * @throws SystemException if a system exception occurred
17673             */
17674            public int filterCountByG_C_S(long groupId, long categoryId, int status)
17675                    throws SystemException {
17676                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17677                            return countByG_C_S(groupId, categoryId, status);
17678                    }
17679    
17680                    StringBundler query = new StringBundler(4);
17681    
17682                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17683    
17684                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
17685    
17686                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
17687    
17688                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
17689    
17690                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17691                                    MBMessage.class.getName(),
17692                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17693    
17694                    Session session = null;
17695    
17696                    try {
17697                            session = openSession();
17698    
17699                            SQLQuery q = session.createSQLQuery(sql);
17700    
17701                            q.addScalar(COUNT_COLUMN_NAME,
17702                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17703    
17704                            QueryPos qPos = QueryPos.getInstance(q);
17705    
17706                            qPos.add(groupId);
17707    
17708                            qPos.add(categoryId);
17709    
17710                            qPos.add(status);
17711    
17712                            Long count = (Long)q.uniqueResult();
17713    
17714                            return count.intValue();
17715                    }
17716                    catch (Exception e) {
17717                            throw processException(e);
17718                    }
17719                    finally {
17720                            closeSession(session);
17721                    }
17722            }
17723    
17724            /**
17725             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
17726             *
17727             * @param userId the user ID
17728             * @param classNameId the class name ID
17729             * @param classPK the class p k
17730             * @return the number of matching message-boards messages
17731             * @throws SystemException if a system exception occurred
17732             */
17733            public int countByU_C_C(long userId, long classNameId, long classPK)
17734                    throws SystemException {
17735                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
17736    
17737                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
17738                                    finderArgs, this);
17739    
17740                    if (count == null) {
17741                            StringBundler query = new StringBundler(4);
17742    
17743                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17744    
17745                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
17746    
17747                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
17748    
17749                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
17750    
17751                            String sql = query.toString();
17752    
17753                            Session session = null;
17754    
17755                            try {
17756                                    session = openSession();
17757    
17758                                    Query q = session.createQuery(sql);
17759    
17760                                    QueryPos qPos = QueryPos.getInstance(q);
17761    
17762                                    qPos.add(userId);
17763    
17764                                    qPos.add(classNameId);
17765    
17766                                    qPos.add(classPK);
17767    
17768                                    count = (Long)q.uniqueResult();
17769                            }
17770                            catch (Exception e) {
17771                                    throw processException(e);
17772                            }
17773                            finally {
17774                                    if (count == null) {
17775                                            count = Long.valueOf(0);
17776                                    }
17777    
17778                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
17779                                            finderArgs, count);
17780    
17781                                    closeSession(session);
17782                            }
17783                    }
17784    
17785                    return count.intValue();
17786            }
17787    
17788            /**
17789             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
17790             *
17791             * @param userId the user ID
17792             * @param classNameId the class name ID
17793             * @param status the status
17794             * @return the number of matching message-boards messages
17795             * @throws SystemException if a system exception occurred
17796             */
17797            public int countByU_C_S(long userId, long classNameId, int status)
17798                    throws SystemException {
17799                    Object[] finderArgs = new Object[] { userId, classNameId, status };
17800    
17801                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_S,
17802                                    finderArgs, this);
17803    
17804                    if (count == null) {
17805                            StringBundler query = new StringBundler(4);
17806    
17807                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17808    
17809                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
17810    
17811                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
17812    
17813                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
17814    
17815                            String sql = query.toString();
17816    
17817                            Session session = null;
17818    
17819                            try {
17820                                    session = openSession();
17821    
17822                                    Query q = session.createQuery(sql);
17823    
17824                                    QueryPos qPos = QueryPos.getInstance(q);
17825    
17826                                    qPos.add(userId);
17827    
17828                                    qPos.add(classNameId);
17829    
17830                                    qPos.add(status);
17831    
17832                                    count = (Long)q.uniqueResult();
17833                            }
17834                            catch (Exception e) {
17835                                    throw processException(e);
17836                            }
17837                            finally {
17838                                    if (count == null) {
17839                                            count = Long.valueOf(0);
17840                                    }
17841    
17842                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_S,
17843                                            finderArgs, count);
17844    
17845                                    closeSession(session);
17846                            }
17847                    }
17848    
17849                    return count.intValue();
17850            }
17851    
17852            /**
17853             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
17854             *
17855             * @param userId the user ID
17856             * @param classNameIds the class name IDs
17857             * @param status the status
17858             * @return the number of matching message-boards messages
17859             * @throws SystemException if a system exception occurred
17860             */
17861            public int countByU_C_S(long userId, long[] classNameIds, int status)
17862                    throws SystemException {
17863                    Object[] finderArgs = new Object[] {
17864                                    userId, StringUtil.merge(classNameIds), status
17865                            };
17866    
17867                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
17868                                    finderArgs, this);
17869    
17870                    if (count == null) {
17871                            StringBundler query = new StringBundler();
17872    
17873                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17874    
17875                            boolean conjunctionable = false;
17876    
17877                            if (conjunctionable) {
17878                                    query.append(WHERE_AND);
17879                            }
17880    
17881                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
17882    
17883                            conjunctionable = true;
17884    
17885                            if ((classNameIds == null) || (classNameIds.length > 0)) {
17886                                    if (conjunctionable) {
17887                                            query.append(WHERE_AND);
17888                                    }
17889    
17890                                    query.append(StringPool.OPEN_PARENTHESIS);
17891    
17892                                    for (int i = 0; i < classNameIds.length; i++) {
17893                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
17894    
17895                                            if ((i + 1) < classNameIds.length) {
17896                                                    query.append(WHERE_OR);
17897                                            }
17898                                    }
17899    
17900                                    query.append(StringPool.CLOSE_PARENTHESIS);
17901    
17902                                    conjunctionable = true;
17903                            }
17904    
17905                            if (conjunctionable) {
17906                                    query.append(WHERE_AND);
17907                            }
17908    
17909                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
17910    
17911                            conjunctionable = true;
17912    
17913                            String sql = query.toString();
17914    
17915                            Session session = null;
17916    
17917                            try {
17918                                    session = openSession();
17919    
17920                                    Query q = session.createQuery(sql);
17921    
17922                                    QueryPos qPos = QueryPos.getInstance(q);
17923    
17924                                    qPos.add(userId);
17925    
17926                                    if (classNameIds != null) {
17927                                            qPos.add(classNameIds);
17928                                    }
17929    
17930                                    qPos.add(status);
17931    
17932                                    count = (Long)q.uniqueResult();
17933                            }
17934                            catch (Exception e) {
17935                                    throw processException(e);
17936                            }
17937                            finally {
17938                                    if (count == null) {
17939                                            count = Long.valueOf(0);
17940                                    }
17941    
17942                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
17943                                            finderArgs, count);
17944    
17945                                    closeSession(session);
17946                            }
17947                    }
17948    
17949                    return count.intValue();
17950            }
17951    
17952            /**
17953             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
17954             *
17955             * @param classNameId the class name ID
17956             * @param classPK the class p k
17957             * @param status the status
17958             * @return the number of matching message-boards messages
17959             * @throws SystemException if a system exception occurred
17960             */
17961            public int countByC_C_S(long classNameId, long classPK, int status)
17962                    throws SystemException {
17963                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
17964    
17965                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
17966                                    finderArgs, this);
17967    
17968                    if (count == null) {
17969                            StringBundler query = new StringBundler(4);
17970    
17971                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17972    
17973                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
17974    
17975                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
17976    
17977                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
17978    
17979                            String sql = query.toString();
17980    
17981                            Session session = null;
17982    
17983                            try {
17984                                    session = openSession();
17985    
17986                                    Query q = session.createQuery(sql);
17987    
17988                                    QueryPos qPos = QueryPos.getInstance(q);
17989    
17990                                    qPos.add(classNameId);
17991    
17992                                    qPos.add(classPK);
17993    
17994                                    qPos.add(status);
17995    
17996                                    count = (Long)q.uniqueResult();
17997                            }
17998                            catch (Exception e) {
17999                                    throw processException(e);
18000                            }
18001                            finally {
18002                                    if (count == null) {
18003                                            count = Long.valueOf(0);
18004                                    }
18005    
18006                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
18007                                            finderArgs, count);
18008    
18009                                    closeSession(session);
18010                            }
18011                    }
18012    
18013                    return count.intValue();
18014            }
18015    
18016            /**
18017             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
18018             *
18019             * @param groupId the group ID
18020             * @param categoryId the category ID
18021             * @param threadId the thread ID
18022             * @param answer the answer
18023             * @return the number of matching message-boards messages
18024             * @throws SystemException if a system exception occurred
18025             */
18026            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
18027                    boolean answer) throws SystemException {
18028                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
18029    
18030                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_A,
18031                                    finderArgs, this);
18032    
18033                    if (count == null) {
18034                            StringBundler query = new StringBundler(5);
18035    
18036                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18037    
18038                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18039    
18040                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18041    
18042                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18043    
18044                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18045    
18046                            String sql = query.toString();
18047    
18048                            Session session = null;
18049    
18050                            try {
18051                                    session = openSession();
18052    
18053                                    Query q = session.createQuery(sql);
18054    
18055                                    QueryPos qPos = QueryPos.getInstance(q);
18056    
18057                                    qPos.add(groupId);
18058    
18059                                    qPos.add(categoryId);
18060    
18061                                    qPos.add(threadId);
18062    
18063                                    qPos.add(answer);
18064    
18065                                    count = (Long)q.uniqueResult();
18066                            }
18067                            catch (Exception e) {
18068                                    throw processException(e);
18069                            }
18070                            finally {
18071                                    if (count == null) {
18072                                            count = Long.valueOf(0);
18073                                    }
18074    
18075                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_A,
18076                                            finderArgs, count);
18077    
18078                                    closeSession(session);
18079                            }
18080                    }
18081    
18082                    return count.intValue();
18083            }
18084    
18085            /**
18086             * 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;.
18087             *
18088             * @param groupId the group ID
18089             * @param categoryId the category ID
18090             * @param threadId the thread ID
18091             * @param answer the answer
18092             * @return the number of matching message-boards messages that the user has permission to view
18093             * @throws SystemException if a system exception occurred
18094             */
18095            public int filterCountByG_C_T_A(long groupId, long categoryId,
18096                    long threadId, boolean answer) throws SystemException {
18097                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18098                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
18099                    }
18100    
18101                    StringBundler query = new StringBundler(5);
18102    
18103                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18104    
18105                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18106    
18107                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18108    
18109                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18110    
18111                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18112    
18113                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18114                                    MBMessage.class.getName(),
18115                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18116    
18117                    Session session = null;
18118    
18119                    try {
18120                            session = openSession();
18121    
18122                            SQLQuery q = session.createSQLQuery(sql);
18123    
18124                            q.addScalar(COUNT_COLUMN_NAME,
18125                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18126    
18127                            QueryPos qPos = QueryPos.getInstance(q);
18128    
18129                            qPos.add(groupId);
18130    
18131                            qPos.add(categoryId);
18132    
18133                            qPos.add(threadId);
18134    
18135                            qPos.add(answer);
18136    
18137                            Long count = (Long)q.uniqueResult();
18138    
18139                            return count.intValue();
18140                    }
18141                    catch (Exception e) {
18142                            throw processException(e);
18143                    }
18144                    finally {
18145                            closeSession(session);
18146                    }
18147            }
18148    
18149            /**
18150             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18151             *
18152             * @param groupId the group ID
18153             * @param categoryId the category ID
18154             * @param threadId the thread ID
18155             * @param status the status
18156             * @return the number of matching message-boards messages
18157             * @throws SystemException if a system exception occurred
18158             */
18159            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18160                    int status) throws SystemException {
18161                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18162    
18163                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
18164                                    finderArgs, this);
18165    
18166                    if (count == null) {
18167                            StringBundler query = new StringBundler(5);
18168    
18169                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18170    
18171                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18172    
18173                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18174    
18175                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18176    
18177                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18178    
18179                            String sql = query.toString();
18180    
18181                            Session session = null;
18182    
18183                            try {
18184                                    session = openSession();
18185    
18186                                    Query q = session.createQuery(sql);
18187    
18188                                    QueryPos qPos = QueryPos.getInstance(q);
18189    
18190                                    qPos.add(groupId);
18191    
18192                                    qPos.add(categoryId);
18193    
18194                                    qPos.add(threadId);
18195    
18196                                    qPos.add(status);
18197    
18198                                    count = (Long)q.uniqueResult();
18199                            }
18200                            catch (Exception e) {
18201                                    throw processException(e);
18202                            }
18203                            finally {
18204                                    if (count == null) {
18205                                            count = Long.valueOf(0);
18206                                    }
18207    
18208                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
18209                                            finderArgs, count);
18210    
18211                                    closeSession(session);
18212                            }
18213                    }
18214    
18215                    return count.intValue();
18216            }
18217    
18218            /**
18219             * 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;.
18220             *
18221             * @param groupId the group ID
18222             * @param categoryId the category ID
18223             * @param threadId the thread ID
18224             * @param status the status
18225             * @return the number of matching message-boards messages that the user has permission to view
18226             * @throws SystemException if a system exception occurred
18227             */
18228            public int filterCountByG_C_T_S(long groupId, long categoryId,
18229                    long threadId, int status) throws SystemException {
18230                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18231                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18232                    }
18233    
18234                    StringBundler query = new StringBundler(5);
18235    
18236                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18237    
18238                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18239    
18240                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18241    
18242                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18243    
18244                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18245    
18246                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18247                                    MBMessage.class.getName(),
18248                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18249    
18250                    Session session = null;
18251    
18252                    try {
18253                            session = openSession();
18254    
18255                            SQLQuery q = session.createSQLQuery(sql);
18256    
18257                            q.addScalar(COUNT_COLUMN_NAME,
18258                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18259    
18260                            QueryPos qPos = QueryPos.getInstance(q);
18261    
18262                            qPos.add(groupId);
18263    
18264                            qPos.add(categoryId);
18265    
18266                            qPos.add(threadId);
18267    
18268                            qPos.add(status);
18269    
18270                            Long count = (Long)q.uniqueResult();
18271    
18272                            return count.intValue();
18273                    }
18274                    catch (Exception e) {
18275                            throw processException(e);
18276                    }
18277                    finally {
18278                            closeSession(session);
18279                    }
18280            }
18281    
18282            /**
18283             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18284             *
18285             * @param userId the user ID
18286             * @param classNameId the class name ID
18287             * @param classPK the class p k
18288             * @param status the status
18289             * @return the number of matching message-boards messages
18290             * @throws SystemException if a system exception occurred
18291             */
18292            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18293                    int status) throws SystemException {
18294                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18295    
18296                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_S,
18297                                    finderArgs, this);
18298    
18299                    if (count == null) {
18300                            StringBundler query = new StringBundler(5);
18301    
18302                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18303    
18304                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18305    
18306                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18307    
18308                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18309    
18310                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18311    
18312                            String sql = query.toString();
18313    
18314                            Session session = null;
18315    
18316                            try {
18317                                    session = openSession();
18318    
18319                                    Query q = session.createQuery(sql);
18320    
18321                                    QueryPos qPos = QueryPos.getInstance(q);
18322    
18323                                    qPos.add(userId);
18324    
18325                                    qPos.add(classNameId);
18326    
18327                                    qPos.add(classPK);
18328    
18329                                    qPos.add(status);
18330    
18331                                    count = (Long)q.uniqueResult();
18332                            }
18333                            catch (Exception e) {
18334                                    throw processException(e);
18335                            }
18336                            finally {
18337                                    if (count == null) {
18338                                            count = Long.valueOf(0);
18339                                    }
18340    
18341                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_S,
18342                                            finderArgs, count);
18343    
18344                                    closeSession(session);
18345                            }
18346                    }
18347    
18348                    return count.intValue();
18349            }
18350    
18351            /**
18352             * Returns the number of message-boards messages.
18353             *
18354             * @return the number of message-boards messages
18355             * @throws SystemException if a system exception occurred
18356             */
18357            public int countAll() throws SystemException {
18358                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
18359                                    FINDER_ARGS_EMPTY, this);
18360    
18361                    if (count == null) {
18362                            Session session = null;
18363    
18364                            try {
18365                                    session = openSession();
18366    
18367                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
18368    
18369                                    count = (Long)q.uniqueResult();
18370                            }
18371                            catch (Exception e) {
18372                                    throw processException(e);
18373                            }
18374                            finally {
18375                                    if (count == null) {
18376                                            count = Long.valueOf(0);
18377                                    }
18378    
18379                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
18380                                            FINDER_ARGS_EMPTY, count);
18381    
18382                                    closeSession(session);
18383                            }
18384                    }
18385    
18386                    return count.intValue();
18387            }
18388    
18389            /**
18390             * Initializes the message-boards message persistence.
18391             */
18392            public void afterPropertiesSet() {
18393                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
18394                                            com.liferay.portal.util.PropsUtil.get(
18395                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
18396    
18397                    if (listenerClassNames.length > 0) {
18398                            try {
18399                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
18400    
18401                                    for (String listenerClassName : listenerClassNames) {
18402                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
18403                                                            listenerClassName));
18404                                    }
18405    
18406                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
18407                            }
18408                            catch (Exception e) {
18409                                    _log.error(e);
18410                            }
18411                    }
18412            }
18413    
18414            public void destroy() {
18415                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
18416                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
18417                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18418            }
18419    
18420            @BeanReference(type = MBBanPersistence.class)
18421            protected MBBanPersistence mbBanPersistence;
18422            @BeanReference(type = MBCategoryPersistence.class)
18423            protected MBCategoryPersistence mbCategoryPersistence;
18424            @BeanReference(type = MBDiscussionPersistence.class)
18425            protected MBDiscussionPersistence mbDiscussionPersistence;
18426            @BeanReference(type = MBMailingListPersistence.class)
18427            protected MBMailingListPersistence mbMailingListPersistence;
18428            @BeanReference(type = MBMessagePersistence.class)
18429            protected MBMessagePersistence mbMessagePersistence;
18430            @BeanReference(type = MBStatsUserPersistence.class)
18431            protected MBStatsUserPersistence mbStatsUserPersistence;
18432            @BeanReference(type = MBThreadPersistence.class)
18433            protected MBThreadPersistence mbThreadPersistence;
18434            @BeanReference(type = MBThreadFlagPersistence.class)
18435            protected MBThreadFlagPersistence mbThreadFlagPersistence;
18436            @BeanReference(type = CompanyPersistence.class)
18437            protected CompanyPersistence companyPersistence;
18438            @BeanReference(type = GroupPersistence.class)
18439            protected GroupPersistence groupPersistence;
18440            @BeanReference(type = LockPersistence.class)
18441            protected LockPersistence lockPersistence;
18442            @BeanReference(type = PortletPreferencesPersistence.class)
18443            protected PortletPreferencesPersistence portletPreferencesPersistence;
18444            @BeanReference(type = ResourcePersistence.class)
18445            protected ResourcePersistence resourcePersistence;
18446            @BeanReference(type = SubscriptionPersistence.class)
18447            protected SubscriptionPersistence subscriptionPersistence;
18448            @BeanReference(type = UserPersistence.class)
18449            protected UserPersistence userPersistence;
18450            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
18451            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
18452            @BeanReference(type = AssetEntryPersistence.class)
18453            protected AssetEntryPersistence assetEntryPersistence;
18454            @BeanReference(type = AssetLinkPersistence.class)
18455            protected AssetLinkPersistence assetLinkPersistence;
18456            @BeanReference(type = AssetTagPersistence.class)
18457            protected AssetTagPersistence assetTagPersistence;
18458            @BeanReference(type = BlogsEntryPersistence.class)
18459            protected BlogsEntryPersistence blogsEntryPersistence;
18460            @BeanReference(type = ExpandoValuePersistence.class)
18461            protected ExpandoValuePersistence expandoValuePersistence;
18462            @BeanReference(type = RatingsStatsPersistence.class)
18463            protected RatingsStatsPersistence ratingsStatsPersistence;
18464            @BeanReference(type = SocialActivityPersistence.class)
18465            protected SocialActivityPersistence socialActivityPersistence;
18466            @BeanReference(type = WikiPagePersistence.class)
18467            protected WikiPagePersistence wikiPagePersistence;
18468            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
18469            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
18470            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
18471            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
18472            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
18473            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
18474            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
18475            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
18476            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
18477            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
18478            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
18479            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
18480            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
18481            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
18482            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
18483            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
18484            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
18485            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
18486            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
18487            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
18488            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18489            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
18490            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
18491            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
18492            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
18493            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
18494                    _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
18495            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
18496            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
18497                    _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
18498            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18499            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
18500            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
18501            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
18502            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
18503            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
18504            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18505            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
18506            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18507            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
18508            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18509            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
18510            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
18511            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
18512            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18513            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
18514            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18515            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18516            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
18517            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
18518            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18519            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
18520            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18521            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
18522                    _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
18523            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18524            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
18525                    _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
18526            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
18527            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
18528                    _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
18529            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18530            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18531            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
18532            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
18533            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18534            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
18535            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
18536            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18537            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18538            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18539            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18540            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18541            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18542            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18543            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18544    
18545            private static String _removeConjunction(String sql) {
18546                    int pos = sql.indexOf(" AND ");
18547    
18548                    if (pos != -1) {
18549                            sql = sql.substring(0, pos);
18550                    }
18551    
18552                    return sql;
18553            }
18554    
18555            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
18556            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
18557            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
18558                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
18559            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
18560                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
18561            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
18562            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
18563            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
18564            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
18565            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
18566            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
18567            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
18568            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
18569            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
18570            private static MBMessage _nullMBMessage = new MBMessageImpl() {
18571                            @Override
18572                            public Object clone() {
18573                                    return this;
18574                            }
18575    
18576                            @Override
18577                            public CacheModel<MBMessage> toCacheModel() {
18578                                    return _nullMBMessageCacheModel;
18579                            }
18580                    };
18581    
18582            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
18583                            public MBMessage toEntityModel() {
18584                                    return _nullMBMessage;
18585                            }
18586                    };
18587    }