001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.sanitizer.Sanitizer;
032    import com.liferay.portal.kernel.sanitizer.SanitizerException;
033    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
034    import com.liferay.portal.kernel.util.ArrayUtil;
035    import com.liferay.portal.kernel.util.ContentTypes;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.StringBundler;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.BatchSessionUtil;
049    import com.liferay.portal.service.persistence.CompanyPersistence;
050    import com.liferay.portal.service.persistence.GroupPersistence;
051    import com.liferay.portal.service.persistence.LockPersistence;
052    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
053    import com.liferay.portal.service.persistence.ResourcePersistence;
054    import com.liferay.portal.service.persistence.SubscriptionPersistence;
055    import com.liferay.portal.service.persistence.UserPersistence;
056    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
057    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
058    
059    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
060    import com.liferay.portlet.asset.service.persistence.AssetLinkPersistence;
061    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
062    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
063    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
064    import com.liferay.portlet.messageboards.NoSuchMessageException;
065    import com.liferay.portlet.messageboards.model.MBMessage;
066    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
067    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
068    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
069    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
070    import com.liferay.portlet.wiki.service.persistence.WikiPagePersistence;
071    
072    import java.io.Serializable;
073    
074    import java.util.ArrayList;
075    import java.util.Collections;
076    import java.util.List;
077    
078    /**
079     * The persistence implementation for the message-boards message service.
080     *
081     * <p>
082     * Caching information and settings can be found in <code>portal.properties</code>
083     * </p>
084     *
085     * @author Brian Wing Shun Chan
086     * @see MBMessagePersistence
087     * @see MBMessageUtil
088     * @generated
089     */
090    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
091            implements MBMessagePersistence {
092            /*
093             * NOTE FOR DEVELOPERS:
094             *
095             * Never modify or reference this class directly. Always use {@link MBMessageUtil} to access the message-boards message persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
096             */
097            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
098            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
099                    ".List1";
100            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
101                    ".List2";
102            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
103                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
105                            new String[] {
106                                    String.class.getName(),
107                                    
108                            "java.lang.Integer", "java.lang.Integer",
109                                    "com.liferay.portal.kernel.util.OrderByComparator"
110                            });
111            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
112                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
114                            new String[] { String.class.getName() },
115                            MBMessageModelImpl.UUID_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
119                            new String[] { String.class.getName() });
120            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
121                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
122                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
123                            new String[] { String.class.getName(), Long.class.getName() },
124                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
125                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
126            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
127                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
129                            new String[] { String.class.getName(), Long.class.getName() });
130            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
131                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
132                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
133                            new String[] {
134                                    Long.class.getName(),
135                                    
136                            "java.lang.Integer", "java.lang.Integer",
137                                    "com.liferay.portal.kernel.util.OrderByComparator"
138                            });
139            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
140                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
141                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
143                            new String[] { Long.class.getName() },
144                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
145            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
146                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
147                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
148                            new String[] { Long.class.getName() });
149            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
150                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
151                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
153                            new String[] {
154                                    Long.class.getName(),
155                                    
156                            "java.lang.Integer", "java.lang.Integer",
157                                    "com.liferay.portal.kernel.util.OrderByComparator"
158                            });
159            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
160                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
161                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
162                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
163                            new String[] { Long.class.getName() },
164                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK);
165            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
168                            new String[] { Long.class.getName() });
169            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
170                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
171                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
172                            new String[] {
173                                    Long.class.getName(),
174                                    
175                            "java.lang.Integer", "java.lang.Integer",
176                                    "com.liferay.portal.kernel.util.OrderByComparator"
177                            });
178            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
179                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
180                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
182                            new String[] { Long.class.getName() },
183                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
184            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
186                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
187                            new String[] { Long.class.getName() });
188            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
189                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
190                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
191                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
192                            new String[] {
193                                    Long.class.getName(),
194                                    
195                            "java.lang.Integer", "java.lang.Integer",
196                                    "com.liferay.portal.kernel.util.OrderByComparator"
197                            });
198            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
199                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
200                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
202                            new String[] { Long.class.getName() },
203                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
204            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
205                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
206                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
207                            new String[] { Long.class.getName() });
208            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
209                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
210                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
211                            new String[] {
212                                    Long.class.getName(),
213                                    
214                            "java.lang.Integer", "java.lang.Integer",
215                                    "com.liferay.portal.kernel.util.OrderByComparator"
216                            });
217            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
218                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
219                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
220                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
221                            new String[] { Long.class.getName() },
222                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
223            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
224                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
225                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
226                            new String[] { Long.class.getName() });
227            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
228                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
229                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
230                            new String[] {
231                                    Long.class.getName(), Long.class.getName(),
232                                    
233                            "java.lang.Integer", "java.lang.Integer",
234                                    "com.liferay.portal.kernel.util.OrderByComparator"
235                            });
236            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
237                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
238                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
239                            new String[] { Long.class.getName(), Long.class.getName() },
240                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
241                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
242            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
243                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
244                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
245                            new String[] { Long.class.getName(), Long.class.getName() });
246            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
247                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
248                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
249                            new String[] {
250                                    Long.class.getName(), Long.class.getName(),
251                                    
252                            "java.lang.Integer", "java.lang.Integer",
253                                    "com.liferay.portal.kernel.util.OrderByComparator"
254                            });
255            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
256                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
257                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
258                            new String[] { Long.class.getName(), Long.class.getName() },
259                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
260                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK);
261            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
262                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
263                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
264                            new String[] { Long.class.getName(), Long.class.getName() });
265            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
266                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
267                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
268                            new String[] {
269                                    Long.class.getName(), Integer.class.getName(),
270                                    
271                            "java.lang.Integer", "java.lang.Integer",
272                                    "com.liferay.portal.kernel.util.OrderByComparator"
273                            });
274            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
275                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
276                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
277                            new String[] { Long.class.getName(), Integer.class.getName() },
278                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
279                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
280            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
281                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
282                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
283                            new String[] { Long.class.getName(), Integer.class.getName() });
284            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
285                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
286                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
287                            new String[] {
288                                    Long.class.getName(), Integer.class.getName(),
289                                    
290                            "java.lang.Integer", "java.lang.Integer",
291                                    "com.liferay.portal.kernel.util.OrderByComparator"
292                            });
293            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
294                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
295                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
296                            new String[] { Long.class.getName(), Integer.class.getName() },
297                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
298                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
299            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
300                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
301                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
302                            new String[] { Long.class.getName(), Integer.class.getName() });
303            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
304                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
305                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
306                            new String[] {
307                                    Long.class.getName(), Long.class.getName(),
308                                    
309                            "java.lang.Integer", "java.lang.Integer",
310                                    "com.liferay.portal.kernel.util.OrderByComparator"
311                            });
312            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
313                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
314                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
315                            new String[] { Long.class.getName(), Long.class.getName() },
316                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
317                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK);
318            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
319                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
320                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
321                            new String[] { Long.class.getName(), Long.class.getName() });
322            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
323                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
324                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
325                            new String[] { Long.class.getName(), Long.class.getName() });
326            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
327                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
328                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
329                            new String[] {
330                                    Long.class.getName(), Long.class.getName(),
331                                    
332                            "java.lang.Integer", "java.lang.Integer",
333                                    "com.liferay.portal.kernel.util.OrderByComparator"
334                            });
335            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
336                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
337                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
338                            new String[] { Long.class.getName(), Long.class.getName() },
339                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
340                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
341            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
342                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
343                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
344                            new String[] { Long.class.getName(), Long.class.getName() });
345            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
346                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
347                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
348                            new String[] {
349                                    Long.class.getName(), Long.class.getName(),
350                                    
351                            "java.lang.Integer", "java.lang.Integer",
352                                    "com.liferay.portal.kernel.util.OrderByComparator"
353                            });
354            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
355                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
356                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
357                            new String[] { Long.class.getName(), Long.class.getName() },
358                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
359                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK);
360            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
361                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
362                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
363                            new String[] { Long.class.getName(), Long.class.getName() });
364            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
365                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
366                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
367                            new String[] {
368                                    Long.class.getName(), Boolean.class.getName(),
369                                    
370                            "java.lang.Integer", "java.lang.Integer",
371                                    "com.liferay.portal.kernel.util.OrderByComparator"
372                            });
373            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
374                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
375                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
376                            new String[] { Long.class.getName(), Boolean.class.getName() },
377                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
378                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
379            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
380                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
381                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
382                            new String[] { Long.class.getName(), Boolean.class.getName() });
383            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
384                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
385                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
386                            new String[] {
387                                    Long.class.getName(), Integer.class.getName(),
388                                    
389                            "java.lang.Integer", "java.lang.Integer",
390                                    "com.liferay.portal.kernel.util.OrderByComparator"
391                            });
392            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
393                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
394                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
395                            new String[] { Long.class.getName(), Integer.class.getName() },
396                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
397                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
398            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
399                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
400                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
401                            new String[] { Long.class.getName(), Integer.class.getName() });
402            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
403                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
404                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
405                            new String[] {
406                                    Long.class.getName(), Integer.class.getName(),
407                                    
408                            "java.lang.Integer", "java.lang.Integer",
409                                    "com.liferay.portal.kernel.util.OrderByComparator"
410                            });
411            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
412                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
413                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
414                            new String[] { Long.class.getName(), Integer.class.getName() },
415                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
416                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
417            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
418                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
419                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
420                            new String[] { Long.class.getName(), Integer.class.getName() });
421            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
422                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
423                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
424                            new String[] {
425                                    Long.class.getName(), Long.class.getName(),
426                                    Integer.class.getName(),
427                                    
428                            "java.lang.Integer", "java.lang.Integer",
429                                    "com.liferay.portal.kernel.util.OrderByComparator"
430                            });
431            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
432                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
433                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
434                            new String[] {
435                                    Long.class.getName(), Long.class.getName(),
436                                    Integer.class.getName()
437                            },
438                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
439                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
440                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
441            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
442                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
443                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
444                            new String[] {
445                                    Long.class.getName(), Long.class.getName(),
446                                    Integer.class.getName()
447                            });
448            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
449                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
450                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
451                            new String[] {
452                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
453                                    
454                            "java.lang.Integer", "java.lang.Integer",
455                                    "com.liferay.portal.kernel.util.OrderByComparator"
456                            });
457            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
458                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
459                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
460                            new String[] {
461                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
462                            },
463                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
464                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
465                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
466            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
467                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
468                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
469                            new String[] {
470                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
471                            });
472            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
473                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
474                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
475                            new String[] {
476                                    Long.class.getName(), Long.class.getName(),
477                                    Integer.class.getName(),
478                                    
479                            "java.lang.Integer", "java.lang.Integer",
480                                    "com.liferay.portal.kernel.util.OrderByComparator"
481                            });
482            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
483                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
484                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
485                            new String[] {
486                                    Long.class.getName(), Long.class.getName(),
487                                    Integer.class.getName()
488                            },
489                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
490                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
491                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
492            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
493                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
494                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
495                            new String[] {
496                                    Long.class.getName(), Long.class.getName(),
497                                    Integer.class.getName()
498                            });
499            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
500                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
501                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
502                            new String[] {
503                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
504                                    
505                            "java.lang.Integer", "java.lang.Integer",
506                                    "com.liferay.portal.kernel.util.OrderByComparator"
507                            });
508            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
509                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
510                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
511                            new String[] {
512                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
513                            },
514                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
515                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
516                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
517            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
518                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
519                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
520                            new String[] {
521                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
522                            });
523            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
524                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
525                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
526                            new String[] {
527                                    Long.class.getName(), Long.class.getName(),
528                                    Integer.class.getName(),
529                                    
530                            "java.lang.Integer", "java.lang.Integer",
531                                    "com.liferay.portal.kernel.util.OrderByComparator"
532                            });
533            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
534                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
535                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
536                            new String[] {
537                                    Long.class.getName(), Long.class.getName(),
538                                    Integer.class.getName()
539                            },
540                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
541                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
542                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
543            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
544                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
545                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
546                            new String[] {
547                                    Long.class.getName(), Long.class.getName(),
548                                    Integer.class.getName()
549                            });
550            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
551                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
552                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
553                            new String[] {
554                                    Long.class.getName(), Long.class.getName(),
555                                    Integer.class.getName()
556                            });
557            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
558                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
559                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
560                            new String[] {
561                                    Long.class.getName(), Long.class.getName(),
562                                    Integer.class.getName(),
563                                    
564                            "java.lang.Integer", "java.lang.Integer",
565                                    "com.liferay.portal.kernel.util.OrderByComparator"
566                            });
567            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
568                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
569                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
570                            new String[] {
571                                    Long.class.getName(), Long.class.getName(),
572                                    Integer.class.getName()
573                            },
574                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
575                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
576                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
577            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
578                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
579                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
580                            new String[] {
581                                    Long.class.getName(), Long.class.getName(),
582                                    Integer.class.getName()
583                            });
584            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
585                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
586                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
587                            new String[] {
588                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
589                                    Boolean.class.getName(),
590                                    
591                            "java.lang.Integer", "java.lang.Integer",
592                                    "com.liferay.portal.kernel.util.OrderByComparator"
593                            });
594            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
595                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
596                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
597                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
598                            new String[] {
599                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
600                                    Boolean.class.getName()
601                            },
602                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
603                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
604                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
605                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
606            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
607                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
608                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
609                            new String[] {
610                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
611                                    Boolean.class.getName()
612                            });
613            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
614                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
615                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
616                            new String[] {
617                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
618                                    Integer.class.getName(),
619                                    
620                            "java.lang.Integer", "java.lang.Integer",
621                                    "com.liferay.portal.kernel.util.OrderByComparator"
622                            });
623            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
624                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
625                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
627                            new String[] {
628                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
629                                    Integer.class.getName()
630                            },
631                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
632                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
633                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
634                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
635            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
636                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
637                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
638                            new String[] {
639                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
640                                    Integer.class.getName()
641                            });
642            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
643                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
644                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
645                            new String[] {
646                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
647                                    Integer.class.getName(),
648                                    
649                            "java.lang.Integer", "java.lang.Integer",
650                                    "com.liferay.portal.kernel.util.OrderByComparator"
651                            });
652            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
653                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
656                            new String[] {
657                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
658                                    Integer.class.getName()
659                            },
660                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
661                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
662                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
663                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
664            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
665                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
666                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
667                            new String[] {
668                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
669                                    Integer.class.getName()
670                            });
671            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
672                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
673                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
674            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
675                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
676                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
677            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
678                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
679                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
680    
681            /**
682             * Caches the message-boards message in the entity cache if it is enabled.
683             *
684             * @param mbMessage the message-boards message
685             */
686            public void cacheResult(MBMessage mbMessage) {
687                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
688                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
689    
690                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
691                            new Object[] {
692                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
693                            }, mbMessage);
694    
695                    mbMessage.resetOriginalValues();
696            }
697    
698            /**
699             * Caches the message-boards messages in the entity cache if it is enabled.
700             *
701             * @param mbMessages the message-boards messages
702             */
703            public void cacheResult(List<MBMessage> mbMessages) {
704                    for (MBMessage mbMessage : mbMessages) {
705                            if (EntityCacheUtil.getResult(
706                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
707                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
708                                    cacheResult(mbMessage);
709                            }
710                            else {
711                                    mbMessage.resetOriginalValues();
712                            }
713                    }
714            }
715    
716            /**
717             * Clears the cache for all message-boards messages.
718             *
719             * <p>
720             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
721             * </p>
722             */
723            @Override
724            public void clearCache() {
725                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
726                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
727                    }
728    
729                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
730    
731                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
732                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
733                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
734            }
735    
736            /**
737             * Clears the cache for the message-boards message.
738             *
739             * <p>
740             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
741             * </p>
742             */
743            @Override
744            public void clearCache(MBMessage mbMessage) {
745                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
746                            MBMessageImpl.class, mbMessage.getPrimaryKey());
747    
748                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
749                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
750    
751                    clearUniqueFindersCache(mbMessage);
752            }
753    
754            @Override
755            public void clearCache(List<MBMessage> mbMessages) {
756                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
757                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
758    
759                    for (MBMessage mbMessage : mbMessages) {
760                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
761                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
762    
763                            clearUniqueFindersCache(mbMessage);
764                    }
765            }
766    
767            protected void 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                    else {
934                            if ((mbMessageModelImpl.getColumnBitmask() &
935                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
936                                    Object[] args = new Object[] {
937                                                    mbMessageModelImpl.getOriginalUuid()
938                                            };
939    
940                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
941                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
942                                            args);
943    
944                                    args = new Object[] { mbMessageModelImpl.getUuid() };
945    
946                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
947                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
948                                            args);
949                            }
950    
951                            if ((mbMessageModelImpl.getColumnBitmask() &
952                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
953                                    Object[] args = new Object[] {
954                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
955                                            };
956    
957                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
958                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
959                                            args);
960    
961                                    args = new Object[] {
962                                                    Long.valueOf(mbMessageModelImpl.getGroupId())
963                                            };
964    
965                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
966                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
967                                            args);
968                            }
969    
970                            if ((mbMessageModelImpl.getColumnBitmask() &
971                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
972                                    Object[] args = new Object[] {
973                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
974                                            };
975    
976                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
977                                            args);
978                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
979                                            args);
980    
981                                    args = new Object[] {
982                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
983                                            };
984    
985                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
986                                            args);
987                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
988                                            args);
989                            }
990    
991                            if ((mbMessageModelImpl.getColumnBitmask() &
992                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
993                                    Object[] args = new Object[] {
994                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
995                                            };
996    
997                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
998                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
999                                            args);
1000    
1001                                    args = new Object[] {
1002                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1003                                            };
1004    
1005                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1006                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1007                                            args);
1008                            }
1009    
1010                            if ((mbMessageModelImpl.getColumnBitmask() &
1011                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
1012                                    Object[] args = new Object[] {
1013                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1014                                            };
1015    
1016                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1017                                            args);
1018                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1019                                            args);
1020    
1021                                    args = new Object[] {
1022                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1023                                            };
1024    
1025                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1026                                            args);
1027                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1028                                            args);
1029                            }
1030    
1031                            if ((mbMessageModelImpl.getColumnBitmask() &
1032                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1033                                    Object[] args = new Object[] {
1034                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1035                                            };
1036    
1037                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1038                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1039                                            args);
1040    
1041                                    args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
1042    
1043                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1044                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1045                                            args);
1046                            }
1047    
1048                            if ((mbMessageModelImpl.getColumnBitmask() &
1049                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
1050                                    Object[] args = new Object[] {
1051                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1052                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1053                                            };
1054    
1055                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1056                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1057                                            args);
1058    
1059                                    args = new Object[] {
1060                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1061                                                    Long.valueOf(mbMessageModelImpl.getUserId())
1062                                            };
1063    
1064                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1065                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1066                                            args);
1067                            }
1068    
1069                            if ((mbMessageModelImpl.getColumnBitmask() &
1070                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1071                                    Object[] args = new Object[] {
1072                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1073                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
1074                                            };
1075    
1076                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1077                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1078                                            args);
1079    
1080                                    args = new Object[] {
1081                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1082                                                    Long.valueOf(mbMessageModelImpl.getCategoryId())
1083                                            };
1084    
1085                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1086                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1087                                            args);
1088                            }
1089    
1090                            if ((mbMessageModelImpl.getColumnBitmask() &
1091                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
1092                                    Object[] args = new Object[] {
1093                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1094                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1095                                            };
1096    
1097                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1098                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1099                                            args);
1100    
1101                                    args = new Object[] {
1102                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1103                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1104                                            };
1105    
1106                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1107                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1108                                            args);
1109                            }
1110    
1111                            if ((mbMessageModelImpl.getColumnBitmask() &
1112                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
1113                                    Object[] args = new Object[] {
1114                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
1115                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1116                                            };
1117    
1118                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1119                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1120                                            args);
1121    
1122                                    args = new Object[] {
1123                                                    Long.valueOf(mbMessageModelImpl.getCompanyId()),
1124                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1125                                            };
1126    
1127                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1128                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1129                                            args);
1130                            }
1131    
1132                            if ((mbMessageModelImpl.getColumnBitmask() &
1133                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
1134                                    Object[] args = new Object[] {
1135                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1136                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
1137                                            };
1138    
1139                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1140                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1141                                            args);
1142    
1143                                    args = new Object[] {
1144                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1145                                                    Long.valueOf(mbMessageModelImpl.getClassNameId())
1146                                            };
1147    
1148                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1149                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1150                                            args);
1151                            }
1152    
1153                            if ((mbMessageModelImpl.getColumnBitmask() &
1154                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1155                                    Object[] args = new Object[] {
1156                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1157                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1158                                            };
1159    
1160                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1161                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1162                                            args);
1163    
1164                                    args = new Object[] {
1165                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1166                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1167                                            };
1168    
1169                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1170                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1171                                            args);
1172                            }
1173    
1174                            if ((mbMessageModelImpl.getColumnBitmask() &
1175                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
1176                                    Object[] args = new Object[] {
1177                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1178                                                    Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
1179                                            };
1180    
1181                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1182                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1183                                            args);
1184    
1185                                    args = new Object[] {
1186                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1187                                                    Long.valueOf(mbMessageModelImpl.getParentMessageId())
1188                                            };
1189    
1190                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1191                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1192                                            args);
1193                            }
1194    
1195                            if ((mbMessageModelImpl.getColumnBitmask() &
1196                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
1197                                    Object[] args = new Object[] {
1198                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1199                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1200                                            };
1201    
1202                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1203                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1204                                            args);
1205    
1206                                    args = new Object[] {
1207                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1208                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1209                                            };
1210    
1211                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1212                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1213                                            args);
1214                            }
1215    
1216                            if ((mbMessageModelImpl.getColumnBitmask() &
1217                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
1218                                    Object[] args = new Object[] {
1219                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1220                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1221                                            };
1222    
1223                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1224                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1225                                            args);
1226    
1227                                    args = new Object[] {
1228                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1229                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1230                                            };
1231    
1232                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1233                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1234                                            args);
1235                            }
1236    
1237                            if ((mbMessageModelImpl.getColumnBitmask() &
1238                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
1239                                    Object[] args = new Object[] {
1240                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1241                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1242                                            };
1243    
1244                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1245                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1246                                            args);
1247    
1248                                    args = new Object[] {
1249                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1250                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1251                                            };
1252    
1253                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1254                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1255                                            args);
1256                            }
1257    
1258                            if ((mbMessageModelImpl.getColumnBitmask() &
1259                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
1260                                    Object[] args = new Object[] {
1261                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1262                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1263                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1264                                            };
1265    
1266                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1267                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1268                                            args);
1269    
1270                                    args = new Object[] {
1271                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1272                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1273                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1274                                            };
1275    
1276                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1277                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1278                                            args);
1279                            }
1280    
1281                            if ((mbMessageModelImpl.getColumnBitmask() &
1282                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
1283                                    Object[] args = new Object[] {
1284                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1285                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1286                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1287                                            };
1288    
1289                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1290                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1291                                            args);
1292    
1293                                    args = new Object[] {
1294                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1295                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1296                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1297                                            };
1298    
1299                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1300                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1301                                            args);
1302                            }
1303    
1304                            if ((mbMessageModelImpl.getColumnBitmask() &
1305                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
1306                                    Object[] args = new Object[] {
1307                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1308                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1309                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1310                                            };
1311    
1312                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1313                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1314                                            args);
1315    
1316                                    args = new Object[] {
1317                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1318                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1319                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1320                                            };
1321    
1322                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1323                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1324                                            args);
1325                            }
1326    
1327                            if ((mbMessageModelImpl.getColumnBitmask() &
1328                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
1329                                    Object[] args = new Object[] {
1330                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1331                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1332                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1333                                            };
1334    
1335                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1336                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1337                                            args);
1338    
1339                                    args = new Object[] {
1340                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1341                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1342                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1343                                            };
1344    
1345                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1346                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1347                                            args);
1348                            }
1349    
1350                            if ((mbMessageModelImpl.getColumnBitmask() &
1351                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
1352                                    Object[] args = new Object[] {
1353                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1354                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1355                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1356                                            };
1357    
1358                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1359                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1360                                            args);
1361    
1362                                    args = new Object[] {
1363                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1364                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1365                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1366                                            };
1367    
1368                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1369                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1370                                            args);
1371                            }
1372    
1373                            if ((mbMessageModelImpl.getColumnBitmask() &
1374                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1375                                    Object[] args = new Object[] {
1376                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1377                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1378                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1379                                            };
1380    
1381                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1382                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1383                                            args);
1384    
1385                                    args = new Object[] {
1386                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1387                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1388                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1389                                            };
1390    
1391                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1392                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1393                                            args);
1394                            }
1395    
1396                            if ((mbMessageModelImpl.getColumnBitmask() &
1397                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
1398                                    Object[] args = new Object[] {
1399                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1400                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1401                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1402                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1403                                            };
1404    
1405                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1406                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1407                                            args);
1408    
1409                                    args = new Object[] {
1410                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1411                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1412                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1413                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1414                                            };
1415    
1416                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1417                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1418                                            args);
1419                            }
1420    
1421                            if ((mbMessageModelImpl.getColumnBitmask() &
1422                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
1423                                    Object[] args = new Object[] {
1424                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1425                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1426                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1427                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1428                                            };
1429    
1430                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1431                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1432                                            args);
1433    
1434                                    args = new Object[] {
1435                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1436                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1437                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1438                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1439                                            };
1440    
1441                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1442                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1443                                            args);
1444                            }
1445    
1446                            if ((mbMessageModelImpl.getColumnBitmask() &
1447                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
1448                                    Object[] args = new Object[] {
1449                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1450                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1451                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1452                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1453                                            };
1454    
1455                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1456                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1457                                            args);
1458    
1459                                    args = new Object[] {
1460                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1461                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1462                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1463                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1464                                            };
1465    
1466                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1467                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1468                                            args);
1469                            }
1470                    }
1471    
1472                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1473                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
1474    
1475                    if (isNew) {
1476                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1477                                    new Object[] {
1478                                            mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
1479                                    }, mbMessage);
1480                    }
1481                    else {
1482                            if ((mbMessageModelImpl.getColumnBitmask() &
1483                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1484                                    Object[] args = new Object[] {
1485                                                    mbMessageModelImpl.getOriginalUuid(),
1486                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
1487                                            };
1488    
1489                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1490                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1491    
1492                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1493                                            new Object[] {
1494                                                    mbMessage.getUuid(),
1495                                                    Long.valueOf(mbMessage.getGroupId())
1496                                            }, mbMessage);
1497                            }
1498                    }
1499    
1500                    return mbMessage;
1501            }
1502    
1503            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
1504                    if (mbMessage instanceof MBMessageImpl) {
1505                            return mbMessage;
1506                    }
1507    
1508                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
1509    
1510                    mbMessageImpl.setNew(mbMessage.isNew());
1511                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
1512    
1513                    mbMessageImpl.setUuid(mbMessage.getUuid());
1514                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
1515                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
1516                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
1517                    mbMessageImpl.setUserId(mbMessage.getUserId());
1518                    mbMessageImpl.setUserName(mbMessage.getUserName());
1519                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
1520                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
1521                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
1522                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
1523                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
1524                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
1525                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
1526                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
1527                    mbMessageImpl.setSubject(mbMessage.getSubject());
1528                    mbMessageImpl.setBody(mbMessage.getBody());
1529                    mbMessageImpl.setFormat(mbMessage.getFormat());
1530                    mbMessageImpl.setAttachments(mbMessage.isAttachments());
1531                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
1532                    mbMessageImpl.setPriority(mbMessage.getPriority());
1533                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
1534                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
1535                    mbMessageImpl.setStatus(mbMessage.getStatus());
1536                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
1537                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
1538                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
1539    
1540                    return mbMessageImpl;
1541            }
1542    
1543            /**
1544             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1545             *
1546             * @param primaryKey the primary key of the message-boards message
1547             * @return the message-boards message
1548             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
1549             * @throws SystemException if a system exception occurred
1550             */
1551            @Override
1552            public MBMessage findByPrimaryKey(Serializable primaryKey)
1553                    throws NoSuchModelException, SystemException {
1554                    return findByPrimaryKey(((Long)primaryKey).longValue());
1555            }
1556    
1557            /**
1558             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
1559             *
1560             * @param messageId the primary key of the message-boards message
1561             * @return the message-boards message
1562             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1563             * @throws SystemException if a system exception occurred
1564             */
1565            public MBMessage findByPrimaryKey(long messageId)
1566                    throws NoSuchMessageException, SystemException {
1567                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
1568    
1569                    if (mbMessage == null) {
1570                            if (_log.isWarnEnabled()) {
1571                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
1572                            }
1573    
1574                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1575                                    messageId);
1576                    }
1577    
1578                    return mbMessage;
1579            }
1580    
1581            /**
1582             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1583             *
1584             * @param primaryKey the primary key of the message-boards message
1585             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1586             * @throws SystemException if a system exception occurred
1587             */
1588            @Override
1589            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
1590                    throws SystemException {
1591                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1592            }
1593    
1594            /**
1595             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1596             *
1597             * @param messageId the primary key of the message-boards message
1598             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1599             * @throws SystemException if a system exception occurred
1600             */
1601            public MBMessage fetchByPrimaryKey(long messageId)
1602                    throws SystemException {
1603                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1604                                    MBMessageImpl.class, messageId);
1605    
1606                    if (mbMessage == _nullMBMessage) {
1607                            return null;
1608                    }
1609    
1610                    if (mbMessage == null) {
1611                            Session session = null;
1612    
1613                            boolean hasException = false;
1614    
1615                            try {
1616                                    session = openSession();
1617    
1618                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
1619                                                    Long.valueOf(messageId));
1620                            }
1621                            catch (Exception e) {
1622                                    hasException = true;
1623    
1624                                    throw processException(e);
1625                            }
1626                            finally {
1627                                    if (mbMessage != null) {
1628                                            cacheResult(mbMessage);
1629                                    }
1630                                    else if (!hasException) {
1631                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1632                                                    MBMessageImpl.class, messageId, _nullMBMessage);
1633                                    }
1634    
1635                                    closeSession(session);
1636                            }
1637                    }
1638    
1639                    return mbMessage;
1640            }
1641    
1642            /**
1643             * Returns all the message-boards messages where uuid = &#63;.
1644             *
1645             * @param uuid the uuid
1646             * @return the matching message-boards messages
1647             * @throws SystemException if a system exception occurred
1648             */
1649            public List<MBMessage> findByUuid(String uuid) throws SystemException {
1650                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1651            }
1652    
1653            /**
1654             * Returns a range of all the message-boards messages where uuid = &#63;.
1655             *
1656             * <p>
1657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1658             * </p>
1659             *
1660             * @param uuid the uuid
1661             * @param start the lower bound of the range of message-boards messages
1662             * @param end the upper bound of the range of message-boards messages (not inclusive)
1663             * @return the range of matching message-boards messages
1664             * @throws SystemException if a system exception occurred
1665             */
1666            public List<MBMessage> findByUuid(String uuid, int start, int end)
1667                    throws SystemException {
1668                    return findByUuid(uuid, start, end, null);
1669            }
1670    
1671            /**
1672             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
1673             *
1674             * <p>
1675             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1676             * </p>
1677             *
1678             * @param uuid the uuid
1679             * @param start the lower bound of the range of message-boards messages
1680             * @param end the upper bound of the range of message-boards messages (not inclusive)
1681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1682             * @return the ordered range of matching message-boards messages
1683             * @throws SystemException if a system exception occurred
1684             */
1685            public List<MBMessage> findByUuid(String uuid, int start, int end,
1686                    OrderByComparator orderByComparator) throws SystemException {
1687                    FinderPath finderPath = null;
1688                    Object[] finderArgs = null;
1689    
1690                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1691                                    (orderByComparator == null)) {
1692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1693                            finderArgs = new Object[] { uuid };
1694                    }
1695                    else {
1696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1697                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1698                    }
1699    
1700                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1701                                    finderArgs, this);
1702    
1703                    if ((list != null) && !list.isEmpty()) {
1704                            for (MBMessage mbMessage : list) {
1705                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
1706                                            list = null;
1707    
1708                                            break;
1709                                    }
1710                            }
1711                    }
1712    
1713                    if (list == null) {
1714                            StringBundler query = null;
1715    
1716                            if (orderByComparator != null) {
1717                                    query = new StringBundler(3 +
1718                                                    (orderByComparator.getOrderByFields().length * 3));
1719                            }
1720                            else {
1721                                    query = new StringBundler(3);
1722                            }
1723    
1724                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1725    
1726                            if (uuid == null) {
1727                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1728                            }
1729                            else {
1730                                    if (uuid.equals(StringPool.BLANK)) {
1731                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1732                                    }
1733                                    else {
1734                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1735                                    }
1736                            }
1737    
1738                            if (orderByComparator != null) {
1739                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1740                                            orderByComparator);
1741                            }
1742    
1743                            else {
1744                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1745                            }
1746    
1747                            String sql = query.toString();
1748    
1749                            Session session = null;
1750    
1751                            try {
1752                                    session = openSession();
1753    
1754                                    Query q = session.createQuery(sql);
1755    
1756                                    QueryPos qPos = QueryPos.getInstance(q);
1757    
1758                                    if (uuid != null) {
1759                                            qPos.add(uuid);
1760                                    }
1761    
1762                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1763                                                    end);
1764                            }
1765                            catch (Exception e) {
1766                                    throw processException(e);
1767                            }
1768                            finally {
1769                                    if (list == null) {
1770                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1771                                    }
1772                                    else {
1773                                            cacheResult(list);
1774    
1775                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1776                                    }
1777    
1778                                    closeSession(session);
1779                            }
1780                    }
1781    
1782                    return list;
1783            }
1784    
1785            /**
1786             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1787             *
1788             * <p>
1789             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1790             * </p>
1791             *
1792             * @param uuid the uuid
1793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1794             * @return the first matching message-boards message
1795             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1796             * @throws SystemException if a system exception occurred
1797             */
1798            public MBMessage findByUuid_First(String uuid,
1799                    OrderByComparator orderByComparator)
1800                    throws NoSuchMessageException, SystemException {
1801                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
1802    
1803                    if (list.isEmpty()) {
1804                            StringBundler msg = new StringBundler(4);
1805    
1806                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1807    
1808                            msg.append("uuid=");
1809                            msg.append(uuid);
1810    
1811                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1812    
1813                            throw new NoSuchMessageException(msg.toString());
1814                    }
1815                    else {
1816                            return list.get(0);
1817                    }
1818            }
1819    
1820            /**
1821             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1822             *
1823             * <p>
1824             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1825             * </p>
1826             *
1827             * @param uuid the uuid
1828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1829             * @return the last matching message-boards message
1830             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1831             * @throws SystemException if a system exception occurred
1832             */
1833            public MBMessage findByUuid_Last(String uuid,
1834                    OrderByComparator orderByComparator)
1835                    throws NoSuchMessageException, SystemException {
1836                    int count = countByUuid(uuid);
1837    
1838                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
1839                                    orderByComparator);
1840    
1841                    if (list.isEmpty()) {
1842                            StringBundler msg = new StringBundler(4);
1843    
1844                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1845    
1846                            msg.append("uuid=");
1847                            msg.append(uuid);
1848    
1849                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1850    
1851                            throw new NoSuchMessageException(msg.toString());
1852                    }
1853                    else {
1854                            return list.get(0);
1855                    }
1856            }
1857    
1858            /**
1859             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
1860             *
1861             * <p>
1862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1863             * </p>
1864             *
1865             * @param messageId the primary key of the current message-boards message
1866             * @param uuid the uuid
1867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1868             * @return the previous, current, and next message-boards message
1869             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1870             * @throws SystemException if a system exception occurred
1871             */
1872            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
1873                    OrderByComparator orderByComparator)
1874                    throws NoSuchMessageException, SystemException {
1875                    MBMessage mbMessage = findByPrimaryKey(messageId);
1876    
1877                    Session session = null;
1878    
1879                    try {
1880                            session = openSession();
1881    
1882                            MBMessage[] array = new MBMessageImpl[3];
1883    
1884                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1885                                            orderByComparator, true);
1886    
1887                            array[1] = mbMessage;
1888    
1889                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1890                                            orderByComparator, false);
1891    
1892                            return array;
1893                    }
1894                    catch (Exception e) {
1895                            throw processException(e);
1896                    }
1897                    finally {
1898                            closeSession(session);
1899                    }
1900            }
1901    
1902            protected MBMessage getByUuid_PrevAndNext(Session session,
1903                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
1904                    boolean previous) {
1905                    StringBundler query = null;
1906    
1907                    if (orderByComparator != null) {
1908                            query = new StringBundler(6 +
1909                                            (orderByComparator.getOrderByFields().length * 6));
1910                    }
1911                    else {
1912                            query = new StringBundler(3);
1913                    }
1914    
1915                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1916    
1917                    if (uuid == null) {
1918                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1919                    }
1920                    else {
1921                            if (uuid.equals(StringPool.BLANK)) {
1922                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1923                            }
1924                            else {
1925                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1926                            }
1927                    }
1928    
1929                    if (orderByComparator != null) {
1930                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1931    
1932                            if (orderByConditionFields.length > 0) {
1933                                    query.append(WHERE_AND);
1934                            }
1935    
1936                            for (int i = 0; i < orderByConditionFields.length; i++) {
1937                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1938                                    query.append(orderByConditionFields[i]);
1939    
1940                                    if ((i + 1) < orderByConditionFields.length) {
1941                                            if (orderByComparator.isAscending() ^ previous) {
1942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1943                                            }
1944                                            else {
1945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1946                                            }
1947                                    }
1948                                    else {
1949                                            if (orderByComparator.isAscending() ^ previous) {
1950                                                    query.append(WHERE_GREATER_THAN);
1951                                            }
1952                                            else {
1953                                                    query.append(WHERE_LESSER_THAN);
1954                                            }
1955                                    }
1956                            }
1957    
1958                            query.append(ORDER_BY_CLAUSE);
1959    
1960                            String[] orderByFields = orderByComparator.getOrderByFields();
1961    
1962                            for (int i = 0; i < orderByFields.length; i++) {
1963                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1964                                    query.append(orderByFields[i]);
1965    
1966                                    if ((i + 1) < orderByFields.length) {
1967                                            if (orderByComparator.isAscending() ^ previous) {
1968                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1969                                            }
1970                                            else {
1971                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1972                                            }
1973                                    }
1974                                    else {
1975                                            if (orderByComparator.isAscending() ^ previous) {
1976                                                    query.append(ORDER_BY_ASC);
1977                                            }
1978                                            else {
1979                                                    query.append(ORDER_BY_DESC);
1980                                            }
1981                                    }
1982                            }
1983                    }
1984    
1985                    else {
1986                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1987                    }
1988    
1989                    String sql = query.toString();
1990    
1991                    Query q = session.createQuery(sql);
1992    
1993                    q.setFirstResult(0);
1994                    q.setMaxResults(2);
1995    
1996                    QueryPos qPos = QueryPos.getInstance(q);
1997    
1998                    if (uuid != null) {
1999                            qPos.add(uuid);
2000                    }
2001    
2002                    if (orderByComparator != null) {
2003                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2004    
2005                            for (Object value : values) {
2006                                    qPos.add(value);
2007                            }
2008                    }
2009    
2010                    List<MBMessage> list = q.list();
2011    
2012                    if (list.size() == 2) {
2013                            return list.get(1);
2014                    }
2015                    else {
2016                            return null;
2017                    }
2018            }
2019    
2020            /**
2021             * 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.
2022             *
2023             * @param uuid the uuid
2024             * @param groupId the group ID
2025             * @return the matching message-boards message
2026             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2027             * @throws SystemException if a system exception occurred
2028             */
2029            public MBMessage findByUUID_G(String uuid, long groupId)
2030                    throws NoSuchMessageException, SystemException {
2031                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
2032    
2033                    if (mbMessage == null) {
2034                            StringBundler msg = new StringBundler(6);
2035    
2036                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2037    
2038                            msg.append("uuid=");
2039                            msg.append(uuid);
2040    
2041                            msg.append(", groupId=");
2042                            msg.append(groupId);
2043    
2044                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2045    
2046                            if (_log.isWarnEnabled()) {
2047                                    _log.warn(msg.toString());
2048                            }
2049    
2050                            throw new NoSuchMessageException(msg.toString());
2051                    }
2052    
2053                    return mbMessage;
2054            }
2055    
2056            /**
2057             * 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.
2058             *
2059             * @param uuid the uuid
2060             * @param groupId the group ID
2061             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2062             * @throws SystemException if a system exception occurred
2063             */
2064            public MBMessage fetchByUUID_G(String uuid, long groupId)
2065                    throws SystemException {
2066                    return fetchByUUID_G(uuid, groupId, true);
2067            }
2068    
2069            /**
2070             * 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.
2071             *
2072             * @param uuid the uuid
2073             * @param groupId the group ID
2074             * @param retrieveFromCache whether to use the finder cache
2075             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2076             * @throws SystemException if a system exception occurred
2077             */
2078            public MBMessage fetchByUUID_G(String uuid, long groupId,
2079                    boolean retrieveFromCache) throws SystemException {
2080                    Object[] finderArgs = new Object[] { uuid, groupId };
2081    
2082                    Object result = null;
2083    
2084                    if (retrieveFromCache) {
2085                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
2086                                            finderArgs, this);
2087                    }
2088    
2089                    if (result instanceof MBMessage) {
2090                            MBMessage mbMessage = (MBMessage)result;
2091    
2092                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
2093                                            (groupId != mbMessage.getGroupId())) {
2094                                    result = null;
2095                            }
2096                    }
2097    
2098                    if (result == null) {
2099                            StringBundler query = new StringBundler(4);
2100    
2101                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2102    
2103                            if (uuid == null) {
2104                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2105                            }
2106                            else {
2107                                    if (uuid.equals(StringPool.BLANK)) {
2108                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2109                                    }
2110                                    else {
2111                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2112                                    }
2113                            }
2114    
2115                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2116    
2117                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2118    
2119                            String sql = query.toString();
2120    
2121                            Session session = null;
2122    
2123                            try {
2124                                    session = openSession();
2125    
2126                                    Query q = session.createQuery(sql);
2127    
2128                                    QueryPos qPos = QueryPos.getInstance(q);
2129    
2130                                    if (uuid != null) {
2131                                            qPos.add(uuid);
2132                                    }
2133    
2134                                    qPos.add(groupId);
2135    
2136                                    List<MBMessage> list = q.list();
2137    
2138                                    result = list;
2139    
2140                                    MBMessage mbMessage = null;
2141    
2142                                    if (list.isEmpty()) {
2143                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2144                                                    finderArgs, list);
2145                                    }
2146                                    else {
2147                                            mbMessage = list.get(0);
2148    
2149                                            cacheResult(mbMessage);
2150    
2151                                            if ((mbMessage.getUuid() == null) ||
2152                                                            !mbMessage.getUuid().equals(uuid) ||
2153                                                            (mbMessage.getGroupId() != groupId)) {
2154                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2155                                                            finderArgs, mbMessage);
2156                                            }
2157                                    }
2158    
2159                                    return mbMessage;
2160                            }
2161                            catch (Exception e) {
2162                                    throw processException(e);
2163                            }
2164                            finally {
2165                                    if (result == null) {
2166                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
2167                                                    finderArgs);
2168                                    }
2169    
2170                                    closeSession(session);
2171                            }
2172                    }
2173                    else {
2174                            if (result instanceof List<?>) {
2175                                    return null;
2176                            }
2177                            else {
2178                                    return (MBMessage)result;
2179                            }
2180                    }
2181            }
2182    
2183            /**
2184             * Returns all the message-boards messages where groupId = &#63;.
2185             *
2186             * @param groupId the group ID
2187             * @return the matching message-boards messages
2188             * @throws SystemException if a system exception occurred
2189             */
2190            public List<MBMessage> findByGroupId(long groupId)
2191                    throws SystemException {
2192                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2193            }
2194    
2195            /**
2196             * Returns a range of all the message-boards messages where groupId = &#63;.
2197             *
2198             * <p>
2199             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2200             * </p>
2201             *
2202             * @param groupId the group ID
2203             * @param start the lower bound of the range of message-boards messages
2204             * @param end the upper bound of the range of message-boards messages (not inclusive)
2205             * @return the range of matching message-boards messages
2206             * @throws SystemException if a system exception occurred
2207             */
2208            public List<MBMessage> findByGroupId(long groupId, int start, int end)
2209                    throws SystemException {
2210                    return findByGroupId(groupId, start, end, null);
2211            }
2212    
2213            /**
2214             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
2215             *
2216             * <p>
2217             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2218             * </p>
2219             *
2220             * @param groupId the group ID
2221             * @param start the lower bound of the range of message-boards messages
2222             * @param end the upper bound of the range of message-boards messages (not inclusive)
2223             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2224             * @return the ordered range of matching message-boards messages
2225             * @throws SystemException if a system exception occurred
2226             */
2227            public List<MBMessage> findByGroupId(long groupId, int start, int end,
2228                    OrderByComparator orderByComparator) throws SystemException {
2229                    FinderPath finderPath = null;
2230                    Object[] finderArgs = null;
2231    
2232                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2233                                    (orderByComparator == null)) {
2234                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2235                            finderArgs = new Object[] { groupId };
2236                    }
2237                    else {
2238                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2239                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2240                    }
2241    
2242                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2243                                    finderArgs, this);
2244    
2245                    if ((list != null) && !list.isEmpty()) {
2246                            for (MBMessage mbMessage : list) {
2247                                    if ((groupId != mbMessage.getGroupId())) {
2248                                            list = null;
2249    
2250                                            break;
2251                                    }
2252                            }
2253                    }
2254    
2255                    if (list == null) {
2256                            StringBundler query = null;
2257    
2258                            if (orderByComparator != null) {
2259                                    query = new StringBundler(3 +
2260                                                    (orderByComparator.getOrderByFields().length * 3));
2261                            }
2262                            else {
2263                                    query = new StringBundler(3);
2264                            }
2265    
2266                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2267    
2268                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2269    
2270                            if (orderByComparator != null) {
2271                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2272                                            orderByComparator);
2273                            }
2274    
2275                            else {
2276                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2277                            }
2278    
2279                            String sql = query.toString();
2280    
2281                            Session session = null;
2282    
2283                            try {
2284                                    session = openSession();
2285    
2286                                    Query q = session.createQuery(sql);
2287    
2288                                    QueryPos qPos = QueryPos.getInstance(q);
2289    
2290                                    qPos.add(groupId);
2291    
2292                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2293                                                    end);
2294                            }
2295                            catch (Exception e) {
2296                                    throw processException(e);
2297                            }
2298                            finally {
2299                                    if (list == null) {
2300                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2301                                    }
2302                                    else {
2303                                            cacheResult(list);
2304    
2305                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2306                                    }
2307    
2308                                    closeSession(session);
2309                            }
2310                    }
2311    
2312                    return list;
2313            }
2314    
2315            /**
2316             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2317             *
2318             * <p>
2319             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2320             * </p>
2321             *
2322             * @param groupId the group ID
2323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2324             * @return the first matching message-boards message
2325             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2326             * @throws SystemException if a system exception occurred
2327             */
2328            public MBMessage findByGroupId_First(long groupId,
2329                    OrderByComparator orderByComparator)
2330                    throws NoSuchMessageException, SystemException {
2331                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
2332    
2333                    if (list.isEmpty()) {
2334                            StringBundler msg = new StringBundler(4);
2335    
2336                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2337    
2338                            msg.append("groupId=");
2339                            msg.append(groupId);
2340    
2341                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2342    
2343                            throw new NoSuchMessageException(msg.toString());
2344                    }
2345                    else {
2346                            return list.get(0);
2347                    }
2348            }
2349    
2350            /**
2351             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2352             *
2353             * <p>
2354             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2355             * </p>
2356             *
2357             * @param groupId the group ID
2358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2359             * @return the last matching message-boards message
2360             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2361             * @throws SystemException if a system exception occurred
2362             */
2363            public MBMessage findByGroupId_Last(long groupId,
2364                    OrderByComparator orderByComparator)
2365                    throws NoSuchMessageException, SystemException {
2366                    int count = countByGroupId(groupId);
2367    
2368                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
2369                                    orderByComparator);
2370    
2371                    if (list.isEmpty()) {
2372                            StringBundler msg = new StringBundler(4);
2373    
2374                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2375    
2376                            msg.append("groupId=");
2377                            msg.append(groupId);
2378    
2379                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2380    
2381                            throw new NoSuchMessageException(msg.toString());
2382                    }
2383                    else {
2384                            return list.get(0);
2385                    }
2386            }
2387    
2388            /**
2389             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
2390             *
2391             * <p>
2392             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2393             * </p>
2394             *
2395             * @param messageId the primary key of the current message-boards message
2396             * @param groupId the group ID
2397             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2398             * @return the previous, current, and next message-boards message
2399             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2400             * @throws SystemException if a system exception occurred
2401             */
2402            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
2403                    OrderByComparator orderByComparator)
2404                    throws NoSuchMessageException, SystemException {
2405                    MBMessage mbMessage = findByPrimaryKey(messageId);
2406    
2407                    Session session = null;
2408    
2409                    try {
2410                            session = openSession();
2411    
2412                            MBMessage[] array = new MBMessageImpl[3];
2413    
2414                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2415                                            orderByComparator, true);
2416    
2417                            array[1] = mbMessage;
2418    
2419                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2420                                            orderByComparator, false);
2421    
2422                            return array;
2423                    }
2424                    catch (Exception e) {
2425                            throw processException(e);
2426                    }
2427                    finally {
2428                            closeSession(session);
2429                    }
2430            }
2431    
2432            protected MBMessage getByGroupId_PrevAndNext(Session session,
2433                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2434                    boolean previous) {
2435                    StringBundler query = null;
2436    
2437                    if (orderByComparator != null) {
2438                            query = new StringBundler(6 +
2439                                            (orderByComparator.getOrderByFields().length * 6));
2440                    }
2441                    else {
2442                            query = new StringBundler(3);
2443                    }
2444    
2445                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2446    
2447                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2448    
2449                    if (orderByComparator != null) {
2450                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2451    
2452                            if (orderByConditionFields.length > 0) {
2453                                    query.append(WHERE_AND);
2454                            }
2455    
2456                            for (int i = 0; i < orderByConditionFields.length; i++) {
2457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2458                                    query.append(orderByConditionFields[i]);
2459    
2460                                    if ((i + 1) < orderByConditionFields.length) {
2461                                            if (orderByComparator.isAscending() ^ previous) {
2462                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2463                                            }
2464                                            else {
2465                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2466                                            }
2467                                    }
2468                                    else {
2469                                            if (orderByComparator.isAscending() ^ previous) {
2470                                                    query.append(WHERE_GREATER_THAN);
2471                                            }
2472                                            else {
2473                                                    query.append(WHERE_LESSER_THAN);
2474                                            }
2475                                    }
2476                            }
2477    
2478                            query.append(ORDER_BY_CLAUSE);
2479    
2480                            String[] orderByFields = orderByComparator.getOrderByFields();
2481    
2482                            for (int i = 0; i < orderByFields.length; i++) {
2483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2484                                    query.append(orderByFields[i]);
2485    
2486                                    if ((i + 1) < orderByFields.length) {
2487                                            if (orderByComparator.isAscending() ^ previous) {
2488                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2489                                            }
2490                                            else {
2491                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2492                                            }
2493                                    }
2494                                    else {
2495                                            if (orderByComparator.isAscending() ^ previous) {
2496                                                    query.append(ORDER_BY_ASC);
2497                                            }
2498                                            else {
2499                                                    query.append(ORDER_BY_DESC);
2500                                            }
2501                                    }
2502                            }
2503                    }
2504    
2505                    else {
2506                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2507                    }
2508    
2509                    String sql = query.toString();
2510    
2511                    Query q = session.createQuery(sql);
2512    
2513                    q.setFirstResult(0);
2514                    q.setMaxResults(2);
2515    
2516                    QueryPos qPos = QueryPos.getInstance(q);
2517    
2518                    qPos.add(groupId);
2519    
2520                    if (orderByComparator != null) {
2521                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2522    
2523                            for (Object value : values) {
2524                                    qPos.add(value);
2525                            }
2526                    }
2527    
2528                    List<MBMessage> list = q.list();
2529    
2530                    if (list.size() == 2) {
2531                            return list.get(1);
2532                    }
2533                    else {
2534                            return null;
2535                    }
2536            }
2537    
2538            /**
2539             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
2540             *
2541             * @param groupId the group ID
2542             * @return the matching message-boards messages that the user has permission to view
2543             * @throws SystemException if a system exception occurred
2544             */
2545            public List<MBMessage> filterFindByGroupId(long groupId)
2546                    throws SystemException {
2547                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2548                            QueryUtil.ALL_POS, null);
2549            }
2550    
2551            /**
2552             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
2553             *
2554             * <p>
2555             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2556             * </p>
2557             *
2558             * @param groupId the group ID
2559             * @param start the lower bound of the range of message-boards messages
2560             * @param end the upper bound of the range of message-boards messages (not inclusive)
2561             * @return the range of matching message-boards messages that the user has permission to view
2562             * @throws SystemException if a system exception occurred
2563             */
2564            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
2565                    throws SystemException {
2566                    return filterFindByGroupId(groupId, start, end, null);
2567            }
2568    
2569            /**
2570             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
2571             *
2572             * <p>
2573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2574             * </p>
2575             *
2576             * @param groupId the group ID
2577             * @param start the lower bound of the range of message-boards messages
2578             * @param end the upper bound of the range of message-boards messages (not inclusive)
2579             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2580             * @return the ordered range of matching message-boards messages that the user has permission to view
2581             * @throws SystemException if a system exception occurred
2582             */
2583            public List<MBMessage> filterFindByGroupId(long groupId, int start,
2584                    int end, OrderByComparator orderByComparator) throws SystemException {
2585                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2586                            return findByGroupId(groupId, start, end, orderByComparator);
2587                    }
2588    
2589                    StringBundler query = null;
2590    
2591                    if (orderByComparator != null) {
2592                            query = new StringBundler(3 +
2593                                            (orderByComparator.getOrderByFields().length * 3));
2594                    }
2595                    else {
2596                            query = new StringBundler(3);
2597                    }
2598    
2599                    if (getDB().isSupportsInlineDistinct()) {
2600                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2601                    }
2602                    else {
2603                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2604                    }
2605    
2606                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2607    
2608                    if (!getDB().isSupportsInlineDistinct()) {
2609                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2610                    }
2611    
2612                    if (orderByComparator != null) {
2613                            if (getDB().isSupportsInlineDistinct()) {
2614                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2615                                            orderByComparator);
2616                            }
2617                            else {
2618                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2619                                            orderByComparator);
2620                            }
2621                    }
2622    
2623                    else {
2624                            if (getDB().isSupportsInlineDistinct()) {
2625                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2626                            }
2627                            else {
2628                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2629                            }
2630                    }
2631    
2632                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2633                                    MBMessage.class.getName(),
2634                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2635    
2636                    Session session = null;
2637    
2638                    try {
2639                            session = openSession();
2640    
2641                            SQLQuery q = session.createSQLQuery(sql);
2642    
2643                            if (getDB().isSupportsInlineDistinct()) {
2644                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2645                            }
2646                            else {
2647                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2648                            }
2649    
2650                            QueryPos qPos = QueryPos.getInstance(q);
2651    
2652                            qPos.add(groupId);
2653    
2654                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2655                    }
2656                    catch (Exception e) {
2657                            throw processException(e);
2658                    }
2659                    finally {
2660                            closeSession(session);
2661                    }
2662            }
2663    
2664            /**
2665             * 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;.
2666             *
2667             * @param messageId the primary key of the current message-boards message
2668             * @param groupId the group ID
2669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2670             * @return the previous, current, and next message-boards message
2671             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2672             * @throws SystemException if a system exception occurred
2673             */
2674            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2675                    long groupId, OrderByComparator orderByComparator)
2676                    throws NoSuchMessageException, SystemException {
2677                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2678                            return findByGroupId_PrevAndNext(messageId, groupId,
2679                                    orderByComparator);
2680                    }
2681    
2682                    MBMessage mbMessage = findByPrimaryKey(messageId);
2683    
2684                    Session session = null;
2685    
2686                    try {
2687                            session = openSession();
2688    
2689                            MBMessage[] array = new MBMessageImpl[3];
2690    
2691                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2692                                            groupId, orderByComparator, true);
2693    
2694                            array[1] = mbMessage;
2695    
2696                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2697                                            groupId, orderByComparator, false);
2698    
2699                            return array;
2700                    }
2701                    catch (Exception e) {
2702                            throw processException(e);
2703                    }
2704                    finally {
2705                            closeSession(session);
2706                    }
2707            }
2708    
2709            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2710                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2711                    boolean previous) {
2712                    StringBundler query = null;
2713    
2714                    if (orderByComparator != null) {
2715                            query = new StringBundler(6 +
2716                                            (orderByComparator.getOrderByFields().length * 6));
2717                    }
2718                    else {
2719                            query = new StringBundler(3);
2720                    }
2721    
2722                    if (getDB().isSupportsInlineDistinct()) {
2723                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2724                    }
2725                    else {
2726                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2727                    }
2728    
2729                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2730    
2731                    if (!getDB().isSupportsInlineDistinct()) {
2732                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2733                    }
2734    
2735                    if (orderByComparator != null) {
2736                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2737    
2738                            if (orderByConditionFields.length > 0) {
2739                                    query.append(WHERE_AND);
2740                            }
2741    
2742                            for (int i = 0; i < orderByConditionFields.length; i++) {
2743                                    if (getDB().isSupportsInlineDistinct()) {
2744                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2745                                    }
2746                                    else {
2747                                            query.append(_ORDER_BY_ENTITY_TABLE);
2748                                    }
2749    
2750                                    query.append(orderByConditionFields[i]);
2751    
2752                                    if ((i + 1) < orderByConditionFields.length) {
2753                                            if (orderByComparator.isAscending() ^ previous) {
2754                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2755                                            }
2756                                            else {
2757                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2758                                            }
2759                                    }
2760                                    else {
2761                                            if (orderByComparator.isAscending() ^ previous) {
2762                                                    query.append(WHERE_GREATER_THAN);
2763                                            }
2764                                            else {
2765                                                    query.append(WHERE_LESSER_THAN);
2766                                            }
2767                                    }
2768                            }
2769    
2770                            query.append(ORDER_BY_CLAUSE);
2771    
2772                            String[] orderByFields = orderByComparator.getOrderByFields();
2773    
2774                            for (int i = 0; i < orderByFields.length; i++) {
2775                                    if (getDB().isSupportsInlineDistinct()) {
2776                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2777                                    }
2778                                    else {
2779                                            query.append(_ORDER_BY_ENTITY_TABLE);
2780                                    }
2781    
2782                                    query.append(orderByFields[i]);
2783    
2784                                    if ((i + 1) < orderByFields.length) {
2785                                            if (orderByComparator.isAscending() ^ previous) {
2786                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2787                                            }
2788                                            else {
2789                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2790                                            }
2791                                    }
2792                                    else {
2793                                            if (orderByComparator.isAscending() ^ previous) {
2794                                                    query.append(ORDER_BY_ASC);
2795                                            }
2796                                            else {
2797                                                    query.append(ORDER_BY_DESC);
2798                                            }
2799                                    }
2800                            }
2801                    }
2802    
2803                    else {
2804                            if (getDB().isSupportsInlineDistinct()) {
2805                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2806                            }
2807                            else {
2808                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2809                            }
2810                    }
2811    
2812                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2813                                    MBMessage.class.getName(),
2814                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2815    
2816                    SQLQuery q = session.createSQLQuery(sql);
2817    
2818                    q.setFirstResult(0);
2819                    q.setMaxResults(2);
2820    
2821                    if (getDB().isSupportsInlineDistinct()) {
2822                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2823                    }
2824                    else {
2825                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2826                    }
2827    
2828                    QueryPos qPos = QueryPos.getInstance(q);
2829    
2830                    qPos.add(groupId);
2831    
2832                    if (orderByComparator != null) {
2833                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2834    
2835                            for (Object value : values) {
2836                                    qPos.add(value);
2837                            }
2838                    }
2839    
2840                    List<MBMessage> list = q.list();
2841    
2842                    if (list.size() == 2) {
2843                            return list.get(1);
2844                    }
2845                    else {
2846                            return null;
2847                    }
2848            }
2849    
2850            /**
2851             * Returns all the message-boards messages where companyId = &#63;.
2852             *
2853             * @param companyId the company ID
2854             * @return the matching message-boards messages
2855             * @throws SystemException if a system exception occurred
2856             */
2857            public List<MBMessage> findByCompanyId(long companyId)
2858                    throws SystemException {
2859                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2860                            null);
2861            }
2862    
2863            /**
2864             * Returns a range of all the message-boards messages where companyId = &#63;.
2865             *
2866             * <p>
2867             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2868             * </p>
2869             *
2870             * @param companyId the company ID
2871             * @param start the lower bound of the range of message-boards messages
2872             * @param end the upper bound of the range of message-boards messages (not inclusive)
2873             * @return the range of matching message-boards messages
2874             * @throws SystemException if a system exception occurred
2875             */
2876            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2877                    throws SystemException {
2878                    return findByCompanyId(companyId, start, end, null);
2879            }
2880    
2881            /**
2882             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2883             *
2884             * <p>
2885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2886             * </p>
2887             *
2888             * @param companyId the company ID
2889             * @param start the lower bound of the range of message-boards messages
2890             * @param end the upper bound of the range of message-boards messages (not inclusive)
2891             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2892             * @return the ordered range of matching message-boards messages
2893             * @throws SystemException if a system exception occurred
2894             */
2895            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2896                    OrderByComparator orderByComparator) throws SystemException {
2897                    FinderPath finderPath = null;
2898                    Object[] finderArgs = null;
2899    
2900                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2901                                    (orderByComparator == null)) {
2902                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2903                            finderArgs = new Object[] { companyId };
2904                    }
2905                    else {
2906                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2907                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2908                    }
2909    
2910                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2911                                    finderArgs, this);
2912    
2913                    if ((list != null) && !list.isEmpty()) {
2914                            for (MBMessage mbMessage : list) {
2915                                    if ((companyId != mbMessage.getCompanyId())) {
2916                                            list = null;
2917    
2918                                            break;
2919                                    }
2920                            }
2921                    }
2922    
2923                    if (list == null) {
2924                            StringBundler query = null;
2925    
2926                            if (orderByComparator != null) {
2927                                    query = new StringBundler(3 +
2928                                                    (orderByComparator.getOrderByFields().length * 3));
2929                            }
2930                            else {
2931                                    query = new StringBundler(3);
2932                            }
2933    
2934                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2935    
2936                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2937    
2938                            if (orderByComparator != null) {
2939                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2940                                            orderByComparator);
2941                            }
2942    
2943                            else {
2944                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2945                            }
2946    
2947                            String sql = query.toString();
2948    
2949                            Session session = null;
2950    
2951                            try {
2952                                    session = openSession();
2953    
2954                                    Query q = session.createQuery(sql);
2955    
2956                                    QueryPos qPos = QueryPos.getInstance(q);
2957    
2958                                    qPos.add(companyId);
2959    
2960                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2961                                                    end);
2962                            }
2963                            catch (Exception e) {
2964                                    throw processException(e);
2965                            }
2966                            finally {
2967                                    if (list == null) {
2968                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2969                                    }
2970                                    else {
2971                                            cacheResult(list);
2972    
2973                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2974                                    }
2975    
2976                                    closeSession(session);
2977                            }
2978                    }
2979    
2980                    return list;
2981            }
2982    
2983            /**
2984             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2985             *
2986             * <p>
2987             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2988             * </p>
2989             *
2990             * @param companyId the company ID
2991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2992             * @return the first matching message-boards message
2993             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2994             * @throws SystemException if a system exception occurred
2995             */
2996            public MBMessage findByCompanyId_First(long companyId,
2997                    OrderByComparator orderByComparator)
2998                    throws NoSuchMessageException, SystemException {
2999                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
3000                                    orderByComparator);
3001    
3002                    if (list.isEmpty()) {
3003                            StringBundler msg = new StringBundler(4);
3004    
3005                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3006    
3007                            msg.append("companyId=");
3008                            msg.append(companyId);
3009    
3010                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3011    
3012                            throw new NoSuchMessageException(msg.toString());
3013                    }
3014                    else {
3015                            return list.get(0);
3016                    }
3017            }
3018    
3019            /**
3020             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3021             *
3022             * <p>
3023             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3024             * </p>
3025             *
3026             * @param companyId the company ID
3027             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3028             * @return the last matching message-boards message
3029             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3030             * @throws SystemException if a system exception occurred
3031             */
3032            public MBMessage findByCompanyId_Last(long companyId,
3033                    OrderByComparator orderByComparator)
3034                    throws NoSuchMessageException, SystemException {
3035                    int count = countByCompanyId(companyId);
3036    
3037                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
3038                                    orderByComparator);
3039    
3040                    if (list.isEmpty()) {
3041                            StringBundler msg = new StringBundler(4);
3042    
3043                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3044    
3045                            msg.append("companyId=");
3046                            msg.append(companyId);
3047    
3048                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3049    
3050                            throw new NoSuchMessageException(msg.toString());
3051                    }
3052                    else {
3053                            return list.get(0);
3054                    }
3055            }
3056    
3057            /**
3058             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
3059             *
3060             * <p>
3061             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3062             * </p>
3063             *
3064             * @param messageId the primary key of the current message-boards message
3065             * @param companyId the company ID
3066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3067             * @return the previous, current, and next message-boards message
3068             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3069             * @throws SystemException if a system exception occurred
3070             */
3071            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
3072                    long companyId, OrderByComparator orderByComparator)
3073                    throws NoSuchMessageException, SystemException {
3074                    MBMessage mbMessage = findByPrimaryKey(messageId);
3075    
3076                    Session session = null;
3077    
3078                    try {
3079                            session = openSession();
3080    
3081                            MBMessage[] array = new MBMessageImpl[3];
3082    
3083                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
3084                                            companyId, orderByComparator, true);
3085    
3086                            array[1] = mbMessage;
3087    
3088                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
3089                                            companyId, orderByComparator, false);
3090    
3091                            return array;
3092                    }
3093                    catch (Exception e) {
3094                            throw processException(e);
3095                    }
3096                    finally {
3097                            closeSession(session);
3098                    }
3099            }
3100    
3101            protected MBMessage getByCompanyId_PrevAndNext(Session session,
3102                    MBMessage mbMessage, long companyId,
3103                    OrderByComparator orderByComparator, boolean previous) {
3104                    StringBundler query = null;
3105    
3106                    if (orderByComparator != null) {
3107                            query = new StringBundler(6 +
3108                                            (orderByComparator.getOrderByFields().length * 6));
3109                    }
3110                    else {
3111                            query = new StringBundler(3);
3112                    }
3113    
3114                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3115    
3116                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3117    
3118                    if (orderByComparator != null) {
3119                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3120    
3121                            if (orderByConditionFields.length > 0) {
3122                                    query.append(WHERE_AND);
3123                            }
3124    
3125                            for (int i = 0; i < orderByConditionFields.length; i++) {
3126                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3127                                    query.append(orderByConditionFields[i]);
3128    
3129                                    if ((i + 1) < orderByConditionFields.length) {
3130                                            if (orderByComparator.isAscending() ^ previous) {
3131                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3132                                            }
3133                                            else {
3134                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3135                                            }
3136                                    }
3137                                    else {
3138                                            if (orderByComparator.isAscending() ^ previous) {
3139                                                    query.append(WHERE_GREATER_THAN);
3140                                            }
3141                                            else {
3142                                                    query.append(WHERE_LESSER_THAN);
3143                                            }
3144                                    }
3145                            }
3146    
3147                            query.append(ORDER_BY_CLAUSE);
3148    
3149                            String[] orderByFields = orderByComparator.getOrderByFields();
3150    
3151                            for (int i = 0; i < orderByFields.length; i++) {
3152                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3153                                    query.append(orderByFields[i]);
3154    
3155                                    if ((i + 1) < orderByFields.length) {
3156                                            if (orderByComparator.isAscending() ^ previous) {
3157                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3158                                            }
3159                                            else {
3160                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3161                                            }
3162                                    }
3163                                    else {
3164                                            if (orderByComparator.isAscending() ^ previous) {
3165                                                    query.append(ORDER_BY_ASC);
3166                                            }
3167                                            else {
3168                                                    query.append(ORDER_BY_DESC);
3169                                            }
3170                                    }
3171                            }
3172                    }
3173    
3174                    else {
3175                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3176                    }
3177    
3178                    String sql = query.toString();
3179    
3180                    Query q = session.createQuery(sql);
3181    
3182                    q.setFirstResult(0);
3183                    q.setMaxResults(2);
3184    
3185                    QueryPos qPos = QueryPos.getInstance(q);
3186    
3187                    qPos.add(companyId);
3188    
3189                    if (orderByComparator != null) {
3190                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3191    
3192                            for (Object value : values) {
3193                                    qPos.add(value);
3194                            }
3195                    }
3196    
3197                    List<MBMessage> list = q.list();
3198    
3199                    if (list.size() == 2) {
3200                            return list.get(1);
3201                    }
3202                    else {
3203                            return null;
3204                    }
3205            }
3206    
3207            /**
3208             * Returns all the message-boards messages where threadId = &#63;.
3209             *
3210             * @param threadId the thread ID
3211             * @return the matching message-boards messages
3212             * @throws SystemException if a system exception occurred
3213             */
3214            public List<MBMessage> findByThreadId(long threadId)
3215                    throws SystemException {
3216                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3217                            null);
3218            }
3219    
3220            /**
3221             * Returns a range of all the message-boards messages where threadId = &#63;.
3222             *
3223             * <p>
3224             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3225             * </p>
3226             *
3227             * @param threadId the thread ID
3228             * @param start the lower bound of the range of message-boards messages
3229             * @param end the upper bound of the range of message-boards messages (not inclusive)
3230             * @return the range of matching message-boards messages
3231             * @throws SystemException if a system exception occurred
3232             */
3233            public List<MBMessage> findByThreadId(long threadId, int start, int end)
3234                    throws SystemException {
3235                    return findByThreadId(threadId, start, end, null);
3236            }
3237    
3238            /**
3239             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3240             *
3241             * <p>
3242             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3243             * </p>
3244             *
3245             * @param threadId the thread ID
3246             * @param start the lower bound of the range of message-boards messages
3247             * @param end the upper bound of the range of message-boards messages (not inclusive)
3248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3249             * @return the ordered range of matching message-boards messages
3250             * @throws SystemException if a system exception occurred
3251             */
3252            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3253                    OrderByComparator orderByComparator) throws SystemException {
3254                    FinderPath finderPath = null;
3255                    Object[] finderArgs = null;
3256    
3257                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3258                                    (orderByComparator == null)) {
3259                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3260                            finderArgs = new Object[] { threadId };
3261                    }
3262                    else {
3263                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3264                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3265                    }
3266    
3267                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3268                                    finderArgs, this);
3269    
3270                    if ((list != null) && !list.isEmpty()) {
3271                            for (MBMessage mbMessage : list) {
3272                                    if ((threadId != mbMessage.getThreadId())) {
3273                                            list = null;
3274    
3275                                            break;
3276                                    }
3277                            }
3278                    }
3279    
3280                    if (list == null) {
3281                            StringBundler query = null;
3282    
3283                            if (orderByComparator != null) {
3284                                    query = new StringBundler(3 +
3285                                                    (orderByComparator.getOrderByFields().length * 3));
3286                            }
3287                            else {
3288                                    query = new StringBundler(3);
3289                            }
3290    
3291                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3292    
3293                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3294    
3295                            if (orderByComparator != null) {
3296                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3297                                            orderByComparator);
3298                            }
3299    
3300                            else {
3301                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3302                            }
3303    
3304                            String sql = query.toString();
3305    
3306                            Session session = null;
3307    
3308                            try {
3309                                    session = openSession();
3310    
3311                                    Query q = session.createQuery(sql);
3312    
3313                                    QueryPos qPos = QueryPos.getInstance(q);
3314    
3315                                    qPos.add(threadId);
3316    
3317                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3318                                                    end);
3319                            }
3320                            catch (Exception e) {
3321                                    throw processException(e);
3322                            }
3323                            finally {
3324                                    if (list == null) {
3325                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3326                                    }
3327                                    else {
3328                                            cacheResult(list);
3329    
3330                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3331                                    }
3332    
3333                                    closeSession(session);
3334                            }
3335                    }
3336    
3337                    return list;
3338            }
3339    
3340            /**
3341             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3342             *
3343             * <p>
3344             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3345             * </p>
3346             *
3347             * @param threadId the thread ID
3348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3349             * @return the first matching message-boards message
3350             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3351             * @throws SystemException if a system exception occurred
3352             */
3353            public MBMessage findByThreadId_First(long threadId,
3354                    OrderByComparator orderByComparator)
3355                    throws NoSuchMessageException, SystemException {
3356                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3357    
3358                    if (list.isEmpty()) {
3359                            StringBundler msg = new StringBundler(4);
3360    
3361                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3362    
3363                            msg.append("threadId=");
3364                            msg.append(threadId);
3365    
3366                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3367    
3368                            throw new NoSuchMessageException(msg.toString());
3369                    }
3370                    else {
3371                            return list.get(0);
3372                    }
3373            }
3374    
3375            /**
3376             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3377             *
3378             * <p>
3379             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3380             * </p>
3381             *
3382             * @param threadId the thread ID
3383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3384             * @return the last matching message-boards message
3385             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3386             * @throws SystemException if a system exception occurred
3387             */
3388            public MBMessage findByThreadId_Last(long threadId,
3389                    OrderByComparator orderByComparator)
3390                    throws NoSuchMessageException, SystemException {
3391                    int count = countByThreadId(threadId);
3392    
3393                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3394                                    orderByComparator);
3395    
3396                    if (list.isEmpty()) {
3397                            StringBundler msg = new StringBundler(4);
3398    
3399                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3400    
3401                            msg.append("threadId=");
3402                            msg.append(threadId);
3403    
3404                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3405    
3406                            throw new NoSuchMessageException(msg.toString());
3407                    }
3408                    else {
3409                            return list.get(0);
3410                    }
3411            }
3412    
3413            /**
3414             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3415             *
3416             * <p>
3417             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3418             * </p>
3419             *
3420             * @param messageId the primary key of the current message-boards message
3421             * @param threadId the thread ID
3422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3423             * @return the previous, current, and next message-boards message
3424             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3425             * @throws SystemException if a system exception occurred
3426             */
3427            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3428                    long threadId, OrderByComparator orderByComparator)
3429                    throws NoSuchMessageException, SystemException {
3430                    MBMessage mbMessage = findByPrimaryKey(messageId);
3431    
3432                    Session session = null;
3433    
3434                    try {
3435                            session = openSession();
3436    
3437                            MBMessage[] array = new MBMessageImpl[3];
3438    
3439                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3440                                            orderByComparator, true);
3441    
3442                            array[1] = mbMessage;
3443    
3444                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3445                                            orderByComparator, false);
3446    
3447                            return array;
3448                    }
3449                    catch (Exception e) {
3450                            throw processException(e);
3451                    }
3452                    finally {
3453                            closeSession(session);
3454                    }
3455            }
3456    
3457            protected MBMessage getByThreadId_PrevAndNext(Session session,
3458                    MBMessage mbMessage, long threadId,
3459                    OrderByComparator orderByComparator, boolean previous) {
3460                    StringBundler query = null;
3461    
3462                    if (orderByComparator != null) {
3463                            query = new StringBundler(6 +
3464                                            (orderByComparator.getOrderByFields().length * 6));
3465                    }
3466                    else {
3467                            query = new StringBundler(3);
3468                    }
3469    
3470                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3471    
3472                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3473    
3474                    if (orderByComparator != null) {
3475                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3476    
3477                            if (orderByConditionFields.length > 0) {
3478                                    query.append(WHERE_AND);
3479                            }
3480    
3481                            for (int i = 0; i < orderByConditionFields.length; i++) {
3482                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3483                                    query.append(orderByConditionFields[i]);
3484    
3485                                    if ((i + 1) < orderByConditionFields.length) {
3486                                            if (orderByComparator.isAscending() ^ previous) {
3487                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3488                                            }
3489                                            else {
3490                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3491                                            }
3492                                    }
3493                                    else {
3494                                            if (orderByComparator.isAscending() ^ previous) {
3495                                                    query.append(WHERE_GREATER_THAN);
3496                                            }
3497                                            else {
3498                                                    query.append(WHERE_LESSER_THAN);
3499                                            }
3500                                    }
3501                            }
3502    
3503                            query.append(ORDER_BY_CLAUSE);
3504    
3505                            String[] orderByFields = orderByComparator.getOrderByFields();
3506    
3507                            for (int i = 0; i < orderByFields.length; i++) {
3508                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3509                                    query.append(orderByFields[i]);
3510    
3511                                    if ((i + 1) < orderByFields.length) {
3512                                            if (orderByComparator.isAscending() ^ previous) {
3513                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3514                                            }
3515                                            else {
3516                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3517                                            }
3518                                    }
3519                                    else {
3520                                            if (orderByComparator.isAscending() ^ previous) {
3521                                                    query.append(ORDER_BY_ASC);
3522                                            }
3523                                            else {
3524                                                    query.append(ORDER_BY_DESC);
3525                                            }
3526                                    }
3527                            }
3528                    }
3529    
3530                    else {
3531                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3532                    }
3533    
3534                    String sql = query.toString();
3535    
3536                    Query q = session.createQuery(sql);
3537    
3538                    q.setFirstResult(0);
3539                    q.setMaxResults(2);
3540    
3541                    QueryPos qPos = QueryPos.getInstance(q);
3542    
3543                    qPos.add(threadId);
3544    
3545                    if (orderByComparator != null) {
3546                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3547    
3548                            for (Object value : values) {
3549                                    qPos.add(value);
3550                            }
3551                    }
3552    
3553                    List<MBMessage> list = q.list();
3554    
3555                    if (list.size() == 2) {
3556                            return list.get(1);
3557                    }
3558                    else {
3559                            return null;
3560                    }
3561            }
3562    
3563            /**
3564             * Returns all the message-boards messages where threadId = &#63;.
3565             *
3566             * @param threadId the thread ID
3567             * @return the matching message-boards messages
3568             * @throws SystemException if a system exception occurred
3569             */
3570            public List<MBMessage> findByThreadReplies(long threadId)
3571                    throws SystemException {
3572                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3573                            QueryUtil.ALL_POS, null);
3574            }
3575    
3576            /**
3577             * Returns a range of all the message-boards messages where threadId = &#63;.
3578             *
3579             * <p>
3580             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3581             * </p>
3582             *
3583             * @param threadId the thread ID
3584             * @param start the lower bound of the range of message-boards messages
3585             * @param end the upper bound of the range of message-boards messages (not inclusive)
3586             * @return the range of matching message-boards messages
3587             * @throws SystemException if a system exception occurred
3588             */
3589            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3590                    throws SystemException {
3591                    return findByThreadReplies(threadId, start, end, null);
3592            }
3593    
3594            /**
3595             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3596             *
3597             * <p>
3598             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3599             * </p>
3600             *
3601             * @param threadId the thread ID
3602             * @param start the lower bound of the range of message-boards messages
3603             * @param end the upper bound of the range of message-boards messages (not inclusive)
3604             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3605             * @return the ordered range of matching message-boards messages
3606             * @throws SystemException if a system exception occurred
3607             */
3608            public List<MBMessage> findByThreadReplies(long threadId, int start,
3609                    int end, OrderByComparator orderByComparator) throws SystemException {
3610                    FinderPath finderPath = null;
3611                    Object[] finderArgs = null;
3612    
3613                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3614                                    (orderByComparator == null)) {
3615                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3616                            finderArgs = new Object[] { threadId };
3617                    }
3618                    else {
3619                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3620                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3621                    }
3622    
3623                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3624                                    finderArgs, this);
3625    
3626                    if ((list != null) && !list.isEmpty()) {
3627                            for (MBMessage mbMessage : list) {
3628                                    if ((threadId != mbMessage.getThreadId())) {
3629                                            list = null;
3630    
3631                                            break;
3632                                    }
3633                            }
3634                    }
3635    
3636                    if (list == null) {
3637                            StringBundler query = null;
3638    
3639                            if (orderByComparator != null) {
3640                                    query = new StringBundler(3 +
3641                                                    (orderByComparator.getOrderByFields().length * 3));
3642                            }
3643                            else {
3644                                    query = new StringBundler(3);
3645                            }
3646    
3647                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3648    
3649                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3650    
3651                            if (orderByComparator != null) {
3652                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3653                                            orderByComparator);
3654                            }
3655    
3656                            else {
3657                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3658                            }
3659    
3660                            String sql = query.toString();
3661    
3662                            Session session = null;
3663    
3664                            try {
3665                                    session = openSession();
3666    
3667                                    Query q = session.createQuery(sql);
3668    
3669                                    QueryPos qPos = QueryPos.getInstance(q);
3670    
3671                                    qPos.add(threadId);
3672    
3673                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3674                                                    end);
3675                            }
3676                            catch (Exception e) {
3677                                    throw processException(e);
3678                            }
3679                            finally {
3680                                    if (list == null) {
3681                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3682                                    }
3683                                    else {
3684                                            cacheResult(list);
3685    
3686                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3687                                    }
3688    
3689                                    closeSession(session);
3690                            }
3691                    }
3692    
3693                    return list;
3694            }
3695    
3696            /**
3697             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3698             *
3699             * <p>
3700             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3701             * </p>
3702             *
3703             * @param threadId the thread ID
3704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3705             * @return the first matching message-boards message
3706             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3707             * @throws SystemException if a system exception occurred
3708             */
3709            public MBMessage findByThreadReplies_First(long threadId,
3710                    OrderByComparator orderByComparator)
3711                    throws NoSuchMessageException, SystemException {
3712                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3713                                    orderByComparator);
3714    
3715                    if (list.isEmpty()) {
3716                            StringBundler msg = new StringBundler(4);
3717    
3718                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3719    
3720                            msg.append("threadId=");
3721                            msg.append(threadId);
3722    
3723                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3724    
3725                            throw new NoSuchMessageException(msg.toString());
3726                    }
3727                    else {
3728                            return list.get(0);
3729                    }
3730            }
3731    
3732            /**
3733             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3734             *
3735             * <p>
3736             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3737             * </p>
3738             *
3739             * @param threadId the thread ID
3740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3741             * @return the last matching message-boards message
3742             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3743             * @throws SystemException if a system exception occurred
3744             */
3745            public MBMessage findByThreadReplies_Last(long threadId,
3746                    OrderByComparator orderByComparator)
3747                    throws NoSuchMessageException, SystemException {
3748                    int count = countByThreadReplies(threadId);
3749    
3750                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3751                                    orderByComparator);
3752    
3753                    if (list.isEmpty()) {
3754                            StringBundler msg = new StringBundler(4);
3755    
3756                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3757    
3758                            msg.append("threadId=");
3759                            msg.append(threadId);
3760    
3761                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3762    
3763                            throw new NoSuchMessageException(msg.toString());
3764                    }
3765                    else {
3766                            return list.get(0);
3767                    }
3768            }
3769    
3770            /**
3771             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3772             *
3773             * <p>
3774             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3775             * </p>
3776             *
3777             * @param messageId the primary key of the current message-boards message
3778             * @param threadId the thread ID
3779             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3780             * @return the previous, current, and next message-boards message
3781             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3782             * @throws SystemException if a system exception occurred
3783             */
3784            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3785                    long threadId, OrderByComparator orderByComparator)
3786                    throws NoSuchMessageException, SystemException {
3787                    MBMessage mbMessage = findByPrimaryKey(messageId);
3788    
3789                    Session session = null;
3790    
3791                    try {
3792                            session = openSession();
3793    
3794                            MBMessage[] array = new MBMessageImpl[3];
3795    
3796                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3797                                            threadId, orderByComparator, true);
3798    
3799                            array[1] = mbMessage;
3800    
3801                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3802                                            threadId, orderByComparator, false);
3803    
3804                            return array;
3805                    }
3806                    catch (Exception e) {
3807                            throw processException(e);
3808                    }
3809                    finally {
3810                            closeSession(session);
3811                    }
3812            }
3813    
3814            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3815                    MBMessage mbMessage, long threadId,
3816                    OrderByComparator orderByComparator, boolean previous) {
3817                    StringBundler query = null;
3818    
3819                    if (orderByComparator != null) {
3820                            query = new StringBundler(6 +
3821                                            (orderByComparator.getOrderByFields().length * 6));
3822                    }
3823                    else {
3824                            query = new StringBundler(3);
3825                    }
3826    
3827                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3828    
3829                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3830    
3831                    if (orderByComparator != null) {
3832                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3833    
3834                            if (orderByConditionFields.length > 0) {
3835                                    query.append(WHERE_AND);
3836                            }
3837    
3838                            for (int i = 0; i < orderByConditionFields.length; i++) {
3839                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3840                                    query.append(orderByConditionFields[i]);
3841    
3842                                    if ((i + 1) < orderByConditionFields.length) {
3843                                            if (orderByComparator.isAscending() ^ previous) {
3844                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3845                                            }
3846                                            else {
3847                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3848                                            }
3849                                    }
3850                                    else {
3851                                            if (orderByComparator.isAscending() ^ previous) {
3852                                                    query.append(WHERE_GREATER_THAN);
3853                                            }
3854                                            else {
3855                                                    query.append(WHERE_LESSER_THAN);
3856                                            }
3857                                    }
3858                            }
3859    
3860                            query.append(ORDER_BY_CLAUSE);
3861    
3862                            String[] orderByFields = orderByComparator.getOrderByFields();
3863    
3864                            for (int i = 0; i < orderByFields.length; i++) {
3865                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3866                                    query.append(orderByFields[i]);
3867    
3868                                    if ((i + 1) < orderByFields.length) {
3869                                            if (orderByComparator.isAscending() ^ previous) {
3870                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3871                                            }
3872                                            else {
3873                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3874                                            }
3875                                    }
3876                                    else {
3877                                            if (orderByComparator.isAscending() ^ previous) {
3878                                                    query.append(ORDER_BY_ASC);
3879                                            }
3880                                            else {
3881                                                    query.append(ORDER_BY_DESC);
3882                                            }
3883                                    }
3884                            }
3885                    }
3886    
3887                    else {
3888                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3889                    }
3890    
3891                    String sql = query.toString();
3892    
3893                    Query q = session.createQuery(sql);
3894    
3895                    q.setFirstResult(0);
3896                    q.setMaxResults(2);
3897    
3898                    QueryPos qPos = QueryPos.getInstance(q);
3899    
3900                    qPos.add(threadId);
3901    
3902                    if (orderByComparator != null) {
3903                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3904    
3905                            for (Object value : values) {
3906                                    qPos.add(value);
3907                            }
3908                    }
3909    
3910                    List<MBMessage> list = q.list();
3911    
3912                    if (list.size() == 2) {
3913                            return list.get(1);
3914                    }
3915                    else {
3916                            return null;
3917                    }
3918            }
3919    
3920            /**
3921             * Returns all the message-boards messages where userId = &#63;.
3922             *
3923             * @param userId the user ID
3924             * @return the matching message-boards messages
3925             * @throws SystemException if a system exception occurred
3926             */
3927            public List<MBMessage> findByUserId(long userId) throws SystemException {
3928                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3929            }
3930    
3931            /**
3932             * Returns a range of all the message-boards messages where userId = &#63;.
3933             *
3934             * <p>
3935             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3936             * </p>
3937             *
3938             * @param userId the user ID
3939             * @param start the lower bound of the range of message-boards messages
3940             * @param end the upper bound of the range of message-boards messages (not inclusive)
3941             * @return the range of matching message-boards messages
3942             * @throws SystemException if a system exception occurred
3943             */
3944            public List<MBMessage> findByUserId(long userId, int start, int end)
3945                    throws SystemException {
3946                    return findByUserId(userId, start, end, null);
3947            }
3948    
3949            /**
3950             * Returns an ordered range of all the message-boards messages where userId = &#63;.
3951             *
3952             * <p>
3953             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3954             * </p>
3955             *
3956             * @param userId the user ID
3957             * @param start the lower bound of the range of message-boards messages
3958             * @param end the upper bound of the range of message-boards messages (not inclusive)
3959             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3960             * @return the ordered range of matching message-boards messages
3961             * @throws SystemException if a system exception occurred
3962             */
3963            public List<MBMessage> findByUserId(long userId, int start, int end,
3964                    OrderByComparator orderByComparator) throws SystemException {
3965                    FinderPath finderPath = null;
3966                    Object[] finderArgs = null;
3967    
3968                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3969                                    (orderByComparator == null)) {
3970                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3971                            finderArgs = new Object[] { userId };
3972                    }
3973                    else {
3974                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3975                            finderArgs = new Object[] { userId, start, end, orderByComparator };
3976                    }
3977    
3978                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3979                                    finderArgs, this);
3980    
3981                    if ((list != null) && !list.isEmpty()) {
3982                            for (MBMessage mbMessage : list) {
3983                                    if ((userId != mbMessage.getUserId())) {
3984                                            list = null;
3985    
3986                                            break;
3987                                    }
3988                            }
3989                    }
3990    
3991                    if (list == null) {
3992                            StringBundler query = null;
3993    
3994                            if (orderByComparator != null) {
3995                                    query = new StringBundler(3 +
3996                                                    (orderByComparator.getOrderByFields().length * 3));
3997                            }
3998                            else {
3999                                    query = new StringBundler(3);
4000                            }
4001    
4002                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4003    
4004                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4005    
4006                            if (orderByComparator != null) {
4007                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4008                                            orderByComparator);
4009                            }
4010    
4011                            else {
4012                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4013                            }
4014    
4015                            String sql = query.toString();
4016    
4017                            Session session = null;
4018    
4019                            try {
4020                                    session = openSession();
4021    
4022                                    Query q = session.createQuery(sql);
4023    
4024                                    QueryPos qPos = QueryPos.getInstance(q);
4025    
4026                                    qPos.add(userId);
4027    
4028                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4029                                                    end);
4030                            }
4031                            catch (Exception e) {
4032                                    throw processException(e);
4033                            }
4034                            finally {
4035                                    if (list == null) {
4036                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4037                                    }
4038                                    else {
4039                                            cacheResult(list);
4040    
4041                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4042                                    }
4043    
4044                                    closeSession(session);
4045                            }
4046                    }
4047    
4048                    return list;
4049            }
4050    
4051            /**
4052             * Returns the first message-boards message in the ordered set where userId = &#63;.
4053             *
4054             * <p>
4055             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4056             * </p>
4057             *
4058             * @param userId the user ID
4059             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4060             * @return the first matching message-boards message
4061             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4062             * @throws SystemException if a system exception occurred
4063             */
4064            public MBMessage findByUserId_First(long userId,
4065                    OrderByComparator orderByComparator)
4066                    throws NoSuchMessageException, SystemException {
4067                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
4068    
4069                    if (list.isEmpty()) {
4070                            StringBundler msg = new StringBundler(4);
4071    
4072                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4073    
4074                            msg.append("userId=");
4075                            msg.append(userId);
4076    
4077                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4078    
4079                            throw new NoSuchMessageException(msg.toString());
4080                    }
4081                    else {
4082                            return list.get(0);
4083                    }
4084            }
4085    
4086            /**
4087             * Returns the last message-boards message in the ordered set where userId = &#63;.
4088             *
4089             * <p>
4090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4091             * </p>
4092             *
4093             * @param userId the user ID
4094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4095             * @return the last matching message-boards message
4096             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4097             * @throws SystemException if a system exception occurred
4098             */
4099            public MBMessage findByUserId_Last(long userId,
4100                    OrderByComparator orderByComparator)
4101                    throws NoSuchMessageException, SystemException {
4102                    int count = countByUserId(userId);
4103    
4104                    List<MBMessage> list = findByUserId(userId, count - 1, count,
4105                                    orderByComparator);
4106    
4107                    if (list.isEmpty()) {
4108                            StringBundler msg = new StringBundler(4);
4109    
4110                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4111    
4112                            msg.append("userId=");
4113                            msg.append(userId);
4114    
4115                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4116    
4117                            throw new NoSuchMessageException(msg.toString());
4118                    }
4119                    else {
4120                            return list.get(0);
4121                    }
4122            }
4123    
4124            /**
4125             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
4126             *
4127             * <p>
4128             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4129             * </p>
4130             *
4131             * @param messageId the primary key of the current message-boards message
4132             * @param userId the user ID
4133             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4134             * @return the previous, current, and next message-boards message
4135             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4136             * @throws SystemException if a system exception occurred
4137             */
4138            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
4139                    OrderByComparator orderByComparator)
4140                    throws NoSuchMessageException, SystemException {
4141                    MBMessage mbMessage = findByPrimaryKey(messageId);
4142    
4143                    Session session = null;
4144    
4145                    try {
4146                            session = openSession();
4147    
4148                            MBMessage[] array = new MBMessageImpl[3];
4149    
4150                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
4151                                            orderByComparator, true);
4152    
4153                            array[1] = mbMessage;
4154    
4155                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
4156                                            orderByComparator, false);
4157    
4158                            return array;
4159                    }
4160                    catch (Exception e) {
4161                            throw processException(e);
4162                    }
4163                    finally {
4164                            closeSession(session);
4165                    }
4166            }
4167    
4168            protected MBMessage getByUserId_PrevAndNext(Session session,
4169                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
4170                    boolean previous) {
4171                    StringBundler query = null;
4172    
4173                    if (orderByComparator != null) {
4174                            query = new StringBundler(6 +
4175                                            (orderByComparator.getOrderByFields().length * 6));
4176                    }
4177                    else {
4178                            query = new StringBundler(3);
4179                    }
4180    
4181                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4182    
4183                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4184    
4185                    if (orderByComparator != null) {
4186                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4187    
4188                            if (orderByConditionFields.length > 0) {
4189                                    query.append(WHERE_AND);
4190                            }
4191    
4192                            for (int i = 0; i < orderByConditionFields.length; i++) {
4193                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4194                                    query.append(orderByConditionFields[i]);
4195    
4196                                    if ((i + 1) < orderByConditionFields.length) {
4197                                            if (orderByComparator.isAscending() ^ previous) {
4198                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4199                                            }
4200                                            else {
4201                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4202                                            }
4203                                    }
4204                                    else {
4205                                            if (orderByComparator.isAscending() ^ previous) {
4206                                                    query.append(WHERE_GREATER_THAN);
4207                                            }
4208                                            else {
4209                                                    query.append(WHERE_LESSER_THAN);
4210                                            }
4211                                    }
4212                            }
4213    
4214                            query.append(ORDER_BY_CLAUSE);
4215    
4216                            String[] orderByFields = orderByComparator.getOrderByFields();
4217    
4218                            for (int i = 0; i < orderByFields.length; i++) {
4219                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4220                                    query.append(orderByFields[i]);
4221    
4222                                    if ((i + 1) < orderByFields.length) {
4223                                            if (orderByComparator.isAscending() ^ previous) {
4224                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4225                                            }
4226                                            else {
4227                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4228                                            }
4229                                    }
4230                                    else {
4231                                            if (orderByComparator.isAscending() ^ previous) {
4232                                                    query.append(ORDER_BY_ASC);
4233                                            }
4234                                            else {
4235                                                    query.append(ORDER_BY_DESC);
4236                                            }
4237                                    }
4238                            }
4239                    }
4240    
4241                    else {
4242                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4243                    }
4244    
4245                    String sql = query.toString();
4246    
4247                    Query q = session.createQuery(sql);
4248    
4249                    q.setFirstResult(0);
4250                    q.setMaxResults(2);
4251    
4252                    QueryPos qPos = QueryPos.getInstance(q);
4253    
4254                    qPos.add(userId);
4255    
4256                    if (orderByComparator != null) {
4257                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4258    
4259                            for (Object value : values) {
4260                                    qPos.add(value);
4261                            }
4262                    }
4263    
4264                    List<MBMessage> list = q.list();
4265    
4266                    if (list.size() == 2) {
4267                            return list.get(1);
4268                    }
4269                    else {
4270                            return null;
4271                    }
4272            }
4273    
4274            /**
4275             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4276             *
4277             * @param groupId the group ID
4278             * @param userId the user ID
4279             * @return the matching message-boards messages
4280             * @throws SystemException if a system exception occurred
4281             */
4282            public List<MBMessage> findByG_U(long groupId, long userId)
4283                    throws SystemException {
4284                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4285                            null);
4286            }
4287    
4288            /**
4289             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4290             *
4291             * <p>
4292             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4293             * </p>
4294             *
4295             * @param groupId the group ID
4296             * @param userId the user ID
4297             * @param start the lower bound of the range of message-boards messages
4298             * @param end the upper bound of the range of message-boards messages (not inclusive)
4299             * @return the range of matching message-boards messages
4300             * @throws SystemException if a system exception occurred
4301             */
4302            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4303                    int end) throws SystemException {
4304                    return findByG_U(groupId, userId, start, end, null);
4305            }
4306    
4307            /**
4308             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4309             *
4310             * <p>
4311             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4312             * </p>
4313             *
4314             * @param groupId the group ID
4315             * @param userId the user ID
4316             * @param start the lower bound of the range of message-boards messages
4317             * @param end the upper bound of the range of message-boards messages (not inclusive)
4318             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4319             * @return the ordered range of matching message-boards messages
4320             * @throws SystemException if a system exception occurred
4321             */
4322            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4323                    int end, OrderByComparator orderByComparator) throws SystemException {
4324                    FinderPath finderPath = null;
4325                    Object[] finderArgs = null;
4326    
4327                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4328                                    (orderByComparator == null)) {
4329                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4330                            finderArgs = new Object[] { groupId, userId };
4331                    }
4332                    else {
4333                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4334                            finderArgs = new Object[] {
4335                                            groupId, userId,
4336                                            
4337                                            start, end, orderByComparator
4338                                    };
4339                    }
4340    
4341                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4342                                    finderArgs, this);
4343    
4344                    if ((list != null) && !list.isEmpty()) {
4345                            for (MBMessage mbMessage : list) {
4346                                    if ((groupId != mbMessage.getGroupId()) ||
4347                                                    (userId != mbMessage.getUserId())) {
4348                                            list = null;
4349    
4350                                            break;
4351                                    }
4352                            }
4353                    }
4354    
4355                    if (list == null) {
4356                            StringBundler query = null;
4357    
4358                            if (orderByComparator != null) {
4359                                    query = new StringBundler(4 +
4360                                                    (orderByComparator.getOrderByFields().length * 3));
4361                            }
4362                            else {
4363                                    query = new StringBundler(4);
4364                            }
4365    
4366                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4367    
4368                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4369    
4370                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4371    
4372                            if (orderByComparator != null) {
4373                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4374                                            orderByComparator);
4375                            }
4376    
4377                            else {
4378                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4379                            }
4380    
4381                            String sql = query.toString();
4382    
4383                            Session session = null;
4384    
4385                            try {
4386                                    session = openSession();
4387    
4388                                    Query q = session.createQuery(sql);
4389    
4390                                    QueryPos qPos = QueryPos.getInstance(q);
4391    
4392                                    qPos.add(groupId);
4393    
4394                                    qPos.add(userId);
4395    
4396                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4397                                                    end);
4398                            }
4399                            catch (Exception e) {
4400                                    throw processException(e);
4401                            }
4402                            finally {
4403                                    if (list == null) {
4404                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4405                                    }
4406                                    else {
4407                                            cacheResult(list);
4408    
4409                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4410                                    }
4411    
4412                                    closeSession(session);
4413                            }
4414                    }
4415    
4416                    return list;
4417            }
4418    
4419            /**
4420             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4421             *
4422             * <p>
4423             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4424             * </p>
4425             *
4426             * @param groupId the group ID
4427             * @param userId the user ID
4428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4429             * @return the first matching message-boards message
4430             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4431             * @throws SystemException if a system exception occurred
4432             */
4433            public MBMessage findByG_U_First(long groupId, long userId,
4434                    OrderByComparator orderByComparator)
4435                    throws NoSuchMessageException, SystemException {
4436                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4437                                    orderByComparator);
4438    
4439                    if (list.isEmpty()) {
4440                            StringBundler msg = new StringBundler(6);
4441    
4442                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4443    
4444                            msg.append("groupId=");
4445                            msg.append(groupId);
4446    
4447                            msg.append(", userId=");
4448                            msg.append(userId);
4449    
4450                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4451    
4452                            throw new NoSuchMessageException(msg.toString());
4453                    }
4454                    else {
4455                            return list.get(0);
4456                    }
4457            }
4458    
4459            /**
4460             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4461             *
4462             * <p>
4463             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4464             * </p>
4465             *
4466             * @param groupId the group ID
4467             * @param userId the user ID
4468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4469             * @return the last matching message-boards message
4470             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4471             * @throws SystemException if a system exception occurred
4472             */
4473            public MBMessage findByG_U_Last(long groupId, long userId,
4474                    OrderByComparator orderByComparator)
4475                    throws NoSuchMessageException, SystemException {
4476                    int count = countByG_U(groupId, userId);
4477    
4478                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4479                                    orderByComparator);
4480    
4481                    if (list.isEmpty()) {
4482                            StringBundler msg = new StringBundler(6);
4483    
4484                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4485    
4486                            msg.append("groupId=");
4487                            msg.append(groupId);
4488    
4489                            msg.append(", userId=");
4490                            msg.append(userId);
4491    
4492                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4493    
4494                            throw new NoSuchMessageException(msg.toString());
4495                    }
4496                    else {
4497                            return list.get(0);
4498                    }
4499            }
4500    
4501            /**
4502             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4503             *
4504             * <p>
4505             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4506             * </p>
4507             *
4508             * @param messageId the primary key of the current message-boards message
4509             * @param groupId the group ID
4510             * @param userId the user ID
4511             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4512             * @return the previous, current, and next message-boards message
4513             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4514             * @throws SystemException if a system exception occurred
4515             */
4516            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4517                    long userId, OrderByComparator orderByComparator)
4518                    throws NoSuchMessageException, SystemException {
4519                    MBMessage mbMessage = findByPrimaryKey(messageId);
4520    
4521                    Session session = null;
4522    
4523                    try {
4524                            session = openSession();
4525    
4526                            MBMessage[] array = new MBMessageImpl[3];
4527    
4528                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4529                                            userId, orderByComparator, true);
4530    
4531                            array[1] = mbMessage;
4532    
4533                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4534                                            userId, orderByComparator, false);
4535    
4536                            return array;
4537                    }
4538                    catch (Exception e) {
4539                            throw processException(e);
4540                    }
4541                    finally {
4542                            closeSession(session);
4543                    }
4544            }
4545    
4546            protected MBMessage getByG_U_PrevAndNext(Session session,
4547                    MBMessage mbMessage, long groupId, long userId,
4548                    OrderByComparator orderByComparator, boolean previous) {
4549                    StringBundler query = null;
4550    
4551                    if (orderByComparator != null) {
4552                            query = new StringBundler(6 +
4553                                            (orderByComparator.getOrderByFields().length * 6));
4554                    }
4555                    else {
4556                            query = new StringBundler(3);
4557                    }
4558    
4559                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4560    
4561                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4562    
4563                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4564    
4565                    if (orderByComparator != null) {
4566                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4567    
4568                            if (orderByConditionFields.length > 0) {
4569                                    query.append(WHERE_AND);
4570                            }
4571    
4572                            for (int i = 0; i < orderByConditionFields.length; i++) {
4573                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4574                                    query.append(orderByConditionFields[i]);
4575    
4576                                    if ((i + 1) < orderByConditionFields.length) {
4577                                            if (orderByComparator.isAscending() ^ previous) {
4578                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4579                                            }
4580                                            else {
4581                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4582                                            }
4583                                    }
4584                                    else {
4585                                            if (orderByComparator.isAscending() ^ previous) {
4586                                                    query.append(WHERE_GREATER_THAN);
4587                                            }
4588                                            else {
4589                                                    query.append(WHERE_LESSER_THAN);
4590                                            }
4591                                    }
4592                            }
4593    
4594                            query.append(ORDER_BY_CLAUSE);
4595    
4596                            String[] orderByFields = orderByComparator.getOrderByFields();
4597    
4598                            for (int i = 0; i < orderByFields.length; i++) {
4599                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4600                                    query.append(orderByFields[i]);
4601    
4602                                    if ((i + 1) < orderByFields.length) {
4603                                            if (orderByComparator.isAscending() ^ previous) {
4604                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4605                                            }
4606                                            else {
4607                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4608                                            }
4609                                    }
4610                                    else {
4611                                            if (orderByComparator.isAscending() ^ previous) {
4612                                                    query.append(ORDER_BY_ASC);
4613                                            }
4614                                            else {
4615                                                    query.append(ORDER_BY_DESC);
4616                                            }
4617                                    }
4618                            }
4619                    }
4620    
4621                    else {
4622                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4623                    }
4624    
4625                    String sql = query.toString();
4626    
4627                    Query q = session.createQuery(sql);
4628    
4629                    q.setFirstResult(0);
4630                    q.setMaxResults(2);
4631    
4632                    QueryPos qPos = QueryPos.getInstance(q);
4633    
4634                    qPos.add(groupId);
4635    
4636                    qPos.add(userId);
4637    
4638                    if (orderByComparator != null) {
4639                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4640    
4641                            for (Object value : values) {
4642                                    qPos.add(value);
4643                            }
4644                    }
4645    
4646                    List<MBMessage> list = q.list();
4647    
4648                    if (list.size() == 2) {
4649                            return list.get(1);
4650                    }
4651                    else {
4652                            return null;
4653                    }
4654            }
4655    
4656            /**
4657             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4658             *
4659             * @param groupId the group ID
4660             * @param userId the user ID
4661             * @return the matching message-boards messages that the user has permission to view
4662             * @throws SystemException if a system exception occurred
4663             */
4664            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4665                    throws SystemException {
4666                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4667                            QueryUtil.ALL_POS, null);
4668            }
4669    
4670            /**
4671             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4672             *
4673             * <p>
4674             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4675             * </p>
4676             *
4677             * @param groupId the group ID
4678             * @param userId the user ID
4679             * @param start the lower bound of the range of message-boards messages
4680             * @param end the upper bound of the range of message-boards messages (not inclusive)
4681             * @return the range of matching message-boards messages that the user has permission to view
4682             * @throws SystemException if a system exception occurred
4683             */
4684            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4685                    int start, int end) throws SystemException {
4686                    return filterFindByG_U(groupId, userId, start, end, null);
4687            }
4688    
4689            /**
4690             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4691             *
4692             * <p>
4693             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4694             * </p>
4695             *
4696             * @param groupId the group ID
4697             * @param userId the user ID
4698             * @param start the lower bound of the range of message-boards messages
4699             * @param end the upper bound of the range of message-boards messages (not inclusive)
4700             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4701             * @return the ordered range of matching message-boards messages that the user has permission to view
4702             * @throws SystemException if a system exception occurred
4703             */
4704            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4705                    int start, int end, OrderByComparator orderByComparator)
4706                    throws SystemException {
4707                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4708                            return findByG_U(groupId, userId, start, end, orderByComparator);
4709                    }
4710    
4711                    StringBundler query = null;
4712    
4713                    if (orderByComparator != null) {
4714                            query = new StringBundler(4 +
4715                                            (orderByComparator.getOrderByFields().length * 3));
4716                    }
4717                    else {
4718                            query = new StringBundler(4);
4719                    }
4720    
4721                    if (getDB().isSupportsInlineDistinct()) {
4722                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4723                    }
4724                    else {
4725                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4726                    }
4727    
4728                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4729    
4730                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4731    
4732                    if (!getDB().isSupportsInlineDistinct()) {
4733                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4734                    }
4735    
4736                    if (orderByComparator != null) {
4737                            if (getDB().isSupportsInlineDistinct()) {
4738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4739                                            orderByComparator);
4740                            }
4741                            else {
4742                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4743                                            orderByComparator);
4744                            }
4745                    }
4746    
4747                    else {
4748                            if (getDB().isSupportsInlineDistinct()) {
4749                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4750                            }
4751                            else {
4752                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4753                            }
4754                    }
4755    
4756                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4757                                    MBMessage.class.getName(),
4758                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4759    
4760                    Session session = null;
4761    
4762                    try {
4763                            session = openSession();
4764    
4765                            SQLQuery q = session.createSQLQuery(sql);
4766    
4767                            if (getDB().isSupportsInlineDistinct()) {
4768                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4769                            }
4770                            else {
4771                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4772                            }
4773    
4774                            QueryPos qPos = QueryPos.getInstance(q);
4775    
4776                            qPos.add(groupId);
4777    
4778                            qPos.add(userId);
4779    
4780                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4781                    }
4782                    catch (Exception e) {
4783                            throw processException(e);
4784                    }
4785                    finally {
4786                            closeSession(session);
4787                    }
4788            }
4789    
4790            /**
4791             * 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;.
4792             *
4793             * @param messageId the primary key of the current message-boards message
4794             * @param groupId the group ID
4795             * @param userId the user ID
4796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4797             * @return the previous, current, and next message-boards message
4798             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4799             * @throws SystemException if a system exception occurred
4800             */
4801            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4802                    long groupId, long userId, OrderByComparator orderByComparator)
4803                    throws NoSuchMessageException, SystemException {
4804                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4805                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4806                                    orderByComparator);
4807                    }
4808    
4809                    MBMessage mbMessage = findByPrimaryKey(messageId);
4810    
4811                    Session session = null;
4812    
4813                    try {
4814                            session = openSession();
4815    
4816                            MBMessage[] array = new MBMessageImpl[3];
4817    
4818                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4819                                            userId, orderByComparator, true);
4820    
4821                            array[1] = mbMessage;
4822    
4823                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4824                                            userId, orderByComparator, false);
4825    
4826                            return array;
4827                    }
4828                    catch (Exception e) {
4829                            throw processException(e);
4830                    }
4831                    finally {
4832                            closeSession(session);
4833                    }
4834            }
4835    
4836            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4837                    MBMessage mbMessage, long groupId, long userId,
4838                    OrderByComparator orderByComparator, boolean previous) {
4839                    StringBundler query = null;
4840    
4841                    if (orderByComparator != null) {
4842                            query = new StringBundler(6 +
4843                                            (orderByComparator.getOrderByFields().length * 6));
4844                    }
4845                    else {
4846                            query = new StringBundler(3);
4847                    }
4848    
4849                    if (getDB().isSupportsInlineDistinct()) {
4850                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4851                    }
4852                    else {
4853                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4854                    }
4855    
4856                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4857    
4858                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4859    
4860                    if (!getDB().isSupportsInlineDistinct()) {
4861                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4862                    }
4863    
4864                    if (orderByComparator != null) {
4865                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4866    
4867                            if (orderByConditionFields.length > 0) {
4868                                    query.append(WHERE_AND);
4869                            }
4870    
4871                            for (int i = 0; i < orderByConditionFields.length; i++) {
4872                                    if (getDB().isSupportsInlineDistinct()) {
4873                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4874                                    }
4875                                    else {
4876                                            query.append(_ORDER_BY_ENTITY_TABLE);
4877                                    }
4878    
4879                                    query.append(orderByConditionFields[i]);
4880    
4881                                    if ((i + 1) < orderByConditionFields.length) {
4882                                            if (orderByComparator.isAscending() ^ previous) {
4883                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4884                                            }
4885                                            else {
4886                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4887                                            }
4888                                    }
4889                                    else {
4890                                            if (orderByComparator.isAscending() ^ previous) {
4891                                                    query.append(WHERE_GREATER_THAN);
4892                                            }
4893                                            else {
4894                                                    query.append(WHERE_LESSER_THAN);
4895                                            }
4896                                    }
4897                            }
4898    
4899                            query.append(ORDER_BY_CLAUSE);
4900    
4901                            String[] orderByFields = orderByComparator.getOrderByFields();
4902    
4903                            for (int i = 0; i < orderByFields.length; i++) {
4904                                    if (getDB().isSupportsInlineDistinct()) {
4905                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4906                                    }
4907                                    else {
4908                                            query.append(_ORDER_BY_ENTITY_TABLE);
4909                                    }
4910    
4911                                    query.append(orderByFields[i]);
4912    
4913                                    if ((i + 1) < orderByFields.length) {
4914                                            if (orderByComparator.isAscending() ^ previous) {
4915                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4916                                            }
4917                                            else {
4918                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4919                                            }
4920                                    }
4921                                    else {
4922                                            if (orderByComparator.isAscending() ^ previous) {
4923                                                    query.append(ORDER_BY_ASC);
4924                                            }
4925                                            else {
4926                                                    query.append(ORDER_BY_DESC);
4927                                            }
4928                                    }
4929                            }
4930                    }
4931    
4932                    else {
4933                            if (getDB().isSupportsInlineDistinct()) {
4934                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4935                            }
4936                            else {
4937                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4938                            }
4939                    }
4940    
4941                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4942                                    MBMessage.class.getName(),
4943                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4944    
4945                    SQLQuery q = session.createSQLQuery(sql);
4946    
4947                    q.setFirstResult(0);
4948                    q.setMaxResults(2);
4949    
4950                    if (getDB().isSupportsInlineDistinct()) {
4951                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4952                    }
4953                    else {
4954                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4955                    }
4956    
4957                    QueryPos qPos = QueryPos.getInstance(q);
4958    
4959                    qPos.add(groupId);
4960    
4961                    qPos.add(userId);
4962    
4963                    if (orderByComparator != null) {
4964                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4965    
4966                            for (Object value : values) {
4967                                    qPos.add(value);
4968                            }
4969                    }
4970    
4971                    List<MBMessage> list = q.list();
4972    
4973                    if (list.size() == 2) {
4974                            return list.get(1);
4975                    }
4976                    else {
4977                            return null;
4978                    }
4979            }
4980    
4981            /**
4982             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
4983             *
4984             * @param groupId the group ID
4985             * @param categoryId the category ID
4986             * @return the matching message-boards messages
4987             * @throws SystemException if a system exception occurred
4988             */
4989            public List<MBMessage> findByG_C(long groupId, long categoryId)
4990                    throws SystemException {
4991                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
4992                            QueryUtil.ALL_POS, null);
4993            }
4994    
4995            /**
4996             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
4997             *
4998             * <p>
4999             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5000             * </p>
5001             *
5002             * @param groupId the group ID
5003             * @param categoryId the category ID
5004             * @param start the lower bound of the range of message-boards messages
5005             * @param end the upper bound of the range of message-boards messages (not inclusive)
5006             * @return the range of matching message-boards messages
5007             * @throws SystemException if a system exception occurred
5008             */
5009            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5010                    int end) throws SystemException {
5011                    return findByG_C(groupId, categoryId, start, end, null);
5012            }
5013    
5014            /**
5015             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5016             *
5017             * <p>
5018             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5019             * </p>
5020             *
5021             * @param groupId the group ID
5022             * @param categoryId the category ID
5023             * @param start the lower bound of the range of message-boards messages
5024             * @param end the upper bound of the range of message-boards messages (not inclusive)
5025             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5026             * @return the ordered range of matching message-boards messages
5027             * @throws SystemException if a system exception occurred
5028             */
5029            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5030                    int end, OrderByComparator orderByComparator) throws SystemException {
5031                    FinderPath finderPath = null;
5032                    Object[] finderArgs = null;
5033    
5034                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5035                                    (orderByComparator == null)) {
5036                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5037                            finderArgs = new Object[] { groupId, categoryId };
5038                    }
5039                    else {
5040                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5041                            finderArgs = new Object[] {
5042                                            groupId, categoryId,
5043                                            
5044                                            start, end, orderByComparator
5045                                    };
5046                    }
5047    
5048                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5049                                    finderArgs, this);
5050    
5051                    if ((list != null) && !list.isEmpty()) {
5052                            for (MBMessage mbMessage : list) {
5053                                    if ((groupId != mbMessage.getGroupId()) ||
5054                                                    (categoryId != mbMessage.getCategoryId())) {
5055                                            list = null;
5056    
5057                                            break;
5058                                    }
5059                            }
5060                    }
5061    
5062                    if (list == null) {
5063                            StringBundler query = null;
5064    
5065                            if (orderByComparator != null) {
5066                                    query = new StringBundler(4 +
5067                                                    (orderByComparator.getOrderByFields().length * 3));
5068                            }
5069                            else {
5070                                    query = new StringBundler(4);
5071                            }
5072    
5073                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5074    
5075                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5076    
5077                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5078    
5079                            if (orderByComparator != null) {
5080                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5081                                            orderByComparator);
5082                            }
5083    
5084                            else {
5085                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5086                            }
5087    
5088                            String sql = query.toString();
5089    
5090                            Session session = null;
5091    
5092                            try {
5093                                    session = openSession();
5094    
5095                                    Query q = session.createQuery(sql);
5096    
5097                                    QueryPos qPos = QueryPos.getInstance(q);
5098    
5099                                    qPos.add(groupId);
5100    
5101                                    qPos.add(categoryId);
5102    
5103                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5104                                                    end);
5105                            }
5106                            catch (Exception e) {
5107                                    throw processException(e);
5108                            }
5109                            finally {
5110                                    if (list == null) {
5111                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5112                                    }
5113                                    else {
5114                                            cacheResult(list);
5115    
5116                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5117                                    }
5118    
5119                                    closeSession(session);
5120                            }
5121                    }
5122    
5123                    return list;
5124            }
5125    
5126            /**
5127             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5128             *
5129             * <p>
5130             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5131             * </p>
5132             *
5133             * @param groupId the group ID
5134             * @param categoryId the category ID
5135             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5136             * @return the first matching message-boards message
5137             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5138             * @throws SystemException if a system exception occurred
5139             */
5140            public MBMessage findByG_C_First(long groupId, long categoryId,
5141                    OrderByComparator orderByComparator)
5142                    throws NoSuchMessageException, SystemException {
5143                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5144                                    orderByComparator);
5145    
5146                    if (list.isEmpty()) {
5147                            StringBundler msg = new StringBundler(6);
5148    
5149                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5150    
5151                            msg.append("groupId=");
5152                            msg.append(groupId);
5153    
5154                            msg.append(", categoryId=");
5155                            msg.append(categoryId);
5156    
5157                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5158    
5159                            throw new NoSuchMessageException(msg.toString());
5160                    }
5161                    else {
5162                            return list.get(0);
5163                    }
5164            }
5165    
5166            /**
5167             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5168             *
5169             * <p>
5170             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5171             * </p>
5172             *
5173             * @param groupId the group ID
5174             * @param categoryId the category ID
5175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5176             * @return the last matching message-boards message
5177             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5178             * @throws SystemException if a system exception occurred
5179             */
5180            public MBMessage findByG_C_Last(long groupId, long categoryId,
5181                    OrderByComparator orderByComparator)
5182                    throws NoSuchMessageException, SystemException {
5183                    int count = countByG_C(groupId, categoryId);
5184    
5185                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5186                                    orderByComparator);
5187    
5188                    if (list.isEmpty()) {
5189                            StringBundler msg = new StringBundler(6);
5190    
5191                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5192    
5193                            msg.append("groupId=");
5194                            msg.append(groupId);
5195    
5196                            msg.append(", categoryId=");
5197                            msg.append(categoryId);
5198    
5199                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5200    
5201                            throw new NoSuchMessageException(msg.toString());
5202                    }
5203                    else {
5204                            return list.get(0);
5205                    }
5206            }
5207    
5208            /**
5209             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5210             *
5211             * <p>
5212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5213             * </p>
5214             *
5215             * @param messageId the primary key of the current message-boards message
5216             * @param groupId the group ID
5217             * @param categoryId the category ID
5218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5219             * @return the previous, current, and next message-boards message
5220             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5221             * @throws SystemException if a system exception occurred
5222             */
5223            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5224                    long categoryId, OrderByComparator orderByComparator)
5225                    throws NoSuchMessageException, SystemException {
5226                    MBMessage mbMessage = findByPrimaryKey(messageId);
5227    
5228                    Session session = null;
5229    
5230                    try {
5231                            session = openSession();
5232    
5233                            MBMessage[] array = new MBMessageImpl[3];
5234    
5235                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5236                                            categoryId, orderByComparator, true);
5237    
5238                            array[1] = mbMessage;
5239    
5240                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5241                                            categoryId, orderByComparator, false);
5242    
5243                            return array;
5244                    }
5245                    catch (Exception e) {
5246                            throw processException(e);
5247                    }
5248                    finally {
5249                            closeSession(session);
5250                    }
5251            }
5252    
5253            protected MBMessage getByG_C_PrevAndNext(Session session,
5254                    MBMessage mbMessage, long groupId, long categoryId,
5255                    OrderByComparator orderByComparator, boolean previous) {
5256                    StringBundler query = null;
5257    
5258                    if (orderByComparator != null) {
5259                            query = new StringBundler(6 +
5260                                            (orderByComparator.getOrderByFields().length * 6));
5261                    }
5262                    else {
5263                            query = new StringBundler(3);
5264                    }
5265    
5266                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5267    
5268                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5269    
5270                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5271    
5272                    if (orderByComparator != null) {
5273                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5274    
5275                            if (orderByConditionFields.length > 0) {
5276                                    query.append(WHERE_AND);
5277                            }
5278    
5279                            for (int i = 0; i < orderByConditionFields.length; i++) {
5280                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5281                                    query.append(orderByConditionFields[i]);
5282    
5283                                    if ((i + 1) < orderByConditionFields.length) {
5284                                            if (orderByComparator.isAscending() ^ previous) {
5285                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5286                                            }
5287                                            else {
5288                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5289                                            }
5290                                    }
5291                                    else {
5292                                            if (orderByComparator.isAscending() ^ previous) {
5293                                                    query.append(WHERE_GREATER_THAN);
5294                                            }
5295                                            else {
5296                                                    query.append(WHERE_LESSER_THAN);
5297                                            }
5298                                    }
5299                            }
5300    
5301                            query.append(ORDER_BY_CLAUSE);
5302    
5303                            String[] orderByFields = orderByComparator.getOrderByFields();
5304    
5305                            for (int i = 0; i < orderByFields.length; i++) {
5306                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5307                                    query.append(orderByFields[i]);
5308    
5309                                    if ((i + 1) < orderByFields.length) {
5310                                            if (orderByComparator.isAscending() ^ previous) {
5311                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5312                                            }
5313                                            else {
5314                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5315                                            }
5316                                    }
5317                                    else {
5318                                            if (orderByComparator.isAscending() ^ previous) {
5319                                                    query.append(ORDER_BY_ASC);
5320                                            }
5321                                            else {
5322                                                    query.append(ORDER_BY_DESC);
5323                                            }
5324                                    }
5325                            }
5326                    }
5327    
5328                    else {
5329                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5330                    }
5331    
5332                    String sql = query.toString();
5333    
5334                    Query q = session.createQuery(sql);
5335    
5336                    q.setFirstResult(0);
5337                    q.setMaxResults(2);
5338    
5339                    QueryPos qPos = QueryPos.getInstance(q);
5340    
5341                    qPos.add(groupId);
5342    
5343                    qPos.add(categoryId);
5344    
5345                    if (orderByComparator != null) {
5346                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5347    
5348                            for (Object value : values) {
5349                                    qPos.add(value);
5350                            }
5351                    }
5352    
5353                    List<MBMessage> list = q.list();
5354    
5355                    if (list.size() == 2) {
5356                            return list.get(1);
5357                    }
5358                    else {
5359                            return null;
5360                    }
5361            }
5362    
5363            /**
5364             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5365             *
5366             * @param groupId the group ID
5367             * @param categoryId the category ID
5368             * @return the matching message-boards messages that the user has permission to view
5369             * @throws SystemException if a system exception occurred
5370             */
5371            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5372                    throws SystemException {
5373                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5374                            QueryUtil.ALL_POS, null);
5375            }
5376    
5377            /**
5378             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5379             *
5380             * <p>
5381             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5382             * </p>
5383             *
5384             * @param groupId the group ID
5385             * @param categoryId the category ID
5386             * @param start the lower bound of the range of message-boards messages
5387             * @param end the upper bound of the range of message-boards messages (not inclusive)
5388             * @return the range of matching message-boards messages that the user has permission to view
5389             * @throws SystemException if a system exception occurred
5390             */
5391            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5392                    int start, int end) throws SystemException {
5393                    return filterFindByG_C(groupId, categoryId, start, end, null);
5394            }
5395    
5396            /**
5397             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5398             *
5399             * <p>
5400             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5401             * </p>
5402             *
5403             * @param groupId the group ID
5404             * @param categoryId the category ID
5405             * @param start the lower bound of the range of message-boards messages
5406             * @param end the upper bound of the range of message-boards messages (not inclusive)
5407             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5408             * @return the ordered range of matching message-boards messages that the user has permission to view
5409             * @throws SystemException if a system exception occurred
5410             */
5411            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5412                    int start, int end, OrderByComparator orderByComparator)
5413                    throws SystemException {
5414                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5415                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5416                    }
5417    
5418                    StringBundler query = null;
5419    
5420                    if (orderByComparator != null) {
5421                            query = new StringBundler(4 +
5422                                            (orderByComparator.getOrderByFields().length * 3));
5423                    }
5424                    else {
5425                            query = new StringBundler(4);
5426                    }
5427    
5428                    if (getDB().isSupportsInlineDistinct()) {
5429                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5430                    }
5431                    else {
5432                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5433                    }
5434    
5435                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5436    
5437                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5438    
5439                    if (!getDB().isSupportsInlineDistinct()) {
5440                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5441                    }
5442    
5443                    if (orderByComparator != null) {
5444                            if (getDB().isSupportsInlineDistinct()) {
5445                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5446                                            orderByComparator);
5447                            }
5448                            else {
5449                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5450                                            orderByComparator);
5451                            }
5452                    }
5453    
5454                    else {
5455                            if (getDB().isSupportsInlineDistinct()) {
5456                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5457                            }
5458                            else {
5459                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5460                            }
5461                    }
5462    
5463                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5464                                    MBMessage.class.getName(),
5465                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5466    
5467                    Session session = null;
5468    
5469                    try {
5470                            session = openSession();
5471    
5472                            SQLQuery q = session.createSQLQuery(sql);
5473    
5474                            if (getDB().isSupportsInlineDistinct()) {
5475                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5476                            }
5477                            else {
5478                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5479                            }
5480    
5481                            QueryPos qPos = QueryPos.getInstance(q);
5482    
5483                            qPos.add(groupId);
5484    
5485                            qPos.add(categoryId);
5486    
5487                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5488                    }
5489                    catch (Exception e) {
5490                            throw processException(e);
5491                    }
5492                    finally {
5493                            closeSession(session);
5494                    }
5495            }
5496    
5497            /**
5498             * 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;.
5499             *
5500             * @param messageId the primary key of the current message-boards message
5501             * @param groupId the group ID
5502             * @param categoryId the category ID
5503             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5504             * @return the previous, current, and next message-boards message
5505             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5506             * @throws SystemException if a system exception occurred
5507             */
5508            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5509                    long groupId, long categoryId, OrderByComparator orderByComparator)
5510                    throws NoSuchMessageException, SystemException {
5511                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5512                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5513                                    orderByComparator);
5514                    }
5515    
5516                    MBMessage mbMessage = findByPrimaryKey(messageId);
5517    
5518                    Session session = null;
5519    
5520                    try {
5521                            session = openSession();
5522    
5523                            MBMessage[] array = new MBMessageImpl[3];
5524    
5525                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5526                                            categoryId, orderByComparator, true);
5527    
5528                            array[1] = mbMessage;
5529    
5530                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5531                                            categoryId, orderByComparator, false);
5532    
5533                            return array;
5534                    }
5535                    catch (Exception e) {
5536                            throw processException(e);
5537                    }
5538                    finally {
5539                            closeSession(session);
5540                    }
5541            }
5542    
5543            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5544                    MBMessage mbMessage, long groupId, long categoryId,
5545                    OrderByComparator orderByComparator, boolean previous) {
5546                    StringBundler query = null;
5547    
5548                    if (orderByComparator != null) {
5549                            query = new StringBundler(6 +
5550                                            (orderByComparator.getOrderByFields().length * 6));
5551                    }
5552                    else {
5553                            query = new StringBundler(3);
5554                    }
5555    
5556                    if (getDB().isSupportsInlineDistinct()) {
5557                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5558                    }
5559                    else {
5560                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5561                    }
5562    
5563                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5564    
5565                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5566    
5567                    if (!getDB().isSupportsInlineDistinct()) {
5568                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5569                    }
5570    
5571                    if (orderByComparator != null) {
5572                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5573    
5574                            if (orderByConditionFields.length > 0) {
5575                                    query.append(WHERE_AND);
5576                            }
5577    
5578                            for (int i = 0; i < orderByConditionFields.length; i++) {
5579                                    if (getDB().isSupportsInlineDistinct()) {
5580                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5581                                    }
5582                                    else {
5583                                            query.append(_ORDER_BY_ENTITY_TABLE);
5584                                    }
5585    
5586                                    query.append(orderByConditionFields[i]);
5587    
5588                                    if ((i + 1) < orderByConditionFields.length) {
5589                                            if (orderByComparator.isAscending() ^ previous) {
5590                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5591                                            }
5592                                            else {
5593                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5594                                            }
5595                                    }
5596                                    else {
5597                                            if (orderByComparator.isAscending() ^ previous) {
5598                                                    query.append(WHERE_GREATER_THAN);
5599                                            }
5600                                            else {
5601                                                    query.append(WHERE_LESSER_THAN);
5602                                            }
5603                                    }
5604                            }
5605    
5606                            query.append(ORDER_BY_CLAUSE);
5607    
5608                            String[] orderByFields = orderByComparator.getOrderByFields();
5609    
5610                            for (int i = 0; i < orderByFields.length; i++) {
5611                                    if (getDB().isSupportsInlineDistinct()) {
5612                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5613                                    }
5614                                    else {
5615                                            query.append(_ORDER_BY_ENTITY_TABLE);
5616                                    }
5617    
5618                                    query.append(orderByFields[i]);
5619    
5620                                    if ((i + 1) < orderByFields.length) {
5621                                            if (orderByComparator.isAscending() ^ previous) {
5622                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5623                                            }
5624                                            else {
5625                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5626                                            }
5627                                    }
5628                                    else {
5629                                            if (orderByComparator.isAscending() ^ previous) {
5630                                                    query.append(ORDER_BY_ASC);
5631                                            }
5632                                            else {
5633                                                    query.append(ORDER_BY_DESC);
5634                                            }
5635                                    }
5636                            }
5637                    }
5638    
5639                    else {
5640                            if (getDB().isSupportsInlineDistinct()) {
5641                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5642                            }
5643                            else {
5644                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5645                            }
5646                    }
5647    
5648                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5649                                    MBMessage.class.getName(),
5650                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5651    
5652                    SQLQuery q = session.createSQLQuery(sql);
5653    
5654                    q.setFirstResult(0);
5655                    q.setMaxResults(2);
5656    
5657                    if (getDB().isSupportsInlineDistinct()) {
5658                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5659                    }
5660                    else {
5661                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5662                    }
5663    
5664                    QueryPos qPos = QueryPos.getInstance(q);
5665    
5666                    qPos.add(groupId);
5667    
5668                    qPos.add(categoryId);
5669    
5670                    if (orderByComparator != null) {
5671                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5672    
5673                            for (Object value : values) {
5674                                    qPos.add(value);
5675                            }
5676                    }
5677    
5678                    List<MBMessage> list = q.list();
5679    
5680                    if (list.size() == 2) {
5681                            return list.get(1);
5682                    }
5683                    else {
5684                            return null;
5685                    }
5686            }
5687    
5688            /**
5689             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5690             *
5691             * @param groupId the group ID
5692             * @param status the status
5693             * @return the matching message-boards messages
5694             * @throws SystemException if a system exception occurred
5695             */
5696            public List<MBMessage> findByG_S(long groupId, int status)
5697                    throws SystemException {
5698                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5699                            null);
5700            }
5701    
5702            /**
5703             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5704             *
5705             * <p>
5706             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5707             * </p>
5708             *
5709             * @param groupId the group ID
5710             * @param status the status
5711             * @param start the lower bound of the range of message-boards messages
5712             * @param end the upper bound of the range of message-boards messages (not inclusive)
5713             * @return the range of matching message-boards messages
5714             * @throws SystemException if a system exception occurred
5715             */
5716            public List<MBMessage> findByG_S(long groupId, int status, int start,
5717                    int end) throws SystemException {
5718                    return findByG_S(groupId, status, start, end, null);
5719            }
5720    
5721            /**
5722             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
5723             *
5724             * <p>
5725             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5726             * </p>
5727             *
5728             * @param groupId the group ID
5729             * @param status the status
5730             * @param start the lower bound of the range of message-boards messages
5731             * @param end the upper bound of the range of message-boards messages (not inclusive)
5732             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5733             * @return the ordered range of matching message-boards messages
5734             * @throws SystemException if a system exception occurred
5735             */
5736            public List<MBMessage> findByG_S(long groupId, int status, int start,
5737                    int end, OrderByComparator orderByComparator) throws SystemException {
5738                    FinderPath finderPath = null;
5739                    Object[] finderArgs = null;
5740    
5741                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5742                                    (orderByComparator == null)) {
5743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
5744                            finderArgs = new Object[] { groupId, status };
5745                    }
5746                    else {
5747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
5748                            finderArgs = new Object[] {
5749                                            groupId, status,
5750                                            
5751                                            start, end, orderByComparator
5752                                    };
5753                    }
5754    
5755                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5756                                    finderArgs, this);
5757    
5758                    if ((list != null) && !list.isEmpty()) {
5759                            for (MBMessage mbMessage : list) {
5760                                    if ((groupId != mbMessage.getGroupId()) ||
5761                                                    (status != mbMessage.getStatus())) {
5762                                            list = null;
5763    
5764                                            break;
5765                                    }
5766                            }
5767                    }
5768    
5769                    if (list == null) {
5770                            StringBundler query = null;
5771    
5772                            if (orderByComparator != null) {
5773                                    query = new StringBundler(4 +
5774                                                    (orderByComparator.getOrderByFields().length * 3));
5775                            }
5776                            else {
5777                                    query = new StringBundler(4);
5778                            }
5779    
5780                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5781    
5782                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5783    
5784                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5785    
5786                            if (orderByComparator != null) {
5787                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5788                                            orderByComparator);
5789                            }
5790    
5791                            else {
5792                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5793                            }
5794    
5795                            String sql = query.toString();
5796    
5797                            Session session = null;
5798    
5799                            try {
5800                                    session = openSession();
5801    
5802                                    Query q = session.createQuery(sql);
5803    
5804                                    QueryPos qPos = QueryPos.getInstance(q);
5805    
5806                                    qPos.add(groupId);
5807    
5808                                    qPos.add(status);
5809    
5810                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5811                                                    end);
5812                            }
5813                            catch (Exception e) {
5814                                    throw processException(e);
5815                            }
5816                            finally {
5817                                    if (list == null) {
5818                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5819                                    }
5820                                    else {
5821                                            cacheResult(list);
5822    
5823                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5824                                    }
5825    
5826                                    closeSession(session);
5827                            }
5828                    }
5829    
5830                    return list;
5831            }
5832    
5833            /**
5834             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
5835             *
5836             * <p>
5837             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5838             * </p>
5839             *
5840             * @param groupId the group ID
5841             * @param status the status
5842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5843             * @return the first matching message-boards message
5844             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5845             * @throws SystemException if a system exception occurred
5846             */
5847            public MBMessage findByG_S_First(long groupId, int status,
5848                    OrderByComparator orderByComparator)
5849                    throws NoSuchMessageException, SystemException {
5850                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
5851                                    orderByComparator);
5852    
5853                    if (list.isEmpty()) {
5854                            StringBundler msg = new StringBundler(6);
5855    
5856                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5857    
5858                            msg.append("groupId=");
5859                            msg.append(groupId);
5860    
5861                            msg.append(", status=");
5862                            msg.append(status);
5863    
5864                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5865    
5866                            throw new NoSuchMessageException(msg.toString());
5867                    }
5868                    else {
5869                            return list.get(0);
5870                    }
5871            }
5872    
5873            /**
5874             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
5875             *
5876             * <p>
5877             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5878             * </p>
5879             *
5880             * @param groupId the group ID
5881             * @param status the status
5882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5883             * @return the last matching message-boards message
5884             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5885             * @throws SystemException if a system exception occurred
5886             */
5887            public MBMessage findByG_S_Last(long groupId, int status,
5888                    OrderByComparator orderByComparator)
5889                    throws NoSuchMessageException, SystemException {
5890                    int count = countByG_S(groupId, status);
5891    
5892                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
5893                                    orderByComparator);
5894    
5895                    if (list.isEmpty()) {
5896                            StringBundler msg = new StringBundler(6);
5897    
5898                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5899    
5900                            msg.append("groupId=");
5901                            msg.append(groupId);
5902    
5903                            msg.append(", status=");
5904                            msg.append(status);
5905    
5906                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5907    
5908                            throw new NoSuchMessageException(msg.toString());
5909                    }
5910                    else {
5911                            return list.get(0);
5912                    }
5913            }
5914    
5915            /**
5916             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
5917             *
5918             * <p>
5919             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5920             * </p>
5921             *
5922             * @param messageId the primary key of the current message-boards message
5923             * @param groupId the group ID
5924             * @param status the status
5925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5926             * @return the previous, current, and next message-boards message
5927             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5928             * @throws SystemException if a system exception occurred
5929             */
5930            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
5931                    int status, OrderByComparator orderByComparator)
5932                    throws NoSuchMessageException, SystemException {
5933                    MBMessage mbMessage = findByPrimaryKey(messageId);
5934    
5935                    Session session = null;
5936    
5937                    try {
5938                            session = openSession();
5939    
5940                            MBMessage[] array = new MBMessageImpl[3];
5941    
5942                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
5943                                            status, orderByComparator, true);
5944    
5945                            array[1] = mbMessage;
5946    
5947                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
5948                                            status, orderByComparator, false);
5949    
5950                            return array;
5951                    }
5952                    catch (Exception e) {
5953                            throw processException(e);
5954                    }
5955                    finally {
5956                            closeSession(session);
5957                    }
5958            }
5959    
5960            protected MBMessage getByG_S_PrevAndNext(Session session,
5961                    MBMessage mbMessage, long groupId, int status,
5962                    OrderByComparator orderByComparator, boolean previous) {
5963                    StringBundler query = null;
5964    
5965                    if (orderByComparator != null) {
5966                            query = new StringBundler(6 +
5967                                            (orderByComparator.getOrderByFields().length * 6));
5968                    }
5969                    else {
5970                            query = new StringBundler(3);
5971                    }
5972    
5973                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5974    
5975                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5976    
5977                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5978    
5979                    if (orderByComparator != null) {
5980                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5981    
5982                            if (orderByConditionFields.length > 0) {
5983                                    query.append(WHERE_AND);
5984                            }
5985    
5986                            for (int i = 0; i < orderByConditionFields.length; i++) {
5987                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5988                                    query.append(orderByConditionFields[i]);
5989    
5990                                    if ((i + 1) < orderByConditionFields.length) {
5991                                            if (orderByComparator.isAscending() ^ previous) {
5992                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5993                                            }
5994                                            else {
5995                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5996                                            }
5997                                    }
5998                                    else {
5999                                            if (orderByComparator.isAscending() ^ previous) {
6000                                                    query.append(WHERE_GREATER_THAN);
6001                                            }
6002                                            else {
6003                                                    query.append(WHERE_LESSER_THAN);
6004                                            }
6005                                    }
6006                            }
6007    
6008                            query.append(ORDER_BY_CLAUSE);
6009    
6010                            String[] orderByFields = orderByComparator.getOrderByFields();
6011    
6012                            for (int i = 0; i < orderByFields.length; i++) {
6013                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6014                                    query.append(orderByFields[i]);
6015    
6016                                    if ((i + 1) < orderByFields.length) {
6017                                            if (orderByComparator.isAscending() ^ previous) {
6018                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6019                                            }
6020                                            else {
6021                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6022                                            }
6023                                    }
6024                                    else {
6025                                            if (orderByComparator.isAscending() ^ previous) {
6026                                                    query.append(ORDER_BY_ASC);
6027                                            }
6028                                            else {
6029                                                    query.append(ORDER_BY_DESC);
6030                                            }
6031                                    }
6032                            }
6033                    }
6034    
6035                    else {
6036                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6037                    }
6038    
6039                    String sql = query.toString();
6040    
6041                    Query q = session.createQuery(sql);
6042    
6043                    q.setFirstResult(0);
6044                    q.setMaxResults(2);
6045    
6046                    QueryPos qPos = QueryPos.getInstance(q);
6047    
6048                    qPos.add(groupId);
6049    
6050                    qPos.add(status);
6051    
6052                    if (orderByComparator != null) {
6053                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6054    
6055                            for (Object value : values) {
6056                                    qPos.add(value);
6057                            }
6058                    }
6059    
6060                    List<MBMessage> list = q.list();
6061    
6062                    if (list.size() == 2) {
6063                            return list.get(1);
6064                    }
6065                    else {
6066                            return null;
6067                    }
6068            }
6069    
6070            /**
6071             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6072             *
6073             * @param groupId the group ID
6074             * @param status the status
6075             * @return the matching message-boards messages that the user has permission to view
6076             * @throws SystemException if a system exception occurred
6077             */
6078            public List<MBMessage> filterFindByG_S(long groupId, int status)
6079                    throws SystemException {
6080                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6081                            QueryUtil.ALL_POS, null);
6082            }
6083    
6084            /**
6085             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6086             *
6087             * <p>
6088             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6089             * </p>
6090             *
6091             * @param groupId the group ID
6092             * @param status the status
6093             * @param start the lower bound of the range of message-boards messages
6094             * @param end the upper bound of the range of message-boards messages (not inclusive)
6095             * @return the range of matching message-boards messages that the user has permission to view
6096             * @throws SystemException if a system exception occurred
6097             */
6098            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6099                    int end) throws SystemException {
6100                    return filterFindByG_S(groupId, status, start, end, null);
6101            }
6102    
6103            /**
6104             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6105             *
6106             * <p>
6107             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6108             * </p>
6109             *
6110             * @param groupId the group ID
6111             * @param status the status
6112             * @param start the lower bound of the range of message-boards messages
6113             * @param end the upper bound of the range of message-boards messages (not inclusive)
6114             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6115             * @return the ordered range of matching message-boards messages that the user has permission to view
6116             * @throws SystemException if a system exception occurred
6117             */
6118            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6119                    int end, OrderByComparator orderByComparator) throws SystemException {
6120                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6121                            return findByG_S(groupId, status, start, end, orderByComparator);
6122                    }
6123    
6124                    StringBundler query = null;
6125    
6126                    if (orderByComparator != null) {
6127                            query = new StringBundler(4 +
6128                                            (orderByComparator.getOrderByFields().length * 3));
6129                    }
6130                    else {
6131                            query = new StringBundler(4);
6132                    }
6133    
6134                    if (getDB().isSupportsInlineDistinct()) {
6135                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6136                    }
6137                    else {
6138                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6139                    }
6140    
6141                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6142    
6143                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6144    
6145                    if (!getDB().isSupportsInlineDistinct()) {
6146                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6147                    }
6148    
6149                    if (orderByComparator != null) {
6150                            if (getDB().isSupportsInlineDistinct()) {
6151                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6152                                            orderByComparator);
6153                            }
6154                            else {
6155                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6156                                            orderByComparator);
6157                            }
6158                    }
6159    
6160                    else {
6161                            if (getDB().isSupportsInlineDistinct()) {
6162                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6163                            }
6164                            else {
6165                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6166                            }
6167                    }
6168    
6169                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6170                                    MBMessage.class.getName(),
6171                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6172    
6173                    Session session = null;
6174    
6175                    try {
6176                            session = openSession();
6177    
6178                            SQLQuery q = session.createSQLQuery(sql);
6179    
6180                            if (getDB().isSupportsInlineDistinct()) {
6181                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6182                            }
6183                            else {
6184                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6185                            }
6186    
6187                            QueryPos qPos = QueryPos.getInstance(q);
6188    
6189                            qPos.add(groupId);
6190    
6191                            qPos.add(status);
6192    
6193                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6194                    }
6195                    catch (Exception e) {
6196                            throw processException(e);
6197                    }
6198                    finally {
6199                            closeSession(session);
6200                    }
6201            }
6202    
6203            /**
6204             * 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;.
6205             *
6206             * @param messageId the primary key of the current message-boards message
6207             * @param groupId the group ID
6208             * @param status the status
6209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6210             * @return the previous, current, and next message-boards message
6211             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6212             * @throws SystemException if a system exception occurred
6213             */
6214            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6215                    long groupId, int status, OrderByComparator orderByComparator)
6216                    throws NoSuchMessageException, SystemException {
6217                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6218                            return findByG_S_PrevAndNext(messageId, groupId, status,
6219                                    orderByComparator);
6220                    }
6221    
6222                    MBMessage mbMessage = findByPrimaryKey(messageId);
6223    
6224                    Session session = null;
6225    
6226                    try {
6227                            session = openSession();
6228    
6229                            MBMessage[] array = new MBMessageImpl[3];
6230    
6231                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6232                                            status, orderByComparator, true);
6233    
6234                            array[1] = mbMessage;
6235    
6236                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6237                                            status, orderByComparator, false);
6238    
6239                            return array;
6240                    }
6241                    catch (Exception e) {
6242                            throw processException(e);
6243                    }
6244                    finally {
6245                            closeSession(session);
6246                    }
6247            }
6248    
6249            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6250                    MBMessage mbMessage, long groupId, int status,
6251                    OrderByComparator orderByComparator, boolean previous) {
6252                    StringBundler query = null;
6253    
6254                    if (orderByComparator != null) {
6255                            query = new StringBundler(6 +
6256                                            (orderByComparator.getOrderByFields().length * 6));
6257                    }
6258                    else {
6259                            query = new StringBundler(3);
6260                    }
6261    
6262                    if (getDB().isSupportsInlineDistinct()) {
6263                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6264                    }
6265                    else {
6266                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6267                    }
6268    
6269                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6270    
6271                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6272    
6273                    if (!getDB().isSupportsInlineDistinct()) {
6274                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6275                    }
6276    
6277                    if (orderByComparator != null) {
6278                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6279    
6280                            if (orderByConditionFields.length > 0) {
6281                                    query.append(WHERE_AND);
6282                            }
6283    
6284                            for (int i = 0; i < orderByConditionFields.length; i++) {
6285                                    if (getDB().isSupportsInlineDistinct()) {
6286                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6287                                    }
6288                                    else {
6289                                            query.append(_ORDER_BY_ENTITY_TABLE);
6290                                    }
6291    
6292                                    query.append(orderByConditionFields[i]);
6293    
6294                                    if ((i + 1) < orderByConditionFields.length) {
6295                                            if (orderByComparator.isAscending() ^ previous) {
6296                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6297                                            }
6298                                            else {
6299                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6300                                            }
6301                                    }
6302                                    else {
6303                                            if (orderByComparator.isAscending() ^ previous) {
6304                                                    query.append(WHERE_GREATER_THAN);
6305                                            }
6306                                            else {
6307                                                    query.append(WHERE_LESSER_THAN);
6308                                            }
6309                                    }
6310                            }
6311    
6312                            query.append(ORDER_BY_CLAUSE);
6313    
6314                            String[] orderByFields = orderByComparator.getOrderByFields();
6315    
6316                            for (int i = 0; i < orderByFields.length; i++) {
6317                                    if (getDB().isSupportsInlineDistinct()) {
6318                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6319                                    }
6320                                    else {
6321                                            query.append(_ORDER_BY_ENTITY_TABLE);
6322                                    }
6323    
6324                                    query.append(orderByFields[i]);
6325    
6326                                    if ((i + 1) < orderByFields.length) {
6327                                            if (orderByComparator.isAscending() ^ previous) {
6328                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6329                                            }
6330                                            else {
6331                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6332                                            }
6333                                    }
6334                                    else {
6335                                            if (orderByComparator.isAscending() ^ previous) {
6336                                                    query.append(ORDER_BY_ASC);
6337                                            }
6338                                            else {
6339                                                    query.append(ORDER_BY_DESC);
6340                                            }
6341                                    }
6342                            }
6343                    }
6344    
6345                    else {
6346                            if (getDB().isSupportsInlineDistinct()) {
6347                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6348                            }
6349                            else {
6350                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6351                            }
6352                    }
6353    
6354                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6355                                    MBMessage.class.getName(),
6356                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6357    
6358                    SQLQuery q = session.createSQLQuery(sql);
6359    
6360                    q.setFirstResult(0);
6361                    q.setMaxResults(2);
6362    
6363                    if (getDB().isSupportsInlineDistinct()) {
6364                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6365                    }
6366                    else {
6367                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6368                    }
6369    
6370                    QueryPos qPos = QueryPos.getInstance(q);
6371    
6372                    qPos.add(groupId);
6373    
6374                    qPos.add(status);
6375    
6376                    if (orderByComparator != null) {
6377                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6378    
6379                            for (Object value : values) {
6380                                    qPos.add(value);
6381                            }
6382                    }
6383    
6384                    List<MBMessage> list = q.list();
6385    
6386                    if (list.size() == 2) {
6387                            return list.get(1);
6388                    }
6389                    else {
6390                            return null;
6391                    }
6392            }
6393    
6394            /**
6395             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6396             *
6397             * @param companyId the company ID
6398             * @param status the status
6399             * @return the matching message-boards messages
6400             * @throws SystemException if a system exception occurred
6401             */
6402            public List<MBMessage> findByC_S(long companyId, int status)
6403                    throws SystemException {
6404                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6405                            QueryUtil.ALL_POS, null);
6406            }
6407    
6408            /**
6409             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6410             *
6411             * <p>
6412             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6413             * </p>
6414             *
6415             * @param companyId the company ID
6416             * @param status the status
6417             * @param start the lower bound of the range of message-boards messages
6418             * @param end the upper bound of the range of message-boards messages (not inclusive)
6419             * @return the range of matching message-boards messages
6420             * @throws SystemException if a system exception occurred
6421             */
6422            public List<MBMessage> findByC_S(long companyId, int status, int start,
6423                    int end) throws SystemException {
6424                    return findByC_S(companyId, status, start, end, null);
6425            }
6426    
6427            /**
6428             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6429             *
6430             * <p>
6431             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6432             * </p>
6433             *
6434             * @param companyId the company ID
6435             * @param status the status
6436             * @param start the lower bound of the range of message-boards messages
6437             * @param end the upper bound of the range of message-boards messages (not inclusive)
6438             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6439             * @return the ordered range of matching message-boards messages
6440             * @throws SystemException if a system exception occurred
6441             */
6442            public List<MBMessage> findByC_S(long companyId, int status, int start,
6443                    int end, OrderByComparator orderByComparator) throws SystemException {
6444                    FinderPath finderPath = null;
6445                    Object[] finderArgs = null;
6446    
6447                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6448                                    (orderByComparator == null)) {
6449                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6450                            finderArgs = new Object[] { companyId, status };
6451                    }
6452                    else {
6453                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6454                            finderArgs = new Object[] {
6455                                            companyId, status,
6456                                            
6457                                            start, end, orderByComparator
6458                                    };
6459                    }
6460    
6461                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6462                                    finderArgs, this);
6463    
6464                    if ((list != null) && !list.isEmpty()) {
6465                            for (MBMessage mbMessage : list) {
6466                                    if ((companyId != mbMessage.getCompanyId()) ||
6467                                                    (status != mbMessage.getStatus())) {
6468                                            list = null;
6469    
6470                                            break;
6471                                    }
6472                            }
6473                    }
6474    
6475                    if (list == null) {
6476                            StringBundler query = null;
6477    
6478                            if (orderByComparator != null) {
6479                                    query = new StringBundler(4 +
6480                                                    (orderByComparator.getOrderByFields().length * 3));
6481                            }
6482                            else {
6483                                    query = new StringBundler(4);
6484                            }
6485    
6486                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6487    
6488                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6489    
6490                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6491    
6492                            if (orderByComparator != null) {
6493                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6494                                            orderByComparator);
6495                            }
6496    
6497                            else {
6498                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6499                            }
6500    
6501                            String sql = query.toString();
6502    
6503                            Session session = null;
6504    
6505                            try {
6506                                    session = openSession();
6507    
6508                                    Query q = session.createQuery(sql);
6509    
6510                                    QueryPos qPos = QueryPos.getInstance(q);
6511    
6512                                    qPos.add(companyId);
6513    
6514                                    qPos.add(status);
6515    
6516                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6517                                                    end);
6518                            }
6519                            catch (Exception e) {
6520                                    throw processException(e);
6521                            }
6522                            finally {
6523                                    if (list == null) {
6524                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6525                                    }
6526                                    else {
6527                                            cacheResult(list);
6528    
6529                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6530                                    }
6531    
6532                                    closeSession(session);
6533                            }
6534                    }
6535    
6536                    return list;
6537            }
6538    
6539            /**
6540             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6541             *
6542             * <p>
6543             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6544             * </p>
6545             *
6546             * @param companyId the company ID
6547             * @param status the status
6548             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6549             * @return the first matching message-boards message
6550             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6551             * @throws SystemException if a system exception occurred
6552             */
6553            public MBMessage findByC_S_First(long companyId, int status,
6554                    OrderByComparator orderByComparator)
6555                    throws NoSuchMessageException, SystemException {
6556                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
6557                                    orderByComparator);
6558    
6559                    if (list.isEmpty()) {
6560                            StringBundler msg = new StringBundler(6);
6561    
6562                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6563    
6564                            msg.append("companyId=");
6565                            msg.append(companyId);
6566    
6567                            msg.append(", status=");
6568                            msg.append(status);
6569    
6570                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6571    
6572                            throw new NoSuchMessageException(msg.toString());
6573                    }
6574                    else {
6575                            return list.get(0);
6576                    }
6577            }
6578    
6579            /**
6580             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6581             *
6582             * <p>
6583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6584             * </p>
6585             *
6586             * @param companyId the company ID
6587             * @param status the status
6588             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6589             * @return the last matching message-boards message
6590             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6591             * @throws SystemException if a system exception occurred
6592             */
6593            public MBMessage findByC_S_Last(long companyId, int status,
6594                    OrderByComparator orderByComparator)
6595                    throws NoSuchMessageException, SystemException {
6596                    int count = countByC_S(companyId, status);
6597    
6598                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
6599                                    orderByComparator);
6600    
6601                    if (list.isEmpty()) {
6602                            StringBundler msg = new StringBundler(6);
6603    
6604                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6605    
6606                            msg.append("companyId=");
6607                            msg.append(companyId);
6608    
6609                            msg.append(", status=");
6610                            msg.append(status);
6611    
6612                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6613    
6614                            throw new NoSuchMessageException(msg.toString());
6615                    }
6616                    else {
6617                            return list.get(0);
6618                    }
6619            }
6620    
6621            /**
6622             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6623             *
6624             * <p>
6625             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6626             * </p>
6627             *
6628             * @param messageId the primary key of the current message-boards message
6629             * @param companyId the company ID
6630             * @param status the status
6631             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6632             * @return the previous, current, and next message-boards message
6633             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6634             * @throws SystemException if a system exception occurred
6635             */
6636            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
6637                    int status, OrderByComparator orderByComparator)
6638                    throws NoSuchMessageException, SystemException {
6639                    MBMessage mbMessage = findByPrimaryKey(messageId);
6640    
6641                    Session session = null;
6642    
6643                    try {
6644                            session = openSession();
6645    
6646                            MBMessage[] array = new MBMessageImpl[3];
6647    
6648                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6649                                            status, orderByComparator, true);
6650    
6651                            array[1] = mbMessage;
6652    
6653                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6654                                            status, orderByComparator, false);
6655    
6656                            return array;
6657                    }
6658                    catch (Exception e) {
6659                            throw processException(e);
6660                    }
6661                    finally {
6662                            closeSession(session);
6663                    }
6664            }
6665    
6666            protected MBMessage getByC_S_PrevAndNext(Session session,
6667                    MBMessage mbMessage, long companyId, int status,
6668                    OrderByComparator orderByComparator, boolean previous) {
6669                    StringBundler query = null;
6670    
6671                    if (orderByComparator != null) {
6672                            query = new StringBundler(6 +
6673                                            (orderByComparator.getOrderByFields().length * 6));
6674                    }
6675                    else {
6676                            query = new StringBundler(3);
6677                    }
6678    
6679                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6680    
6681                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6682    
6683                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
6684    
6685                    if (orderByComparator != null) {
6686                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6687    
6688                            if (orderByConditionFields.length > 0) {
6689                                    query.append(WHERE_AND);
6690                            }
6691    
6692                            for (int i = 0; i < orderByConditionFields.length; i++) {
6693                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6694                                    query.append(orderByConditionFields[i]);
6695    
6696                                    if ((i + 1) < orderByConditionFields.length) {
6697                                            if (orderByComparator.isAscending() ^ previous) {
6698                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6699                                            }
6700                                            else {
6701                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6702                                            }
6703                                    }
6704                                    else {
6705                                            if (orderByComparator.isAscending() ^ previous) {
6706                                                    query.append(WHERE_GREATER_THAN);
6707                                            }
6708                                            else {
6709                                                    query.append(WHERE_LESSER_THAN);
6710                                            }
6711                                    }
6712                            }
6713    
6714                            query.append(ORDER_BY_CLAUSE);
6715    
6716                            String[] orderByFields = orderByComparator.getOrderByFields();
6717    
6718                            for (int i = 0; i < orderByFields.length; i++) {
6719                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6720                                    query.append(orderByFields[i]);
6721    
6722                                    if ((i + 1) < orderByFields.length) {
6723                                            if (orderByComparator.isAscending() ^ previous) {
6724                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6725                                            }
6726                                            else {
6727                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6728                                            }
6729                                    }
6730                                    else {
6731                                            if (orderByComparator.isAscending() ^ previous) {
6732                                                    query.append(ORDER_BY_ASC);
6733                                            }
6734                                            else {
6735                                                    query.append(ORDER_BY_DESC);
6736                                            }
6737                                    }
6738                            }
6739                    }
6740    
6741                    else {
6742                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6743                    }
6744    
6745                    String sql = query.toString();
6746    
6747                    Query q = session.createQuery(sql);
6748    
6749                    q.setFirstResult(0);
6750                    q.setMaxResults(2);
6751    
6752                    QueryPos qPos = QueryPos.getInstance(q);
6753    
6754                    qPos.add(companyId);
6755    
6756                    qPos.add(status);
6757    
6758                    if (orderByComparator != null) {
6759                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6760    
6761                            for (Object value : values) {
6762                                    qPos.add(value);
6763                            }
6764                    }
6765    
6766                    List<MBMessage> list = q.list();
6767    
6768                    if (list.size() == 2) {
6769                            return list.get(1);
6770                    }
6771                    else {
6772                            return null;
6773                    }
6774            }
6775    
6776            /**
6777             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
6778             *
6779             * @param userId the user ID
6780             * @param classNameId the class name ID
6781             * @return the matching message-boards messages
6782             * @throws SystemException if a system exception occurred
6783             */
6784            public List<MBMessage> findByU_C(long userId, long classNameId)
6785                    throws SystemException {
6786                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
6787                            QueryUtil.ALL_POS, null);
6788            }
6789    
6790            /**
6791             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
6792             *
6793             * <p>
6794             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6795             * </p>
6796             *
6797             * @param userId the user ID
6798             * @param classNameId the class name ID
6799             * @param start the lower bound of the range of message-boards messages
6800             * @param end the upper bound of the range of message-boards messages (not inclusive)
6801             * @return the range of matching message-boards messages
6802             * @throws SystemException if a system exception occurred
6803             */
6804            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
6805                    int end) throws SystemException {
6806                    return findByU_C(userId, classNameId, start, end, null);
6807            }
6808    
6809            /**
6810             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
6811             *
6812             * <p>
6813             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6814             * </p>
6815             *
6816             * @param userId the user ID
6817             * @param classNameId the class name ID
6818             * @param start the lower bound of the range of message-boards messages
6819             * @param end the upper bound of the range of message-boards messages (not inclusive)
6820             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6821             * @return the ordered range of matching message-boards messages
6822             * @throws SystemException if a system exception occurred
6823             */
6824            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
6825                    int end, OrderByComparator orderByComparator) throws SystemException {
6826                    FinderPath finderPath = null;
6827                    Object[] finderArgs = null;
6828    
6829                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6830                                    (orderByComparator == null)) {
6831                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
6832                            finderArgs = new Object[] { userId, classNameId };
6833                    }
6834                    else {
6835                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
6836                            finderArgs = new Object[] {
6837                                            userId, classNameId,
6838                                            
6839                                            start, end, orderByComparator
6840                                    };
6841                    }
6842    
6843                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6844                                    finderArgs, this);
6845    
6846                    if ((list != null) && !list.isEmpty()) {
6847                            for (MBMessage mbMessage : list) {
6848                                    if ((userId != mbMessage.getUserId()) ||
6849                                                    (classNameId != mbMessage.getClassNameId())) {
6850                                            list = null;
6851    
6852                                            break;
6853                                    }
6854                            }
6855                    }
6856    
6857                    if (list == null) {
6858                            StringBundler query = null;
6859    
6860                            if (orderByComparator != null) {
6861                                    query = new StringBundler(4 +
6862                                                    (orderByComparator.getOrderByFields().length * 3));
6863                            }
6864                            else {
6865                                    query = new StringBundler(4);
6866                            }
6867    
6868                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6869    
6870                            query.append(_FINDER_COLUMN_U_C_USERID_2);
6871    
6872                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
6873    
6874                            if (orderByComparator != null) {
6875                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6876                                            orderByComparator);
6877                            }
6878    
6879                            else {
6880                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6881                            }
6882    
6883                            String sql = query.toString();
6884    
6885                            Session session = null;
6886    
6887                            try {
6888                                    session = openSession();
6889    
6890                                    Query q = session.createQuery(sql);
6891    
6892                                    QueryPos qPos = QueryPos.getInstance(q);
6893    
6894                                    qPos.add(userId);
6895    
6896                                    qPos.add(classNameId);
6897    
6898                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6899                                                    end);
6900                            }
6901                            catch (Exception e) {
6902                                    throw processException(e);
6903                            }
6904                            finally {
6905                                    if (list == null) {
6906                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6907                                    }
6908                                    else {
6909                                            cacheResult(list);
6910    
6911                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6912                                    }
6913    
6914                                    closeSession(session);
6915                            }
6916                    }
6917    
6918                    return list;
6919            }
6920    
6921            /**
6922             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
6923             *
6924             * <p>
6925             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6926             * </p>
6927             *
6928             * @param userId the user ID
6929             * @param classNameId the class name ID
6930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6931             * @return the first matching message-boards message
6932             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6933             * @throws SystemException if a system exception occurred
6934             */
6935            public MBMessage findByU_C_First(long userId, long classNameId,
6936                    OrderByComparator orderByComparator)
6937                    throws NoSuchMessageException, SystemException {
6938                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
6939                                    orderByComparator);
6940    
6941                    if (list.isEmpty()) {
6942                            StringBundler msg = new StringBundler(6);
6943    
6944                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6945    
6946                            msg.append("userId=");
6947                            msg.append(userId);
6948    
6949                            msg.append(", classNameId=");
6950                            msg.append(classNameId);
6951    
6952                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6953    
6954                            throw new NoSuchMessageException(msg.toString());
6955                    }
6956                    else {
6957                            return list.get(0);
6958                    }
6959            }
6960    
6961            /**
6962             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
6963             *
6964             * <p>
6965             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6966             * </p>
6967             *
6968             * @param userId the user ID
6969             * @param classNameId the class name ID
6970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6971             * @return the last matching message-boards message
6972             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6973             * @throws SystemException if a system exception occurred
6974             */
6975            public MBMessage findByU_C_Last(long userId, long classNameId,
6976                    OrderByComparator orderByComparator)
6977                    throws NoSuchMessageException, SystemException {
6978                    int count = countByU_C(userId, classNameId);
6979    
6980                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
6981                                    orderByComparator);
6982    
6983                    if (list.isEmpty()) {
6984                            StringBundler msg = new StringBundler(6);
6985    
6986                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6987    
6988                            msg.append("userId=");
6989                            msg.append(userId);
6990    
6991                            msg.append(", classNameId=");
6992                            msg.append(classNameId);
6993    
6994                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6995    
6996                            throw new NoSuchMessageException(msg.toString());
6997                    }
6998                    else {
6999                            return list.get(0);
7000                    }
7001            }
7002    
7003            /**
7004             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7005             *
7006             * <p>
7007             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7008             * </p>
7009             *
7010             * @param messageId the primary key of the current message-boards message
7011             * @param userId the user ID
7012             * @param classNameId the class name ID
7013             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7014             * @return the previous, current, and next message-boards message
7015             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7016             * @throws SystemException if a system exception occurred
7017             */
7018            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7019                    long classNameId, OrderByComparator orderByComparator)
7020                    throws NoSuchMessageException, SystemException {
7021                    MBMessage mbMessage = findByPrimaryKey(messageId);
7022    
7023                    Session session = null;
7024    
7025                    try {
7026                            session = openSession();
7027    
7028                            MBMessage[] array = new MBMessageImpl[3];
7029    
7030                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7031                                            classNameId, orderByComparator, true);
7032    
7033                            array[1] = mbMessage;
7034    
7035                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7036                                            classNameId, orderByComparator, false);
7037    
7038                            return array;
7039                    }
7040                    catch (Exception e) {
7041                            throw processException(e);
7042                    }
7043                    finally {
7044                            closeSession(session);
7045                    }
7046            }
7047    
7048            protected MBMessage getByU_C_PrevAndNext(Session session,
7049                    MBMessage mbMessage, long userId, long classNameId,
7050                    OrderByComparator orderByComparator, boolean previous) {
7051                    StringBundler query = null;
7052    
7053                    if (orderByComparator != null) {
7054                            query = new StringBundler(6 +
7055                                            (orderByComparator.getOrderByFields().length * 6));
7056                    }
7057                    else {
7058                            query = new StringBundler(3);
7059                    }
7060    
7061                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7062    
7063                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7064    
7065                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7066    
7067                    if (orderByComparator != null) {
7068                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7069    
7070                            if (orderByConditionFields.length > 0) {
7071                                    query.append(WHERE_AND);
7072                            }
7073    
7074                            for (int i = 0; i < orderByConditionFields.length; i++) {
7075                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7076                                    query.append(orderByConditionFields[i]);
7077    
7078                                    if ((i + 1) < orderByConditionFields.length) {
7079                                            if (orderByComparator.isAscending() ^ previous) {
7080                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7081                                            }
7082                                            else {
7083                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7084                                            }
7085                                    }
7086                                    else {
7087                                            if (orderByComparator.isAscending() ^ previous) {
7088                                                    query.append(WHERE_GREATER_THAN);
7089                                            }
7090                                            else {
7091                                                    query.append(WHERE_LESSER_THAN);
7092                                            }
7093                                    }
7094                            }
7095    
7096                            query.append(ORDER_BY_CLAUSE);
7097    
7098                            String[] orderByFields = orderByComparator.getOrderByFields();
7099    
7100                            for (int i = 0; i < orderByFields.length; i++) {
7101                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7102                                    query.append(orderByFields[i]);
7103    
7104                                    if ((i + 1) < orderByFields.length) {
7105                                            if (orderByComparator.isAscending() ^ previous) {
7106                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7107                                            }
7108                                            else {
7109                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7110                                            }
7111                                    }
7112                                    else {
7113                                            if (orderByComparator.isAscending() ^ previous) {
7114                                                    query.append(ORDER_BY_ASC);
7115                                            }
7116                                            else {
7117                                                    query.append(ORDER_BY_DESC);
7118                                            }
7119                                    }
7120                            }
7121                    }
7122    
7123                    else {
7124                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7125                    }
7126    
7127                    String sql = query.toString();
7128    
7129                    Query q = session.createQuery(sql);
7130    
7131                    q.setFirstResult(0);
7132                    q.setMaxResults(2);
7133    
7134                    QueryPos qPos = QueryPos.getInstance(q);
7135    
7136                    qPos.add(userId);
7137    
7138                    qPos.add(classNameId);
7139    
7140                    if (orderByComparator != null) {
7141                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7142    
7143                            for (Object value : values) {
7144                                    qPos.add(value);
7145                            }
7146                    }
7147    
7148                    List<MBMessage> list = q.list();
7149    
7150                    if (list.size() == 2) {
7151                            return list.get(1);
7152                    }
7153                    else {
7154                            return null;
7155                    }
7156            }
7157    
7158            /**
7159             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7160             *
7161             * <p>
7162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7163             * </p>
7164             *
7165             * @param userId the user ID
7166             * @param classNameIds the class name IDs
7167             * @return the matching message-boards messages
7168             * @throws SystemException if a system exception occurred
7169             */
7170            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7171                    throws SystemException {
7172                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7173                            QueryUtil.ALL_POS, null);
7174            }
7175    
7176            /**
7177             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7178             *
7179             * <p>
7180             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7181             * </p>
7182             *
7183             * @param userId the user ID
7184             * @param classNameIds the class name IDs
7185             * @param start the lower bound of the range of message-boards messages
7186             * @param end the upper bound of the range of message-boards messages (not inclusive)
7187             * @return the range of matching message-boards messages
7188             * @throws SystemException if a system exception occurred
7189             */
7190            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7191                    int start, int end) throws SystemException {
7192                    return findByU_C(userId, classNameIds, start, end, null);
7193            }
7194    
7195            /**
7196             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7197             *
7198             * <p>
7199             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7200             * </p>
7201             *
7202             * @param userId the user ID
7203             * @param classNameIds the class name IDs
7204             * @param start the lower bound of the range of message-boards messages
7205             * @param end the upper bound of the range of message-boards messages (not inclusive)
7206             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7207             * @return the ordered range of matching message-boards messages
7208             * @throws SystemException if a system exception occurred
7209             */
7210            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7211                    int start, int end, OrderByComparator orderByComparator)
7212                    throws SystemException {
7213                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7214                    Object[] finderArgs = null;
7215    
7216                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7217                                    (orderByComparator == null)) {
7218                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7219                    }
7220                    else {
7221                            finderArgs = new Object[] {
7222                                            userId, StringUtil.merge(classNameIds),
7223                                            
7224                                            start, end, orderByComparator
7225                                    };
7226                    }
7227    
7228                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7229                                    finderArgs, this);
7230    
7231                    if ((list != null) && !list.isEmpty()) {
7232                            for (MBMessage mbMessage : list) {
7233                                    if ((userId != mbMessage.getUserId()) ||
7234                                                    !ArrayUtil.contains(classNameIds,
7235                                                            mbMessage.getClassNameId())) {
7236                                            list = null;
7237    
7238                                            break;
7239                                    }
7240                            }
7241                    }
7242    
7243                    if (list == null) {
7244                            StringBundler query = new StringBundler();
7245    
7246                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7247    
7248                            boolean conjunctionable = false;
7249    
7250                            if (conjunctionable) {
7251                                    query.append(WHERE_AND);
7252                            }
7253    
7254                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7255    
7256                            conjunctionable = true;
7257    
7258                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7259                                    if (conjunctionable) {
7260                                            query.append(WHERE_AND);
7261                                    }
7262    
7263                                    query.append(StringPool.OPEN_PARENTHESIS);
7264    
7265                                    for (int i = 0; i < classNameIds.length; i++) {
7266                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7267    
7268                                            if ((i + 1) < classNameIds.length) {
7269                                                    query.append(WHERE_OR);
7270                                            }
7271                                    }
7272    
7273                                    query.append(StringPool.CLOSE_PARENTHESIS);
7274    
7275                                    conjunctionable = true;
7276                            }
7277    
7278                            if (orderByComparator != null) {
7279                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7280                                            orderByComparator);
7281                            }
7282    
7283                            else {
7284                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7285                            }
7286    
7287                            String sql = query.toString();
7288    
7289                            Session session = null;
7290    
7291                            try {
7292                                    session = openSession();
7293    
7294                                    Query q = session.createQuery(sql);
7295    
7296                                    QueryPos qPos = QueryPos.getInstance(q);
7297    
7298                                    qPos.add(userId);
7299    
7300                                    if (classNameIds != null) {
7301                                            qPos.add(classNameIds);
7302                                    }
7303    
7304                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7305                                                    end);
7306                            }
7307                            catch (Exception e) {
7308                                    throw processException(e);
7309                            }
7310                            finally {
7311                                    if (list == null) {
7312                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7313                                    }
7314                                    else {
7315                                            cacheResult(list);
7316    
7317                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7318                                    }
7319    
7320                                    closeSession(session);
7321                            }
7322                    }
7323    
7324                    return list;
7325            }
7326    
7327            /**
7328             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7329             *
7330             * @param classNameId the class name ID
7331             * @param classPK the class p k
7332             * @return the matching message-boards messages
7333             * @throws SystemException if a system exception occurred
7334             */
7335            public List<MBMessage> findByC_C(long classNameId, long classPK)
7336                    throws SystemException {
7337                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
7338                            QueryUtil.ALL_POS, null);
7339            }
7340    
7341            /**
7342             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7343             *
7344             * <p>
7345             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7346             * </p>
7347             *
7348             * @param classNameId the class name ID
7349             * @param classPK the class p k
7350             * @param start the lower bound of the range of message-boards messages
7351             * @param end the upper bound of the range of message-boards messages (not inclusive)
7352             * @return the range of matching message-boards messages
7353             * @throws SystemException if a system exception occurred
7354             */
7355            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7356                    int end) throws SystemException {
7357                    return findByC_C(classNameId, classPK, start, end, null);
7358            }
7359    
7360            /**
7361             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7362             *
7363             * <p>
7364             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7365             * </p>
7366             *
7367             * @param classNameId the class name ID
7368             * @param classPK the class p k
7369             * @param start the lower bound of the range of message-boards messages
7370             * @param end the upper bound of the range of message-boards messages (not inclusive)
7371             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7372             * @return the ordered range of matching message-boards messages
7373             * @throws SystemException if a system exception occurred
7374             */
7375            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7376                    int end, OrderByComparator orderByComparator) throws SystemException {
7377                    FinderPath finderPath = null;
7378                    Object[] finderArgs = null;
7379    
7380                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7381                                    (orderByComparator == null)) {
7382                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
7383                            finderArgs = new Object[] { classNameId, classPK };
7384                    }
7385                    else {
7386                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
7387                            finderArgs = new Object[] {
7388                                            classNameId, classPK,
7389                                            
7390                                            start, end, orderByComparator
7391                                    };
7392                    }
7393    
7394                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7395                                    finderArgs, this);
7396    
7397                    if ((list != null) && !list.isEmpty()) {
7398                            for (MBMessage mbMessage : list) {
7399                                    if ((classNameId != mbMessage.getClassNameId()) ||
7400                                                    (classPK != mbMessage.getClassPK())) {
7401                                            list = null;
7402    
7403                                            break;
7404                                    }
7405                            }
7406                    }
7407    
7408                    if (list == null) {
7409                            StringBundler query = null;
7410    
7411                            if (orderByComparator != null) {
7412                                    query = new StringBundler(4 +
7413                                                    (orderByComparator.getOrderByFields().length * 3));
7414                            }
7415                            else {
7416                                    query = new StringBundler(4);
7417                            }
7418    
7419                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7420    
7421                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7422    
7423                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7424    
7425                            if (orderByComparator != null) {
7426                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7427                                            orderByComparator);
7428                            }
7429    
7430                            else {
7431                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7432                            }
7433    
7434                            String sql = query.toString();
7435    
7436                            Session session = null;
7437    
7438                            try {
7439                                    session = openSession();
7440    
7441                                    Query q = session.createQuery(sql);
7442    
7443                                    QueryPos qPos = QueryPos.getInstance(q);
7444    
7445                                    qPos.add(classNameId);
7446    
7447                                    qPos.add(classPK);
7448    
7449                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7450                                                    end);
7451                            }
7452                            catch (Exception e) {
7453                                    throw processException(e);
7454                            }
7455                            finally {
7456                                    if (list == null) {
7457                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7458                                    }
7459                                    else {
7460                                            cacheResult(list);
7461    
7462                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7463                                    }
7464    
7465                                    closeSession(session);
7466                            }
7467                    }
7468    
7469                    return list;
7470            }
7471    
7472            /**
7473             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7474             *
7475             * <p>
7476             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7477             * </p>
7478             *
7479             * @param classNameId the class name ID
7480             * @param classPK the class p k
7481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7482             * @return the first matching message-boards message
7483             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7484             * @throws SystemException if a system exception occurred
7485             */
7486            public MBMessage findByC_C_First(long classNameId, long classPK,
7487                    OrderByComparator orderByComparator)
7488                    throws NoSuchMessageException, SystemException {
7489                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
7490                                    orderByComparator);
7491    
7492                    if (list.isEmpty()) {
7493                            StringBundler msg = new StringBundler(6);
7494    
7495                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7496    
7497                            msg.append("classNameId=");
7498                            msg.append(classNameId);
7499    
7500                            msg.append(", classPK=");
7501                            msg.append(classPK);
7502    
7503                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7504    
7505                            throw new NoSuchMessageException(msg.toString());
7506                    }
7507                    else {
7508                            return list.get(0);
7509                    }
7510            }
7511    
7512            /**
7513             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7514             *
7515             * <p>
7516             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7517             * </p>
7518             *
7519             * @param classNameId the class name ID
7520             * @param classPK the class p k
7521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7522             * @return the last matching message-boards message
7523             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7524             * @throws SystemException if a system exception occurred
7525             */
7526            public MBMessage findByC_C_Last(long classNameId, long classPK,
7527                    OrderByComparator orderByComparator)
7528                    throws NoSuchMessageException, SystemException {
7529                    int count = countByC_C(classNameId, classPK);
7530    
7531                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
7532                                    count, orderByComparator);
7533    
7534                    if (list.isEmpty()) {
7535                            StringBundler msg = new StringBundler(6);
7536    
7537                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7538    
7539                            msg.append("classNameId=");
7540                            msg.append(classNameId);
7541    
7542                            msg.append(", classPK=");
7543                            msg.append(classPK);
7544    
7545                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7546    
7547                            throw new NoSuchMessageException(msg.toString());
7548                    }
7549                    else {
7550                            return list.get(0);
7551                    }
7552            }
7553    
7554            /**
7555             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7556             *
7557             * <p>
7558             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7559             * </p>
7560             *
7561             * @param messageId the primary key of the current message-boards message
7562             * @param classNameId the class name ID
7563             * @param classPK the class p k
7564             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7565             * @return the previous, current, and next message-boards message
7566             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7567             * @throws SystemException if a system exception occurred
7568             */
7569            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
7570                    long classPK, OrderByComparator orderByComparator)
7571                    throws NoSuchMessageException, SystemException {
7572                    MBMessage mbMessage = findByPrimaryKey(messageId);
7573    
7574                    Session session = null;
7575    
7576                    try {
7577                            session = openSession();
7578    
7579                            MBMessage[] array = new MBMessageImpl[3];
7580    
7581                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7582                                            classPK, orderByComparator, true);
7583    
7584                            array[1] = mbMessage;
7585    
7586                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7587                                            classPK, orderByComparator, false);
7588    
7589                            return array;
7590                    }
7591                    catch (Exception e) {
7592                            throw processException(e);
7593                    }
7594                    finally {
7595                            closeSession(session);
7596                    }
7597            }
7598    
7599            protected MBMessage getByC_C_PrevAndNext(Session session,
7600                    MBMessage mbMessage, long classNameId, long classPK,
7601                    OrderByComparator orderByComparator, boolean previous) {
7602                    StringBundler query = null;
7603    
7604                    if (orderByComparator != null) {
7605                            query = new StringBundler(6 +
7606                                            (orderByComparator.getOrderByFields().length * 6));
7607                    }
7608                    else {
7609                            query = new StringBundler(3);
7610                    }
7611    
7612                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7613    
7614                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7615    
7616                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7617    
7618                    if (orderByComparator != null) {
7619                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7620    
7621                            if (orderByConditionFields.length > 0) {
7622                                    query.append(WHERE_AND);
7623                            }
7624    
7625                            for (int i = 0; i < orderByConditionFields.length; i++) {
7626                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7627                                    query.append(orderByConditionFields[i]);
7628    
7629                                    if ((i + 1) < orderByConditionFields.length) {
7630                                            if (orderByComparator.isAscending() ^ previous) {
7631                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7632                                            }
7633                                            else {
7634                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7635                                            }
7636                                    }
7637                                    else {
7638                                            if (orderByComparator.isAscending() ^ previous) {
7639                                                    query.append(WHERE_GREATER_THAN);
7640                                            }
7641                                            else {
7642                                                    query.append(WHERE_LESSER_THAN);
7643                                            }
7644                                    }
7645                            }
7646    
7647                            query.append(ORDER_BY_CLAUSE);
7648    
7649                            String[] orderByFields = orderByComparator.getOrderByFields();
7650    
7651                            for (int i = 0; i < orderByFields.length; i++) {
7652                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7653                                    query.append(orderByFields[i]);
7654    
7655                                    if ((i + 1) < orderByFields.length) {
7656                                            if (orderByComparator.isAscending() ^ previous) {
7657                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7658                                            }
7659                                            else {
7660                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7661                                            }
7662                                    }
7663                                    else {
7664                                            if (orderByComparator.isAscending() ^ previous) {
7665                                                    query.append(ORDER_BY_ASC);
7666                                            }
7667                                            else {
7668                                                    query.append(ORDER_BY_DESC);
7669                                            }
7670                                    }
7671                            }
7672                    }
7673    
7674                    else {
7675                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7676                    }
7677    
7678                    String sql = query.toString();
7679    
7680                    Query q = session.createQuery(sql);
7681    
7682                    q.setFirstResult(0);
7683                    q.setMaxResults(2);
7684    
7685                    QueryPos qPos = QueryPos.getInstance(q);
7686    
7687                    qPos.add(classNameId);
7688    
7689                    qPos.add(classPK);
7690    
7691                    if (orderByComparator != null) {
7692                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7693    
7694                            for (Object value : values) {
7695                                    qPos.add(value);
7696                            }
7697                    }
7698    
7699                    List<MBMessage> list = q.list();
7700    
7701                    if (list.size() == 2) {
7702                            return list.get(1);
7703                    }
7704                    else {
7705                            return null;
7706                    }
7707            }
7708    
7709            /**
7710             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
7711             *
7712             * @param threadId the thread ID
7713             * @param parentMessageId the parent message ID
7714             * @return the matching message-boards messages
7715             * @throws SystemException if a system exception occurred
7716             */
7717            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
7718                    throws SystemException {
7719                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
7720                            QueryUtil.ALL_POS, null);
7721            }
7722    
7723            /**
7724             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
7725             *
7726             * <p>
7727             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7728             * </p>
7729             *
7730             * @param threadId the thread ID
7731             * @param parentMessageId the parent message ID
7732             * @param start the lower bound of the range of message-boards messages
7733             * @param end the upper bound of the range of message-boards messages (not inclusive)
7734             * @return the range of matching message-boards messages
7735             * @throws SystemException if a system exception occurred
7736             */
7737            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
7738                    int start, int end) throws SystemException {
7739                    return findByT_P(threadId, parentMessageId, start, end, null);
7740            }
7741    
7742            /**
7743             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
7744             *
7745             * <p>
7746             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7747             * </p>
7748             *
7749             * @param threadId the thread ID
7750             * @param parentMessageId the parent message ID
7751             * @param start the lower bound of the range of message-boards messages
7752             * @param end the upper bound of the range of message-boards messages (not inclusive)
7753             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7754             * @return the ordered range of matching message-boards messages
7755             * @throws SystemException if a system exception occurred
7756             */
7757            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
7758                    int start, int end, OrderByComparator orderByComparator)
7759                    throws SystemException {
7760                    FinderPath finderPath = null;
7761                    Object[] finderArgs = null;
7762    
7763                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7764                                    (orderByComparator == null)) {
7765                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
7766                            finderArgs = new Object[] { threadId, parentMessageId };
7767                    }
7768                    else {
7769                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
7770                            finderArgs = new Object[] {
7771                                            threadId, parentMessageId,
7772                                            
7773                                            start, end, orderByComparator
7774                                    };
7775                    }
7776    
7777                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7778                                    finderArgs, this);
7779    
7780                    if ((list != null) && !list.isEmpty()) {
7781                            for (MBMessage mbMessage : list) {
7782                                    if ((threadId != mbMessage.getThreadId()) ||
7783                                                    (parentMessageId != mbMessage.getParentMessageId())) {
7784                                            list = null;
7785    
7786                                            break;
7787                                    }
7788                            }
7789                    }
7790    
7791                    if (list == null) {
7792                            StringBundler query = null;
7793    
7794                            if (orderByComparator != null) {
7795                                    query = new StringBundler(4 +
7796                                                    (orderByComparator.getOrderByFields().length * 3));
7797                            }
7798                            else {
7799                                    query = new StringBundler(4);
7800                            }
7801    
7802                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7803    
7804                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
7805    
7806                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
7807    
7808                            if (orderByComparator != null) {
7809                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7810                                            orderByComparator);
7811                            }
7812    
7813                            else {
7814                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7815                            }
7816    
7817                            String sql = query.toString();
7818    
7819                            Session session = null;
7820    
7821                            try {
7822                                    session = openSession();
7823    
7824                                    Query q = session.createQuery(sql);
7825    
7826                                    QueryPos qPos = QueryPos.getInstance(q);
7827    
7828                                    qPos.add(threadId);
7829    
7830                                    qPos.add(parentMessageId);
7831    
7832                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7833                                                    end);
7834                            }
7835                            catch (Exception e) {
7836                                    throw processException(e);
7837                            }
7838                            finally {
7839                                    if (list == null) {
7840                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7841                                    }
7842                                    else {
7843                                            cacheResult(list);
7844    
7845                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7846                                    }
7847    
7848                                    closeSession(session);
7849                            }
7850                    }
7851    
7852                    return list;
7853            }
7854    
7855            /**
7856             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
7857             *
7858             * <p>
7859             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7860             * </p>
7861             *
7862             * @param threadId the thread ID
7863             * @param parentMessageId the parent message ID
7864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7865             * @return the first matching message-boards message
7866             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7867             * @throws SystemException if a system exception occurred
7868             */
7869            public MBMessage findByT_P_First(long threadId, long parentMessageId,
7870                    OrderByComparator orderByComparator)
7871                    throws NoSuchMessageException, SystemException {
7872                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
7873                                    orderByComparator);
7874    
7875                    if (list.isEmpty()) {
7876                            StringBundler msg = new StringBundler(6);
7877    
7878                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7879    
7880                            msg.append("threadId=");
7881                            msg.append(threadId);
7882    
7883                            msg.append(", parentMessageId=");
7884                            msg.append(parentMessageId);
7885    
7886                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7887    
7888                            throw new NoSuchMessageException(msg.toString());
7889                    }
7890                    else {
7891                            return list.get(0);
7892                    }
7893            }
7894    
7895            /**
7896             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
7897             *
7898             * <p>
7899             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7900             * </p>
7901             *
7902             * @param threadId the thread ID
7903             * @param parentMessageId the parent message ID
7904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7905             * @return the last matching message-boards message
7906             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7907             * @throws SystemException if a system exception occurred
7908             */
7909            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
7910                    OrderByComparator orderByComparator)
7911                    throws NoSuchMessageException, SystemException {
7912                    int count = countByT_P(threadId, parentMessageId);
7913    
7914                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
7915                                    count, orderByComparator);
7916    
7917                    if (list.isEmpty()) {
7918                            StringBundler msg = new StringBundler(6);
7919    
7920                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7921    
7922                            msg.append("threadId=");
7923                            msg.append(threadId);
7924    
7925                            msg.append(", parentMessageId=");
7926                            msg.append(parentMessageId);
7927    
7928                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7929    
7930                            throw new NoSuchMessageException(msg.toString());
7931                    }
7932                    else {
7933                            return list.get(0);
7934                    }
7935            }
7936    
7937            /**
7938             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
7939             *
7940             * <p>
7941             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7942             * </p>
7943             *
7944             * @param messageId the primary key of the current message-boards message
7945             * @param threadId the thread ID
7946             * @param parentMessageId the parent message ID
7947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7948             * @return the previous, current, and next message-boards message
7949             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7950             * @throws SystemException if a system exception occurred
7951             */
7952            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
7953                    long parentMessageId, OrderByComparator orderByComparator)
7954                    throws NoSuchMessageException, SystemException {
7955                    MBMessage mbMessage = findByPrimaryKey(messageId);
7956    
7957                    Session session = null;
7958    
7959                    try {
7960                            session = openSession();
7961    
7962                            MBMessage[] array = new MBMessageImpl[3];
7963    
7964                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
7965                                            parentMessageId, orderByComparator, true);
7966    
7967                            array[1] = mbMessage;
7968    
7969                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
7970                                            parentMessageId, orderByComparator, false);
7971    
7972                            return array;
7973                    }
7974                    catch (Exception e) {
7975                            throw processException(e);
7976                    }
7977                    finally {
7978                            closeSession(session);
7979                    }
7980            }
7981    
7982            protected MBMessage getByT_P_PrevAndNext(Session session,
7983                    MBMessage mbMessage, long threadId, long parentMessageId,
7984                    OrderByComparator orderByComparator, boolean previous) {
7985                    StringBundler query = null;
7986    
7987                    if (orderByComparator != null) {
7988                            query = new StringBundler(6 +
7989                                            (orderByComparator.getOrderByFields().length * 6));
7990                    }
7991                    else {
7992                            query = new StringBundler(3);
7993                    }
7994    
7995                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7996    
7997                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
7998    
7999                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8000    
8001                    if (orderByComparator != null) {
8002                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8003    
8004                            if (orderByConditionFields.length > 0) {
8005                                    query.append(WHERE_AND);
8006                            }
8007    
8008                            for (int i = 0; i < orderByConditionFields.length; i++) {
8009                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8010                                    query.append(orderByConditionFields[i]);
8011    
8012                                    if ((i + 1) < orderByConditionFields.length) {
8013                                            if (orderByComparator.isAscending() ^ previous) {
8014                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8015                                            }
8016                                            else {
8017                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8018                                            }
8019                                    }
8020                                    else {
8021                                            if (orderByComparator.isAscending() ^ previous) {
8022                                                    query.append(WHERE_GREATER_THAN);
8023                                            }
8024                                            else {
8025                                                    query.append(WHERE_LESSER_THAN);
8026                                            }
8027                                    }
8028                            }
8029    
8030                            query.append(ORDER_BY_CLAUSE);
8031    
8032                            String[] orderByFields = orderByComparator.getOrderByFields();
8033    
8034                            for (int i = 0; i < orderByFields.length; i++) {
8035                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8036                                    query.append(orderByFields[i]);
8037    
8038                                    if ((i + 1) < orderByFields.length) {
8039                                            if (orderByComparator.isAscending() ^ previous) {
8040                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8041                                            }
8042                                            else {
8043                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8044                                            }
8045                                    }
8046                                    else {
8047                                            if (orderByComparator.isAscending() ^ previous) {
8048                                                    query.append(ORDER_BY_ASC);
8049                                            }
8050                                            else {
8051                                                    query.append(ORDER_BY_DESC);
8052                                            }
8053                                    }
8054                            }
8055                    }
8056    
8057                    else {
8058                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8059                    }
8060    
8061                    String sql = query.toString();
8062    
8063                    Query q = session.createQuery(sql);
8064    
8065                    q.setFirstResult(0);
8066                    q.setMaxResults(2);
8067    
8068                    QueryPos qPos = QueryPos.getInstance(q);
8069    
8070                    qPos.add(threadId);
8071    
8072                    qPos.add(parentMessageId);
8073    
8074                    if (orderByComparator != null) {
8075                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8076    
8077                            for (Object value : values) {
8078                                    qPos.add(value);
8079                            }
8080                    }
8081    
8082                    List<MBMessage> list = q.list();
8083    
8084                    if (list.size() == 2) {
8085                            return list.get(1);
8086                    }
8087                    else {
8088                            return null;
8089                    }
8090            }
8091    
8092            /**
8093             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
8094             *
8095             * @param threadId the thread ID
8096             * @param answer the answer
8097             * @return the matching message-boards messages
8098             * @throws SystemException if a system exception occurred
8099             */
8100            public List<MBMessage> findByT_A(long threadId, boolean answer)
8101                    throws SystemException {
8102                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
8103                            QueryUtil.ALL_POS, null);
8104            }
8105    
8106            /**
8107             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8108             *
8109             * <p>
8110             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8111             * </p>
8112             *
8113             * @param threadId the thread ID
8114             * @param answer the answer
8115             * @param start the lower bound of the range of message-boards messages
8116             * @param end the upper bound of the range of message-boards messages (not inclusive)
8117             * @return the range of matching message-boards messages
8118             * @throws SystemException if a system exception occurred
8119             */
8120            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8121                    int end) throws SystemException {
8122                    return findByT_A(threadId, answer, start, end, null);
8123            }
8124    
8125            /**
8126             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8127             *
8128             * <p>
8129             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8130             * </p>
8131             *
8132             * @param threadId the thread ID
8133             * @param answer the answer
8134             * @param start the lower bound of the range of message-boards messages
8135             * @param end the upper bound of the range of message-boards messages (not inclusive)
8136             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8137             * @return the ordered range of matching message-boards messages
8138             * @throws SystemException if a system exception occurred
8139             */
8140            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8141                    int end, OrderByComparator orderByComparator) throws SystemException {
8142                    FinderPath finderPath = null;
8143                    Object[] finderArgs = null;
8144    
8145                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8146                                    (orderByComparator == null)) {
8147                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
8148                            finderArgs = new Object[] { threadId, answer };
8149                    }
8150                    else {
8151                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
8152                            finderArgs = new Object[] {
8153                                            threadId, answer,
8154                                            
8155                                            start, end, orderByComparator
8156                                    };
8157                    }
8158    
8159                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8160                                    finderArgs, this);
8161    
8162                    if ((list != null) && !list.isEmpty()) {
8163                            for (MBMessage mbMessage : list) {
8164                                    if ((threadId != mbMessage.getThreadId()) ||
8165                                                    (answer != mbMessage.getAnswer())) {
8166                                            list = null;
8167    
8168                                            break;
8169                                    }
8170                            }
8171                    }
8172    
8173                    if (list == null) {
8174                            StringBundler query = null;
8175    
8176                            if (orderByComparator != null) {
8177                                    query = new StringBundler(4 +
8178                                                    (orderByComparator.getOrderByFields().length * 3));
8179                            }
8180                            else {
8181                                    query = new StringBundler(4);
8182                            }
8183    
8184                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8185    
8186                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
8187    
8188                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8189    
8190                            if (orderByComparator != null) {
8191                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8192                                            orderByComparator);
8193                            }
8194    
8195                            else {
8196                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8197                            }
8198    
8199                            String sql = query.toString();
8200    
8201                            Session session = null;
8202    
8203                            try {
8204                                    session = openSession();
8205    
8206                                    Query q = session.createQuery(sql);
8207    
8208                                    QueryPos qPos = QueryPos.getInstance(q);
8209    
8210                                    qPos.add(threadId);
8211    
8212                                    qPos.add(answer);
8213    
8214                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8215                                                    end);
8216                            }
8217                            catch (Exception e) {
8218                                    throw processException(e);
8219                            }
8220                            finally {
8221                                    if (list == null) {
8222                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8223                                    }
8224                                    else {
8225                                            cacheResult(list);
8226    
8227                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8228                                    }
8229    
8230                                    closeSession(session);
8231                            }
8232                    }
8233    
8234                    return list;
8235            }
8236    
8237            /**
8238             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8239             *
8240             * <p>
8241             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8242             * </p>
8243             *
8244             * @param threadId the thread ID
8245             * @param answer the answer
8246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8247             * @return the first matching message-boards message
8248             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8249             * @throws SystemException if a system exception occurred
8250             */
8251            public MBMessage findByT_A_First(long threadId, boolean answer,
8252                    OrderByComparator orderByComparator)
8253                    throws NoSuchMessageException, SystemException {
8254                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
8255                                    orderByComparator);
8256    
8257                    if (list.isEmpty()) {
8258                            StringBundler msg = new StringBundler(6);
8259    
8260                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8261    
8262                            msg.append("threadId=");
8263                            msg.append(threadId);
8264    
8265                            msg.append(", answer=");
8266                            msg.append(answer);
8267    
8268                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8269    
8270                            throw new NoSuchMessageException(msg.toString());
8271                    }
8272                    else {
8273                            return list.get(0);
8274                    }
8275            }
8276    
8277            /**
8278             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8279             *
8280             * <p>
8281             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8282             * </p>
8283             *
8284             * @param threadId the thread ID
8285             * @param answer the answer
8286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8287             * @return the last matching message-boards message
8288             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8289             * @throws SystemException if a system exception occurred
8290             */
8291            public MBMessage findByT_A_Last(long threadId, boolean answer,
8292                    OrderByComparator orderByComparator)
8293                    throws NoSuchMessageException, SystemException {
8294                    int count = countByT_A(threadId, answer);
8295    
8296                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
8297                                    orderByComparator);
8298    
8299                    if (list.isEmpty()) {
8300                            StringBundler msg = new StringBundler(6);
8301    
8302                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8303    
8304                            msg.append("threadId=");
8305                            msg.append(threadId);
8306    
8307                            msg.append(", answer=");
8308                            msg.append(answer);
8309    
8310                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8311    
8312                            throw new NoSuchMessageException(msg.toString());
8313                    }
8314                    else {
8315                            return list.get(0);
8316                    }
8317            }
8318    
8319            /**
8320             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8321             *
8322             * <p>
8323             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8324             * </p>
8325             *
8326             * @param messageId the primary key of the current message-boards message
8327             * @param threadId the thread ID
8328             * @param answer the answer
8329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8330             * @return the previous, current, and next message-boards message
8331             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8332             * @throws SystemException if a system exception occurred
8333             */
8334            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
8335                    boolean answer, OrderByComparator orderByComparator)
8336                    throws NoSuchMessageException, SystemException {
8337                    MBMessage mbMessage = findByPrimaryKey(messageId);
8338    
8339                    Session session = null;
8340    
8341                    try {
8342                            session = openSession();
8343    
8344                            MBMessage[] array = new MBMessageImpl[3];
8345    
8346                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8347                                            answer, orderByComparator, true);
8348    
8349                            array[1] = mbMessage;
8350    
8351                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8352                                            answer, orderByComparator, false);
8353    
8354                            return array;
8355                    }
8356                    catch (Exception e) {
8357                            throw processException(e);
8358                    }
8359                    finally {
8360                            closeSession(session);
8361                    }
8362            }
8363    
8364            protected MBMessage getByT_A_PrevAndNext(Session session,
8365                    MBMessage mbMessage, long threadId, boolean answer,
8366                    OrderByComparator orderByComparator, boolean previous) {
8367                    StringBundler query = null;
8368    
8369                    if (orderByComparator != null) {
8370                            query = new StringBundler(6 +
8371                                            (orderByComparator.getOrderByFields().length * 6));
8372                    }
8373                    else {
8374                            query = new StringBundler(3);
8375                    }
8376    
8377                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8378    
8379                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
8380    
8381                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8382    
8383                    if (orderByComparator != null) {
8384                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8385    
8386                            if (orderByConditionFields.length > 0) {
8387                                    query.append(WHERE_AND);
8388                            }
8389    
8390                            for (int i = 0; i < orderByConditionFields.length; i++) {
8391                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8392                                    query.append(orderByConditionFields[i]);
8393    
8394                                    if ((i + 1) < orderByConditionFields.length) {
8395                                            if (orderByComparator.isAscending() ^ previous) {
8396                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8397                                            }
8398                                            else {
8399                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8400                                            }
8401                                    }
8402                                    else {
8403                                            if (orderByComparator.isAscending() ^ previous) {
8404                                                    query.append(WHERE_GREATER_THAN);
8405                                            }
8406                                            else {
8407                                                    query.append(WHERE_LESSER_THAN);
8408                                            }
8409                                    }
8410                            }
8411    
8412                            query.append(ORDER_BY_CLAUSE);
8413    
8414                            String[] orderByFields = orderByComparator.getOrderByFields();
8415    
8416                            for (int i = 0; i < orderByFields.length; i++) {
8417                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8418                                    query.append(orderByFields[i]);
8419    
8420                                    if ((i + 1) < orderByFields.length) {
8421                                            if (orderByComparator.isAscending() ^ previous) {
8422                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8423                                            }
8424                                            else {
8425                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8426                                            }
8427                                    }
8428                                    else {
8429                                            if (orderByComparator.isAscending() ^ previous) {
8430                                                    query.append(ORDER_BY_ASC);
8431                                            }
8432                                            else {
8433                                                    query.append(ORDER_BY_DESC);
8434                                            }
8435                                    }
8436                            }
8437                    }
8438    
8439                    else {
8440                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8441                    }
8442    
8443                    String sql = query.toString();
8444    
8445                    Query q = session.createQuery(sql);
8446    
8447                    q.setFirstResult(0);
8448                    q.setMaxResults(2);
8449    
8450                    QueryPos qPos = QueryPos.getInstance(q);
8451    
8452                    qPos.add(threadId);
8453    
8454                    qPos.add(answer);
8455    
8456                    if (orderByComparator != null) {
8457                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8458    
8459                            for (Object value : values) {
8460                                    qPos.add(value);
8461                            }
8462                    }
8463    
8464                    List<MBMessage> list = q.list();
8465    
8466                    if (list.size() == 2) {
8467                            return list.get(1);
8468                    }
8469                    else {
8470                            return null;
8471                    }
8472            }
8473    
8474            /**
8475             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
8476             *
8477             * @param threadId the thread ID
8478             * @param status the status
8479             * @return the matching message-boards messages
8480             * @throws SystemException if a system exception occurred
8481             */
8482            public List<MBMessage> findByT_S(long threadId, int status)
8483                    throws SystemException {
8484                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
8485                            QueryUtil.ALL_POS, null);
8486            }
8487    
8488            /**
8489             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
8490             *
8491             * <p>
8492             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8493             * </p>
8494             *
8495             * @param threadId the thread ID
8496             * @param status the status
8497             * @param start the lower bound of the range of message-boards messages
8498             * @param end the upper bound of the range of message-boards messages (not inclusive)
8499             * @return the range of matching message-boards messages
8500             * @throws SystemException if a system exception occurred
8501             */
8502            public List<MBMessage> findByT_S(long threadId, int status, int start,
8503                    int end) throws SystemException {
8504                    return findByT_S(threadId, status, start, end, null);
8505            }
8506    
8507            /**
8508             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
8509             *
8510             * <p>
8511             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8512             * </p>
8513             *
8514             * @param threadId the thread ID
8515             * @param status the status
8516             * @param start the lower bound of the range of message-boards messages
8517             * @param end the upper bound of the range of message-boards messages (not inclusive)
8518             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8519             * @return the ordered range of matching message-boards messages
8520             * @throws SystemException if a system exception occurred
8521             */
8522            public List<MBMessage> findByT_S(long threadId, int status, int start,
8523                    int end, OrderByComparator orderByComparator) throws SystemException {
8524                    FinderPath finderPath = null;
8525                    Object[] finderArgs = null;
8526    
8527                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8528                                    (orderByComparator == null)) {
8529                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
8530                            finderArgs = new Object[] { threadId, status };
8531                    }
8532                    else {
8533                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
8534                            finderArgs = new Object[] {
8535                                            threadId, status,
8536                                            
8537                                            start, end, orderByComparator
8538                                    };
8539                    }
8540    
8541                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8542                                    finderArgs, this);
8543    
8544                    if ((list != null) && !list.isEmpty()) {
8545                            for (MBMessage mbMessage : list) {
8546                                    if ((threadId != mbMessage.getThreadId()) ||
8547                                                    (status != mbMessage.getStatus())) {
8548                                            list = null;
8549    
8550                                            break;
8551                                    }
8552                            }
8553                    }
8554    
8555                    if (list == null) {
8556                            StringBundler query = null;
8557    
8558                            if (orderByComparator != null) {
8559                                    query = new StringBundler(4 +
8560                                                    (orderByComparator.getOrderByFields().length * 3));
8561                            }
8562                            else {
8563                                    query = new StringBundler(4);
8564                            }
8565    
8566                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8567    
8568                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
8569    
8570                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
8571    
8572                            if (orderByComparator != null) {
8573                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8574                                            orderByComparator);
8575                            }
8576    
8577                            else {
8578                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8579                            }
8580    
8581                            String sql = query.toString();
8582    
8583                            Session session = null;
8584    
8585                            try {
8586                                    session = openSession();
8587    
8588                                    Query q = session.createQuery(sql);
8589    
8590                                    QueryPos qPos = QueryPos.getInstance(q);
8591    
8592                                    qPos.add(threadId);
8593    
8594                                    qPos.add(status);
8595    
8596                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8597                                                    end);
8598                            }
8599                            catch (Exception e) {
8600                                    throw processException(e);
8601                            }
8602                            finally {
8603                                    if (list == null) {
8604                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8605                                    }
8606                                    else {
8607                                            cacheResult(list);
8608    
8609                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8610                                    }
8611    
8612                                    closeSession(session);
8613                            }
8614                    }
8615    
8616                    return list;
8617            }
8618    
8619            /**
8620             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8621             *
8622             * <p>
8623             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8624             * </p>
8625             *
8626             * @param threadId the thread ID
8627             * @param status the status
8628             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8629             * @return the first matching message-boards message
8630             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8631             * @throws SystemException if a system exception occurred
8632             */
8633            public MBMessage findByT_S_First(long threadId, int status,
8634                    OrderByComparator orderByComparator)
8635                    throws NoSuchMessageException, SystemException {
8636                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
8637                                    orderByComparator);
8638    
8639                    if (list.isEmpty()) {
8640                            StringBundler msg = new StringBundler(6);
8641    
8642                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8643    
8644                            msg.append("threadId=");
8645                            msg.append(threadId);
8646    
8647                            msg.append(", status=");
8648                            msg.append(status);
8649    
8650                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8651    
8652                            throw new NoSuchMessageException(msg.toString());
8653                    }
8654                    else {
8655                            return list.get(0);
8656                    }
8657            }
8658    
8659            /**
8660             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8661             *
8662             * <p>
8663             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8664             * </p>
8665             *
8666             * @param threadId the thread ID
8667             * @param status the status
8668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8669             * @return the last matching message-boards message
8670             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8671             * @throws SystemException if a system exception occurred
8672             */
8673            public MBMessage findByT_S_Last(long threadId, int status,
8674                    OrderByComparator orderByComparator)
8675                    throws NoSuchMessageException, SystemException {
8676                    int count = countByT_S(threadId, status);
8677    
8678                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
8679                                    orderByComparator);
8680    
8681                    if (list.isEmpty()) {
8682                            StringBundler msg = new StringBundler(6);
8683    
8684                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8685    
8686                            msg.append("threadId=");
8687                            msg.append(threadId);
8688    
8689                            msg.append(", status=");
8690                            msg.append(status);
8691    
8692                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8693    
8694                            throw new NoSuchMessageException(msg.toString());
8695                    }
8696                    else {
8697                            return list.get(0);
8698                    }
8699            }
8700    
8701            /**
8702             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8703             *
8704             * <p>
8705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8706             * </p>
8707             *
8708             * @param messageId the primary key of the current message-boards message
8709             * @param threadId the thread ID
8710             * @param status the status
8711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8712             * @return the previous, current, and next message-boards message
8713             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8714             * @throws SystemException if a system exception occurred
8715             */
8716            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
8717                    int status, OrderByComparator orderByComparator)
8718                    throws NoSuchMessageException, SystemException {
8719                    MBMessage mbMessage = findByPrimaryKey(messageId);
8720    
8721                    Session session = null;
8722    
8723                    try {
8724                            session = openSession();
8725    
8726                            MBMessage[] array = new MBMessageImpl[3];
8727    
8728                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
8729                                            status, orderByComparator, true);
8730    
8731                            array[1] = mbMessage;
8732    
8733                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
8734                                            status, orderByComparator, false);
8735    
8736                            return array;
8737                    }
8738                    catch (Exception e) {
8739                            throw processException(e);
8740                    }
8741                    finally {
8742                            closeSession(session);
8743                    }
8744            }
8745    
8746            protected MBMessage getByT_S_PrevAndNext(Session session,
8747                    MBMessage mbMessage, long threadId, int status,
8748                    OrderByComparator orderByComparator, boolean previous) {
8749                    StringBundler query = null;
8750    
8751                    if (orderByComparator != null) {
8752                            query = new StringBundler(6 +
8753                                            (orderByComparator.getOrderByFields().length * 6));
8754                    }
8755                    else {
8756                            query = new StringBundler(3);
8757                    }
8758    
8759                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8760    
8761                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
8762    
8763                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
8764    
8765                    if (orderByComparator != null) {
8766                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8767    
8768                            if (orderByConditionFields.length > 0) {
8769                                    query.append(WHERE_AND);
8770                            }
8771    
8772                            for (int i = 0; i < orderByConditionFields.length; i++) {
8773                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8774                                    query.append(orderByConditionFields[i]);
8775    
8776                                    if ((i + 1) < orderByConditionFields.length) {
8777                                            if (orderByComparator.isAscending() ^ previous) {
8778                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8779                                            }
8780                                            else {
8781                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8782                                            }
8783                                    }
8784                                    else {
8785                                            if (orderByComparator.isAscending() ^ previous) {
8786                                                    query.append(WHERE_GREATER_THAN);
8787                                            }
8788                                            else {
8789                                                    query.append(WHERE_LESSER_THAN);
8790                                            }
8791                                    }
8792                            }
8793    
8794                            query.append(ORDER_BY_CLAUSE);
8795    
8796                            String[] orderByFields = orderByComparator.getOrderByFields();
8797    
8798                            for (int i = 0; i < orderByFields.length; i++) {
8799                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8800                                    query.append(orderByFields[i]);
8801    
8802                                    if ((i + 1) < orderByFields.length) {
8803                                            if (orderByComparator.isAscending() ^ previous) {
8804                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8805                                            }
8806                                            else {
8807                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8808                                            }
8809                                    }
8810                                    else {
8811                                            if (orderByComparator.isAscending() ^ previous) {
8812                                                    query.append(ORDER_BY_ASC);
8813                                            }
8814                                            else {
8815                                                    query.append(ORDER_BY_DESC);
8816                                            }
8817                                    }
8818                            }
8819                    }
8820    
8821                    else {
8822                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8823                    }
8824    
8825                    String sql = query.toString();
8826    
8827                    Query q = session.createQuery(sql);
8828    
8829                    q.setFirstResult(0);
8830                    q.setMaxResults(2);
8831    
8832                    QueryPos qPos = QueryPos.getInstance(q);
8833    
8834                    qPos.add(threadId);
8835    
8836                    qPos.add(status);
8837    
8838                    if (orderByComparator != null) {
8839                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8840    
8841                            for (Object value : values) {
8842                                    qPos.add(value);
8843                            }
8844                    }
8845    
8846                    List<MBMessage> list = q.list();
8847    
8848                    if (list.size() == 2) {
8849                            return list.get(1);
8850                    }
8851                    else {
8852                            return null;
8853                    }
8854            }
8855    
8856            /**
8857             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
8858             *
8859             * @param threadId the thread ID
8860             * @param status the status
8861             * @return the matching message-boards messages
8862             * @throws SystemException if a system exception occurred
8863             */
8864            public List<MBMessage> findByTR_S(long threadId, int status)
8865                    throws SystemException {
8866                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
8867                            QueryUtil.ALL_POS, null);
8868            }
8869    
8870            /**
8871             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
8872             *
8873             * <p>
8874             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8875             * </p>
8876             *
8877             * @param threadId the thread ID
8878             * @param status the status
8879             * @param start the lower bound of the range of message-boards messages
8880             * @param end the upper bound of the range of message-boards messages (not inclusive)
8881             * @return the range of matching message-boards messages
8882             * @throws SystemException if a system exception occurred
8883             */
8884            public List<MBMessage> findByTR_S(long threadId, int status, int start,
8885                    int end) throws SystemException {
8886                    return findByTR_S(threadId, status, start, end, null);
8887            }
8888    
8889            /**
8890             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
8891             *
8892             * <p>
8893             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8894             * </p>
8895             *
8896             * @param threadId the thread ID
8897             * @param status the status
8898             * @param start the lower bound of the range of message-boards messages
8899             * @param end the upper bound of the range of message-boards messages (not inclusive)
8900             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8901             * @return the ordered range of matching message-boards messages
8902             * @throws SystemException if a system exception occurred
8903             */
8904            public List<MBMessage> findByTR_S(long threadId, int status, int start,
8905                    int end, OrderByComparator orderByComparator) throws SystemException {
8906                    FinderPath finderPath = null;
8907                    Object[] finderArgs = null;
8908    
8909                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8910                                    (orderByComparator == null)) {
8911                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
8912                            finderArgs = new Object[] { threadId, status };
8913                    }
8914                    else {
8915                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
8916                            finderArgs = new Object[] {
8917                                            threadId, status,
8918                                            
8919                                            start, end, orderByComparator
8920                                    };
8921                    }
8922    
8923                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8924                                    finderArgs, this);
8925    
8926                    if ((list != null) && !list.isEmpty()) {
8927                            for (MBMessage mbMessage : list) {
8928                                    if ((threadId != mbMessage.getThreadId()) ||
8929                                                    (status != mbMessage.getStatus())) {
8930                                            list = null;
8931    
8932                                            break;
8933                                    }
8934                            }
8935                    }
8936    
8937                    if (list == null) {
8938                            StringBundler query = null;
8939    
8940                            if (orderByComparator != null) {
8941                                    query = new StringBundler(4 +
8942                                                    (orderByComparator.getOrderByFields().length * 3));
8943                            }
8944                            else {
8945                                    query = new StringBundler(4);
8946                            }
8947    
8948                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8949    
8950                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
8951    
8952                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
8953    
8954                            if (orderByComparator != null) {
8955                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8956                                            orderByComparator);
8957                            }
8958    
8959                            else {
8960                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8961                            }
8962    
8963                            String sql = query.toString();
8964    
8965                            Session session = null;
8966    
8967                            try {
8968                                    session = openSession();
8969    
8970                                    Query q = session.createQuery(sql);
8971    
8972                                    QueryPos qPos = QueryPos.getInstance(q);
8973    
8974                                    qPos.add(threadId);
8975    
8976                                    qPos.add(status);
8977    
8978                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8979                                                    end);
8980                            }
8981                            catch (Exception e) {
8982                                    throw processException(e);
8983                            }
8984                            finally {
8985                                    if (list == null) {
8986                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8987                                    }
8988                                    else {
8989                                            cacheResult(list);
8990    
8991                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8992                                    }
8993    
8994                                    closeSession(session);
8995                            }
8996                    }
8997    
8998                    return list;
8999            }
9000    
9001            /**
9002             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9003             *
9004             * <p>
9005             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9006             * </p>
9007             *
9008             * @param threadId the thread ID
9009             * @param status the status
9010             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9011             * @return the first matching message-boards message
9012             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9013             * @throws SystemException if a system exception occurred
9014             */
9015            public MBMessage findByTR_S_First(long threadId, int status,
9016                    OrderByComparator orderByComparator)
9017                    throws NoSuchMessageException, SystemException {
9018                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
9019                                    orderByComparator);
9020    
9021                    if (list.isEmpty()) {
9022                            StringBundler msg = new StringBundler(6);
9023    
9024                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9025    
9026                            msg.append("threadId=");
9027                            msg.append(threadId);
9028    
9029                            msg.append(", status=");
9030                            msg.append(status);
9031    
9032                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9033    
9034                            throw new NoSuchMessageException(msg.toString());
9035                    }
9036                    else {
9037                            return list.get(0);
9038                    }
9039            }
9040    
9041            /**
9042             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9043             *
9044             * <p>
9045             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9046             * </p>
9047             *
9048             * @param threadId the thread ID
9049             * @param status the status
9050             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9051             * @return the last matching message-boards message
9052             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9053             * @throws SystemException if a system exception occurred
9054             */
9055            public MBMessage findByTR_S_Last(long threadId, int status,
9056                    OrderByComparator orderByComparator)
9057                    throws NoSuchMessageException, SystemException {
9058                    int count = countByTR_S(threadId, status);
9059    
9060                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
9061                                    orderByComparator);
9062    
9063                    if (list.isEmpty()) {
9064                            StringBundler msg = new StringBundler(6);
9065    
9066                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9067    
9068                            msg.append("threadId=");
9069                            msg.append(threadId);
9070    
9071                            msg.append(", status=");
9072                            msg.append(status);
9073    
9074                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9075    
9076                            throw new NoSuchMessageException(msg.toString());
9077                    }
9078                    else {
9079                            return list.get(0);
9080                    }
9081            }
9082    
9083            /**
9084             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9085             *
9086             * <p>
9087             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9088             * </p>
9089             *
9090             * @param messageId the primary key of the current message-boards message
9091             * @param threadId the thread ID
9092             * @param status the status
9093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9094             * @return the previous, current, and next message-boards message
9095             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9096             * @throws SystemException if a system exception occurred
9097             */
9098            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
9099                    int status, OrderByComparator orderByComparator)
9100                    throws NoSuchMessageException, SystemException {
9101                    MBMessage mbMessage = findByPrimaryKey(messageId);
9102    
9103                    Session session = null;
9104    
9105                    try {
9106                            session = openSession();
9107    
9108                            MBMessage[] array = new MBMessageImpl[3];
9109    
9110                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
9111                                            status, orderByComparator, true);
9112    
9113                            array[1] = mbMessage;
9114    
9115                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
9116                                            status, orderByComparator, false);
9117    
9118                            return array;
9119                    }
9120                    catch (Exception e) {
9121                            throw processException(e);
9122                    }
9123                    finally {
9124                            closeSession(session);
9125                    }
9126            }
9127    
9128            protected MBMessage getByTR_S_PrevAndNext(Session session,
9129                    MBMessage mbMessage, long threadId, int status,
9130                    OrderByComparator orderByComparator, boolean previous) {
9131                    StringBundler query = null;
9132    
9133                    if (orderByComparator != null) {
9134                            query = new StringBundler(6 +
9135                                            (orderByComparator.getOrderByFields().length * 6));
9136                    }
9137                    else {
9138                            query = new StringBundler(3);
9139                    }
9140    
9141                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9142    
9143                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
9144    
9145                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
9146    
9147                    if (orderByComparator != null) {
9148                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9149    
9150                            if (orderByConditionFields.length > 0) {
9151                                    query.append(WHERE_AND);
9152                            }
9153    
9154                            for (int i = 0; i < orderByConditionFields.length; i++) {
9155                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9156                                    query.append(orderByConditionFields[i]);
9157    
9158                                    if ((i + 1) < orderByConditionFields.length) {
9159                                            if (orderByComparator.isAscending() ^ previous) {
9160                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9161                                            }
9162                                            else {
9163                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9164                                            }
9165                                    }
9166                                    else {
9167                                            if (orderByComparator.isAscending() ^ previous) {
9168                                                    query.append(WHERE_GREATER_THAN);
9169                                            }
9170                                            else {
9171                                                    query.append(WHERE_LESSER_THAN);
9172                                            }
9173                                    }
9174                            }
9175    
9176                            query.append(ORDER_BY_CLAUSE);
9177    
9178                            String[] orderByFields = orderByComparator.getOrderByFields();
9179    
9180                            for (int i = 0; i < orderByFields.length; i++) {
9181                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9182                                    query.append(orderByFields[i]);
9183    
9184                                    if ((i + 1) < orderByFields.length) {
9185                                            if (orderByComparator.isAscending() ^ previous) {
9186                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9187                                            }
9188                                            else {
9189                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9190                                            }
9191                                    }
9192                                    else {
9193                                            if (orderByComparator.isAscending() ^ previous) {
9194                                                    query.append(ORDER_BY_ASC);
9195                                            }
9196                                            else {
9197                                                    query.append(ORDER_BY_DESC);
9198                                            }
9199                                    }
9200                            }
9201                    }
9202    
9203                    else {
9204                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9205                    }
9206    
9207                    String sql = query.toString();
9208    
9209                    Query q = session.createQuery(sql);
9210    
9211                    q.setFirstResult(0);
9212                    q.setMaxResults(2);
9213    
9214                    QueryPos qPos = QueryPos.getInstance(q);
9215    
9216                    qPos.add(threadId);
9217    
9218                    qPos.add(status);
9219    
9220                    if (orderByComparator != null) {
9221                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9222    
9223                            for (Object value : values) {
9224                                    qPos.add(value);
9225                            }
9226                    }
9227    
9228                    List<MBMessage> list = q.list();
9229    
9230                    if (list.size() == 2) {
9231                            return list.get(1);
9232                    }
9233                    else {
9234                            return null;
9235                    }
9236            }
9237    
9238            /**
9239             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9240             *
9241             * @param groupId the group ID
9242             * @param userId the user ID
9243             * @param status the status
9244             * @return the matching message-boards messages
9245             * @throws SystemException if a system exception occurred
9246             */
9247            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
9248                    throws SystemException {
9249                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
9250                            QueryUtil.ALL_POS, null);
9251            }
9252    
9253            /**
9254             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9255             *
9256             * <p>
9257             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9258             * </p>
9259             *
9260             * @param groupId the group ID
9261             * @param userId the user ID
9262             * @param status the status
9263             * @param start the lower bound of the range of message-boards messages
9264             * @param end the upper bound of the range of message-boards messages (not inclusive)
9265             * @return the range of matching message-boards messages
9266             * @throws SystemException if a system exception occurred
9267             */
9268            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
9269                    int start, int end) throws SystemException {
9270                    return findByG_U_S(groupId, userId, status, start, end, null);
9271            }
9272    
9273            /**
9274             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9275             *
9276             * <p>
9277             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9278             * </p>
9279             *
9280             * @param groupId the group ID
9281             * @param userId the user ID
9282             * @param status the status
9283             * @param start the lower bound of the range of message-boards messages
9284             * @param end the upper bound of the range of message-boards messages (not inclusive)
9285             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9286             * @return the ordered range of matching message-boards messages
9287             * @throws SystemException if a system exception occurred
9288             */
9289            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
9290                    int start, int end, OrderByComparator orderByComparator)
9291                    throws SystemException {
9292                    FinderPath finderPath = null;
9293                    Object[] finderArgs = null;
9294    
9295                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9296                                    (orderByComparator == null)) {
9297                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
9298                            finderArgs = new Object[] { groupId, userId, status };
9299                    }
9300                    else {
9301                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
9302                            finderArgs = new Object[] {
9303                                            groupId, userId, status,
9304                                            
9305                                            start, end, orderByComparator
9306                                    };
9307                    }
9308    
9309                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9310                                    finderArgs, this);
9311    
9312                    if ((list != null) && !list.isEmpty()) {
9313                            for (MBMessage mbMessage : list) {
9314                                    if ((groupId != mbMessage.getGroupId()) ||
9315                                                    (userId != mbMessage.getUserId()) ||
9316                                                    (status != mbMessage.getStatus())) {
9317                                            list = null;
9318    
9319                                            break;
9320                                    }
9321                            }
9322                    }
9323    
9324                    if (list == null) {
9325                            StringBundler query = null;
9326    
9327                            if (orderByComparator != null) {
9328                                    query = new StringBundler(5 +
9329                                                    (orderByComparator.getOrderByFields().length * 3));
9330                            }
9331                            else {
9332                                    query = new StringBundler(5);
9333                            }
9334    
9335                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9336    
9337                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9338    
9339                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9340    
9341                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9342    
9343                            if (orderByComparator != null) {
9344                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9345                                            orderByComparator);
9346                            }
9347    
9348                            else {
9349                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9350                            }
9351    
9352                            String sql = query.toString();
9353    
9354                            Session session = null;
9355    
9356                            try {
9357                                    session = openSession();
9358    
9359                                    Query q = session.createQuery(sql);
9360    
9361                                    QueryPos qPos = QueryPos.getInstance(q);
9362    
9363                                    qPos.add(groupId);
9364    
9365                                    qPos.add(userId);
9366    
9367                                    qPos.add(status);
9368    
9369                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9370                                                    end);
9371                            }
9372                            catch (Exception e) {
9373                                    throw processException(e);
9374                            }
9375                            finally {
9376                                    if (list == null) {
9377                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9378                                    }
9379                                    else {
9380                                            cacheResult(list);
9381    
9382                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9383                                    }
9384    
9385                                    closeSession(session);
9386                            }
9387                    }
9388    
9389                    return list;
9390            }
9391    
9392            /**
9393             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9394             *
9395             * <p>
9396             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9397             * </p>
9398             *
9399             * @param groupId the group ID
9400             * @param userId the user ID
9401             * @param status the status
9402             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9403             * @return the first matching message-boards message
9404             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9405             * @throws SystemException if a system exception occurred
9406             */
9407            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
9408                    OrderByComparator orderByComparator)
9409                    throws NoSuchMessageException, SystemException {
9410                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
9411                                    orderByComparator);
9412    
9413                    if (list.isEmpty()) {
9414                            StringBundler msg = new StringBundler(8);
9415    
9416                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9417    
9418                            msg.append("groupId=");
9419                            msg.append(groupId);
9420    
9421                            msg.append(", userId=");
9422                            msg.append(userId);
9423    
9424                            msg.append(", status=");
9425                            msg.append(status);
9426    
9427                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9428    
9429                            throw new NoSuchMessageException(msg.toString());
9430                    }
9431                    else {
9432                            return list.get(0);
9433                    }
9434            }
9435    
9436            /**
9437             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9438             *
9439             * <p>
9440             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9441             * </p>
9442             *
9443             * @param groupId the group ID
9444             * @param userId the user ID
9445             * @param status the status
9446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9447             * @return the last matching message-boards message
9448             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9449             * @throws SystemException if a system exception occurred
9450             */
9451            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
9452                    OrderByComparator orderByComparator)
9453                    throws NoSuchMessageException, SystemException {
9454                    int count = countByG_U_S(groupId, userId, status);
9455    
9456                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
9457                                    count, orderByComparator);
9458    
9459                    if (list.isEmpty()) {
9460                            StringBundler msg = new StringBundler(8);
9461    
9462                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9463    
9464                            msg.append("groupId=");
9465                            msg.append(groupId);
9466    
9467                            msg.append(", userId=");
9468                            msg.append(userId);
9469    
9470                            msg.append(", status=");
9471                            msg.append(status);
9472    
9473                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9474    
9475                            throw new NoSuchMessageException(msg.toString());
9476                    }
9477                    else {
9478                            return list.get(0);
9479                    }
9480            }
9481    
9482            /**
9483             * 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;.
9484             *
9485             * <p>
9486             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9487             * </p>
9488             *
9489             * @param messageId the primary key of the current message-boards message
9490             * @param groupId the group ID
9491             * @param userId the user ID
9492             * @param status the status
9493             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9494             * @return the previous, current, and next message-boards message
9495             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9496             * @throws SystemException if a system exception occurred
9497             */
9498            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
9499                    long userId, int status, OrderByComparator orderByComparator)
9500                    throws NoSuchMessageException, SystemException {
9501                    MBMessage mbMessage = findByPrimaryKey(messageId);
9502    
9503                    Session session = null;
9504    
9505                    try {
9506                            session = openSession();
9507    
9508                            MBMessage[] array = new MBMessageImpl[3];
9509    
9510                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9511                                            userId, status, orderByComparator, true);
9512    
9513                            array[1] = mbMessage;
9514    
9515                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9516                                            userId, status, orderByComparator, false);
9517    
9518                            return array;
9519                    }
9520                    catch (Exception e) {
9521                            throw processException(e);
9522                    }
9523                    finally {
9524                            closeSession(session);
9525                    }
9526            }
9527    
9528            protected MBMessage getByG_U_S_PrevAndNext(Session session,
9529                    MBMessage mbMessage, long groupId, long userId, int status,
9530                    OrderByComparator orderByComparator, boolean previous) {
9531                    StringBundler query = null;
9532    
9533                    if (orderByComparator != null) {
9534                            query = new StringBundler(6 +
9535                                            (orderByComparator.getOrderByFields().length * 6));
9536                    }
9537                    else {
9538                            query = new StringBundler(3);
9539                    }
9540    
9541                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9542    
9543                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9544    
9545                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9546    
9547                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9548    
9549                    if (orderByComparator != null) {
9550                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9551    
9552                            if (orderByConditionFields.length > 0) {
9553                                    query.append(WHERE_AND);
9554                            }
9555    
9556                            for (int i = 0; i < orderByConditionFields.length; i++) {
9557                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9558                                    query.append(orderByConditionFields[i]);
9559    
9560                                    if ((i + 1) < orderByConditionFields.length) {
9561                                            if (orderByComparator.isAscending() ^ previous) {
9562                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9563                                            }
9564                                            else {
9565                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9566                                            }
9567                                    }
9568                                    else {
9569                                            if (orderByComparator.isAscending() ^ previous) {
9570                                                    query.append(WHERE_GREATER_THAN);
9571                                            }
9572                                            else {
9573                                                    query.append(WHERE_LESSER_THAN);
9574                                            }
9575                                    }
9576                            }
9577    
9578                            query.append(ORDER_BY_CLAUSE);
9579    
9580                            String[] orderByFields = orderByComparator.getOrderByFields();
9581    
9582                            for (int i = 0; i < orderByFields.length; i++) {
9583                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9584                                    query.append(orderByFields[i]);
9585    
9586                                    if ((i + 1) < orderByFields.length) {
9587                                            if (orderByComparator.isAscending() ^ previous) {
9588                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9589                                            }
9590                                            else {
9591                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9592                                            }
9593                                    }
9594                                    else {
9595                                            if (orderByComparator.isAscending() ^ previous) {
9596                                                    query.append(ORDER_BY_ASC);
9597                                            }
9598                                            else {
9599                                                    query.append(ORDER_BY_DESC);
9600                                            }
9601                                    }
9602                            }
9603                    }
9604    
9605                    else {
9606                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9607                    }
9608    
9609                    String sql = query.toString();
9610    
9611                    Query q = session.createQuery(sql);
9612    
9613                    q.setFirstResult(0);
9614                    q.setMaxResults(2);
9615    
9616                    QueryPos qPos = QueryPos.getInstance(q);
9617    
9618                    qPos.add(groupId);
9619    
9620                    qPos.add(userId);
9621    
9622                    qPos.add(status);
9623    
9624                    if (orderByComparator != null) {
9625                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9626    
9627                            for (Object value : values) {
9628                                    qPos.add(value);
9629                            }
9630                    }
9631    
9632                    List<MBMessage> list = q.list();
9633    
9634                    if (list.size() == 2) {
9635                            return list.get(1);
9636                    }
9637                    else {
9638                            return null;
9639                    }
9640            }
9641    
9642            /**
9643             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
9644             *
9645             * @param groupId the group ID
9646             * @param userId the user ID
9647             * @param status the status
9648             * @return the matching message-boards messages that the user has permission to view
9649             * @throws SystemException if a system exception occurred
9650             */
9651            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
9652                    int status) throws SystemException {
9653                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
9654                            QueryUtil.ALL_POS, null);
9655            }
9656    
9657            /**
9658             * 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;.
9659             *
9660             * <p>
9661             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9662             * </p>
9663             *
9664             * @param groupId the group ID
9665             * @param userId the user ID
9666             * @param status the status
9667             * @param start the lower bound of the range of message-boards messages
9668             * @param end the upper bound of the range of message-boards messages (not inclusive)
9669             * @return the range of matching message-boards messages that the user has permission to view
9670             * @throws SystemException if a system exception occurred
9671             */
9672            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
9673                    int status, int start, int end) throws SystemException {
9674                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
9675            }
9676    
9677            /**
9678             * 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;.
9679             *
9680             * <p>
9681             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9682             * </p>
9683             *
9684             * @param groupId the group ID
9685             * @param userId the user ID
9686             * @param status the status
9687             * @param start the lower bound of the range of message-boards messages
9688             * @param end the upper bound of the range of message-boards messages (not inclusive)
9689             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9690             * @return the ordered range of matching message-boards messages that the user has permission to view
9691             * @throws SystemException if a system exception occurred
9692             */
9693            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
9694                    int status, int start, int end, OrderByComparator orderByComparator)
9695                    throws SystemException {
9696                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9697                            return findByG_U_S(groupId, userId, status, start, end,
9698                                    orderByComparator);
9699                    }
9700    
9701                    StringBundler query = null;
9702    
9703                    if (orderByComparator != null) {
9704                            query = new StringBundler(5 +
9705                                            (orderByComparator.getOrderByFields().length * 3));
9706                    }
9707                    else {
9708                            query = new StringBundler(5);
9709                    }
9710    
9711                    if (getDB().isSupportsInlineDistinct()) {
9712                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
9713                    }
9714                    else {
9715                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
9716                    }
9717    
9718                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9719    
9720                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9721    
9722                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9723    
9724                    if (!getDB().isSupportsInlineDistinct()) {
9725                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
9726                    }
9727    
9728                    if (orderByComparator != null) {
9729                            if (getDB().isSupportsInlineDistinct()) {
9730                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9731                                            orderByComparator);
9732                            }
9733                            else {
9734                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9735                                            orderByComparator);
9736                            }
9737                    }
9738    
9739                    else {
9740                            if (getDB().isSupportsInlineDistinct()) {
9741                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9742                            }
9743                            else {
9744                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
9745                            }
9746                    }
9747    
9748                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9749                                    MBMessage.class.getName(),
9750                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9751    
9752                    Session session = null;
9753    
9754                    try {
9755                            session = openSession();
9756    
9757                            SQLQuery q = session.createSQLQuery(sql);
9758    
9759                            if (getDB().isSupportsInlineDistinct()) {
9760                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
9761                            }
9762                            else {
9763                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
9764                            }
9765    
9766                            QueryPos qPos = QueryPos.getInstance(q);
9767    
9768                            qPos.add(groupId);
9769    
9770                            qPos.add(userId);
9771    
9772                            qPos.add(status);
9773    
9774                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
9775                    }
9776                    catch (Exception e) {
9777                            throw processException(e);
9778                    }
9779                    finally {
9780                            closeSession(session);
9781                    }
9782            }
9783    
9784            /**
9785             * 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;.
9786             *
9787             * @param messageId the primary key of the current message-boards message
9788             * @param groupId the group ID
9789             * @param userId the user ID
9790             * @param status the status
9791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9792             * @return the previous, current, and next message-boards message
9793             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9794             * @throws SystemException if a system exception occurred
9795             */
9796            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
9797                    long groupId, long userId, int status,
9798                    OrderByComparator orderByComparator)
9799                    throws NoSuchMessageException, SystemException {
9800                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9801                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
9802                                    orderByComparator);
9803                    }
9804    
9805                    MBMessage mbMessage = findByPrimaryKey(messageId);
9806    
9807                    Session session = null;
9808    
9809                    try {
9810                            session = openSession();
9811    
9812                            MBMessage[] array = new MBMessageImpl[3];
9813    
9814                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
9815                                            groupId, userId, status, orderByComparator, true);
9816    
9817                            array[1] = mbMessage;
9818    
9819                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
9820                                            groupId, userId, status, orderByComparator, false);
9821    
9822                            return array;
9823                    }
9824                    catch (Exception e) {
9825                            throw processException(e);
9826                    }
9827                    finally {
9828                            closeSession(session);
9829                    }
9830            }
9831    
9832            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
9833                    MBMessage mbMessage, long groupId, long userId, int status,
9834                    OrderByComparator orderByComparator, boolean previous) {
9835                    StringBundler query = null;
9836    
9837                    if (orderByComparator != null) {
9838                            query = new StringBundler(6 +
9839                                            (orderByComparator.getOrderByFields().length * 6));
9840                    }
9841                    else {
9842                            query = new StringBundler(3);
9843                    }
9844    
9845                    if (getDB().isSupportsInlineDistinct()) {
9846                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
9847                    }
9848                    else {
9849                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
9850                    }
9851    
9852                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9853    
9854                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9855    
9856                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9857    
9858                    if (!getDB().isSupportsInlineDistinct()) {
9859                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
9860                    }
9861    
9862                    if (orderByComparator != null) {
9863                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9864    
9865                            if (orderByConditionFields.length > 0) {
9866                                    query.append(WHERE_AND);
9867                            }
9868    
9869                            for (int i = 0; i < orderByConditionFields.length; i++) {
9870                                    if (getDB().isSupportsInlineDistinct()) {
9871                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9872                                    }
9873                                    else {
9874                                            query.append(_ORDER_BY_ENTITY_TABLE);
9875                                    }
9876    
9877                                    query.append(orderByConditionFields[i]);
9878    
9879                                    if ((i + 1) < orderByConditionFields.length) {
9880                                            if (orderByComparator.isAscending() ^ previous) {
9881                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9882                                            }
9883                                            else {
9884                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9885                                            }
9886                                    }
9887                                    else {
9888                                            if (orderByComparator.isAscending() ^ previous) {
9889                                                    query.append(WHERE_GREATER_THAN);
9890                                            }
9891                                            else {
9892                                                    query.append(WHERE_LESSER_THAN);
9893                                            }
9894                                    }
9895                            }
9896    
9897                            query.append(ORDER_BY_CLAUSE);
9898    
9899                            String[] orderByFields = orderByComparator.getOrderByFields();
9900    
9901                            for (int i = 0; i < orderByFields.length; i++) {
9902                                    if (getDB().isSupportsInlineDistinct()) {
9903                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9904                                    }
9905                                    else {
9906                                            query.append(_ORDER_BY_ENTITY_TABLE);
9907                                    }
9908    
9909                                    query.append(orderByFields[i]);
9910    
9911                                    if ((i + 1) < orderByFields.length) {
9912                                            if (orderByComparator.isAscending() ^ previous) {
9913                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9914                                            }
9915                                            else {
9916                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9917                                            }
9918                                    }
9919                                    else {
9920                                            if (orderByComparator.isAscending() ^ previous) {
9921                                                    query.append(ORDER_BY_ASC);
9922                                            }
9923                                            else {
9924                                                    query.append(ORDER_BY_DESC);
9925                                            }
9926                                    }
9927                            }
9928                    }
9929    
9930                    else {
9931                            if (getDB().isSupportsInlineDistinct()) {
9932                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9933                            }
9934                            else {
9935                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
9936                            }
9937                    }
9938    
9939                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9940                                    MBMessage.class.getName(),
9941                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9942    
9943                    SQLQuery q = session.createSQLQuery(sql);
9944    
9945                    q.setFirstResult(0);
9946                    q.setMaxResults(2);
9947    
9948                    if (getDB().isSupportsInlineDistinct()) {
9949                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
9950                    }
9951                    else {
9952                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
9953                    }
9954    
9955                    QueryPos qPos = QueryPos.getInstance(q);
9956    
9957                    qPos.add(groupId);
9958    
9959                    qPos.add(userId);
9960    
9961                    qPos.add(status);
9962    
9963                    if (orderByComparator != null) {
9964                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9965    
9966                            for (Object value : values) {
9967                                    qPos.add(value);
9968                            }
9969                    }
9970    
9971                    List<MBMessage> list = q.list();
9972    
9973                    if (list.size() == 2) {
9974                            return list.get(1);
9975                    }
9976                    else {
9977                            return null;
9978                    }
9979            }
9980    
9981            /**
9982             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9983             *
9984             * @param groupId the group ID
9985             * @param categoryId the category ID
9986             * @param threadId the thread ID
9987             * @return the matching message-boards messages
9988             * @throws SystemException if a system exception occurred
9989             */
9990            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
9991                    long threadId) throws SystemException {
9992                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
9993                            QueryUtil.ALL_POS, null);
9994            }
9995    
9996            /**
9997             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9998             *
9999             * <p>
10000             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10001             * </p>
10002             *
10003             * @param groupId the group ID
10004             * @param categoryId the category ID
10005             * @param threadId the thread ID
10006             * @param start the lower bound of the range of message-boards messages
10007             * @param end the upper bound of the range of message-boards messages (not inclusive)
10008             * @return the range of matching message-boards messages
10009             * @throws SystemException if a system exception occurred
10010             */
10011            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10012                    long threadId, int start, int end) throws SystemException {
10013                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
10014            }
10015    
10016            /**
10017             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10018             *
10019             * <p>
10020             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10021             * </p>
10022             *
10023             * @param groupId the group ID
10024             * @param categoryId the category ID
10025             * @param threadId the thread ID
10026             * @param start the lower bound of the range of message-boards messages
10027             * @param end the upper bound of the range of message-boards messages (not inclusive)
10028             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10029             * @return the ordered range of matching message-boards messages
10030             * @throws SystemException if a system exception occurred
10031             */
10032            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10033                    long threadId, int start, int end, OrderByComparator orderByComparator)
10034                    throws SystemException {
10035                    FinderPath finderPath = null;
10036                    Object[] finderArgs = null;
10037    
10038                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10039                                    (orderByComparator == null)) {
10040                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
10041                            finderArgs = new Object[] { groupId, categoryId, threadId };
10042                    }
10043                    else {
10044                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
10045                            finderArgs = new Object[] {
10046                                            groupId, categoryId, threadId,
10047                                            
10048                                            start, end, orderByComparator
10049                                    };
10050                    }
10051    
10052                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10053                                    finderArgs, this);
10054    
10055                    if ((list != null) && !list.isEmpty()) {
10056                            for (MBMessage mbMessage : list) {
10057                                    if ((groupId != mbMessage.getGroupId()) ||
10058                                                    (categoryId != mbMessage.getCategoryId()) ||
10059                                                    (threadId != mbMessage.getThreadId())) {
10060                                            list = null;
10061    
10062                                            break;
10063                                    }
10064                            }
10065                    }
10066    
10067                    if (list == null) {
10068                            StringBundler query = null;
10069    
10070                            if (orderByComparator != null) {
10071                                    query = new StringBundler(5 +
10072                                                    (orderByComparator.getOrderByFields().length * 3));
10073                            }
10074                            else {
10075                                    query = new StringBundler(5);
10076                            }
10077    
10078                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10079    
10080                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10081    
10082                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10083    
10084                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10085    
10086                            if (orderByComparator != null) {
10087                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10088                                            orderByComparator);
10089                            }
10090    
10091                            else {
10092                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10093                            }
10094    
10095                            String sql = query.toString();
10096    
10097                            Session session = null;
10098    
10099                            try {
10100                                    session = openSession();
10101    
10102                                    Query q = session.createQuery(sql);
10103    
10104                                    QueryPos qPos = QueryPos.getInstance(q);
10105    
10106                                    qPos.add(groupId);
10107    
10108                                    qPos.add(categoryId);
10109    
10110                                    qPos.add(threadId);
10111    
10112                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
10113                                                    end);
10114                            }
10115                            catch (Exception e) {
10116                                    throw processException(e);
10117                            }
10118                            finally {
10119                                    if (list == null) {
10120                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
10121                                    }
10122                                    else {
10123                                            cacheResult(list);
10124    
10125                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
10126                                    }
10127    
10128                                    closeSession(session);
10129                            }
10130                    }
10131    
10132                    return list;
10133            }
10134    
10135            /**
10136             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10137             *
10138             * <p>
10139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10140             * </p>
10141             *
10142             * @param groupId the group ID
10143             * @param categoryId the category ID
10144             * @param threadId the thread ID
10145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10146             * @return the first matching message-boards message
10147             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10148             * @throws SystemException if a system exception occurred
10149             */
10150            public MBMessage findByG_C_T_First(long groupId, long categoryId,
10151                    long threadId, OrderByComparator orderByComparator)
10152                    throws NoSuchMessageException, SystemException {
10153                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
10154                                    orderByComparator);
10155    
10156                    if (list.isEmpty()) {
10157                            StringBundler msg = new StringBundler(8);
10158    
10159                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10160    
10161                            msg.append("groupId=");
10162                            msg.append(groupId);
10163    
10164                            msg.append(", categoryId=");
10165                            msg.append(categoryId);
10166    
10167                            msg.append(", threadId=");
10168                            msg.append(threadId);
10169    
10170                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10171    
10172                            throw new NoSuchMessageException(msg.toString());
10173                    }
10174                    else {
10175                            return list.get(0);
10176                    }
10177            }
10178    
10179            /**
10180             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10181             *
10182             * <p>
10183             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10184             * </p>
10185             *
10186             * @param groupId the group ID
10187             * @param categoryId the category ID
10188             * @param threadId the thread ID
10189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10190             * @return the last matching message-boards message
10191             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10192             * @throws SystemException if a system exception occurred
10193             */
10194            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
10195                    long threadId, OrderByComparator orderByComparator)
10196                    throws NoSuchMessageException, SystemException {
10197                    int count = countByG_C_T(groupId, categoryId, threadId);
10198    
10199                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
10200                                    count - 1, count, orderByComparator);
10201    
10202                    if (list.isEmpty()) {
10203                            StringBundler msg = new StringBundler(8);
10204    
10205                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10206    
10207                            msg.append("groupId=");
10208                            msg.append(groupId);
10209    
10210                            msg.append(", categoryId=");
10211                            msg.append(categoryId);
10212    
10213                            msg.append(", threadId=");
10214                            msg.append(threadId);
10215    
10216                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10217    
10218                            throw new NoSuchMessageException(msg.toString());
10219                    }
10220                    else {
10221                            return list.get(0);
10222                    }
10223            }
10224    
10225            /**
10226             * 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;.
10227             *
10228             * <p>
10229             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10230             * </p>
10231             *
10232             * @param messageId the primary key of the current message-boards message
10233             * @param groupId the group ID
10234             * @param categoryId the category ID
10235             * @param threadId the thread ID
10236             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10237             * @return the previous, current, and next message-boards message
10238             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10239             * @throws SystemException if a system exception occurred
10240             */
10241            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
10242                    long categoryId, long threadId, OrderByComparator orderByComparator)
10243                    throws NoSuchMessageException, SystemException {
10244                    MBMessage mbMessage = findByPrimaryKey(messageId);
10245    
10246                    Session session = null;
10247    
10248                    try {
10249                            session = openSession();
10250    
10251                            MBMessage[] array = new MBMessageImpl[3];
10252    
10253                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10254                                            categoryId, threadId, orderByComparator, true);
10255    
10256                            array[1] = mbMessage;
10257    
10258                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10259                                            categoryId, threadId, orderByComparator, false);
10260    
10261                            return array;
10262                    }
10263                    catch (Exception e) {
10264                            throw processException(e);
10265                    }
10266                    finally {
10267                            closeSession(session);
10268                    }
10269            }
10270    
10271            protected MBMessage getByG_C_T_PrevAndNext(Session session,
10272                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
10273                    OrderByComparator orderByComparator, boolean previous) {
10274                    StringBundler query = null;
10275    
10276                    if (orderByComparator != null) {
10277                            query = new StringBundler(6 +
10278                                            (orderByComparator.getOrderByFields().length * 6));
10279                    }
10280                    else {
10281                            query = new StringBundler(3);
10282                    }
10283    
10284                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10285    
10286                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10287    
10288                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10289    
10290                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10291    
10292                    if (orderByComparator != null) {
10293                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10294    
10295                            if (orderByConditionFields.length > 0) {
10296                                    query.append(WHERE_AND);
10297                            }
10298    
10299                            for (int i = 0; i < orderByConditionFields.length; i++) {
10300                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10301                                    query.append(orderByConditionFields[i]);
10302    
10303                                    if ((i + 1) < orderByConditionFields.length) {
10304                                            if (orderByComparator.isAscending() ^ previous) {
10305                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10306                                            }
10307                                            else {
10308                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10309                                            }
10310                                    }
10311                                    else {
10312                                            if (orderByComparator.isAscending() ^ previous) {
10313                                                    query.append(WHERE_GREATER_THAN);
10314                                            }
10315                                            else {
10316                                                    query.append(WHERE_LESSER_THAN);
10317                                            }
10318                                    }
10319                            }
10320    
10321                            query.append(ORDER_BY_CLAUSE);
10322    
10323                            String[] orderByFields = orderByComparator.getOrderByFields();
10324    
10325                            for (int i = 0; i < orderByFields.length; i++) {
10326                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10327                                    query.append(orderByFields[i]);
10328    
10329                                    if ((i + 1) < orderByFields.length) {
10330                                            if (orderByComparator.isAscending() ^ previous) {
10331                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10332                                            }
10333                                            else {
10334                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10335                                            }
10336                                    }
10337                                    else {
10338                                            if (orderByComparator.isAscending() ^ previous) {
10339                                                    query.append(ORDER_BY_ASC);
10340                                            }
10341                                            else {
10342                                                    query.append(ORDER_BY_DESC);
10343                                            }
10344                                    }
10345                            }
10346                    }
10347    
10348                    else {
10349                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10350                    }
10351    
10352                    String sql = query.toString();
10353    
10354                    Query q = session.createQuery(sql);
10355    
10356                    q.setFirstResult(0);
10357                    q.setMaxResults(2);
10358    
10359                    QueryPos qPos = QueryPos.getInstance(q);
10360    
10361                    qPos.add(groupId);
10362    
10363                    qPos.add(categoryId);
10364    
10365                    qPos.add(threadId);
10366    
10367                    if (orderByComparator != null) {
10368                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10369    
10370                            for (Object value : values) {
10371                                    qPos.add(value);
10372                            }
10373                    }
10374    
10375                    List<MBMessage> list = q.list();
10376    
10377                    if (list.size() == 2) {
10378                            return list.get(1);
10379                    }
10380                    else {
10381                            return null;
10382                    }
10383            }
10384    
10385            /**
10386             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10387             *
10388             * @param groupId the group ID
10389             * @param categoryId the category ID
10390             * @param threadId the thread ID
10391             * @return the matching message-boards messages that the user has permission to view
10392             * @throws SystemException if a system exception occurred
10393             */
10394            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10395                    long threadId) throws SystemException {
10396                    return filterFindByG_C_T(groupId, categoryId, threadId,
10397                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10398            }
10399    
10400            /**
10401             * 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;.
10402             *
10403             * <p>
10404             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10405             * </p>
10406             *
10407             * @param groupId the group ID
10408             * @param categoryId the category ID
10409             * @param threadId the thread ID
10410             * @param start the lower bound of the range of message-boards messages
10411             * @param end the upper bound of the range of message-boards messages (not inclusive)
10412             * @return the range of matching message-boards messages that the user has permission to view
10413             * @throws SystemException if a system exception occurred
10414             */
10415            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10416                    long threadId, int start, int end) throws SystemException {
10417                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
10418            }
10419    
10420            /**
10421             * 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;.
10422             *
10423             * <p>
10424             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10425             * </p>
10426             *
10427             * @param groupId the group ID
10428             * @param categoryId the category ID
10429             * @param threadId the thread ID
10430             * @param start the lower bound of the range of message-boards messages
10431             * @param end the upper bound of the range of message-boards messages (not inclusive)
10432             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10433             * @return the ordered range of matching message-boards messages that the user has permission to view
10434             * @throws SystemException if a system exception occurred
10435             */
10436            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10437                    long threadId, int start, int end, OrderByComparator orderByComparator)
10438                    throws SystemException {
10439                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10440                            return findByG_C_T(groupId, categoryId, threadId, start, end,
10441                                    orderByComparator);
10442                    }
10443    
10444                    StringBundler query = null;
10445    
10446                    if (orderByComparator != null) {
10447                            query = new StringBundler(5 +
10448                                            (orderByComparator.getOrderByFields().length * 3));
10449                    }
10450                    else {
10451                            query = new StringBundler(5);
10452                    }
10453    
10454                    if (getDB().isSupportsInlineDistinct()) {
10455                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10456                    }
10457                    else {
10458                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10459                    }
10460    
10461                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10462    
10463                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10464    
10465                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10466    
10467                    if (!getDB().isSupportsInlineDistinct()) {
10468                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10469                    }
10470    
10471                    if (orderByComparator != null) {
10472                            if (getDB().isSupportsInlineDistinct()) {
10473                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10474                                            orderByComparator);
10475                            }
10476                            else {
10477                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10478                                            orderByComparator);
10479                            }
10480                    }
10481    
10482                    else {
10483                            if (getDB().isSupportsInlineDistinct()) {
10484                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10485                            }
10486                            else {
10487                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10488                            }
10489                    }
10490    
10491                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10492                                    MBMessage.class.getName(),
10493                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10494    
10495                    Session session = null;
10496    
10497                    try {
10498                            session = openSession();
10499    
10500                            SQLQuery q = session.createSQLQuery(sql);
10501    
10502                            if (getDB().isSupportsInlineDistinct()) {
10503                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10504                            }
10505                            else {
10506                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10507                            }
10508    
10509                            QueryPos qPos = QueryPos.getInstance(q);
10510    
10511                            qPos.add(groupId);
10512    
10513                            qPos.add(categoryId);
10514    
10515                            qPos.add(threadId);
10516    
10517                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
10518                    }
10519                    catch (Exception e) {
10520                            throw processException(e);
10521                    }
10522                    finally {
10523                            closeSession(session);
10524                    }
10525            }
10526    
10527            /**
10528             * 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;.
10529             *
10530             * @param messageId the primary key of the current message-boards message
10531             * @param groupId the group ID
10532             * @param categoryId the category ID
10533             * @param threadId the thread ID
10534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10535             * @return the previous, current, and next message-boards message
10536             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10537             * @throws SystemException if a system exception occurred
10538             */
10539            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
10540                    long groupId, long categoryId, long threadId,
10541                    OrderByComparator orderByComparator)
10542                    throws NoSuchMessageException, SystemException {
10543                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10544                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
10545                                    threadId, orderByComparator);
10546                    }
10547    
10548                    MBMessage mbMessage = findByPrimaryKey(messageId);
10549    
10550                    Session session = null;
10551    
10552                    try {
10553                            session = openSession();
10554    
10555                            MBMessage[] array = new MBMessageImpl[3];
10556    
10557                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
10558                                            groupId, categoryId, threadId, orderByComparator, true);
10559    
10560                            array[1] = mbMessage;
10561    
10562                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
10563                                            groupId, categoryId, threadId, orderByComparator, false);
10564    
10565                            return array;
10566                    }
10567                    catch (Exception e) {
10568                            throw processException(e);
10569                    }
10570                    finally {
10571                            closeSession(session);
10572                    }
10573            }
10574    
10575            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
10576                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
10577                    OrderByComparator orderByComparator, boolean previous) {
10578                    StringBundler query = null;
10579    
10580                    if (orderByComparator != null) {
10581                            query = new StringBundler(6 +
10582                                            (orderByComparator.getOrderByFields().length * 6));
10583                    }
10584                    else {
10585                            query = new StringBundler(3);
10586                    }
10587    
10588                    if (getDB().isSupportsInlineDistinct()) {
10589                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10590                    }
10591                    else {
10592                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10593                    }
10594    
10595                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10596    
10597                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10598    
10599                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10600    
10601                    if (!getDB().isSupportsInlineDistinct()) {
10602                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10603                    }
10604    
10605                    if (orderByComparator != null) {
10606                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10607    
10608                            if (orderByConditionFields.length > 0) {
10609                                    query.append(WHERE_AND);
10610                            }
10611    
10612                            for (int i = 0; i < orderByConditionFields.length; i++) {
10613                                    if (getDB().isSupportsInlineDistinct()) {
10614                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10615                                    }
10616                                    else {
10617                                            query.append(_ORDER_BY_ENTITY_TABLE);
10618                                    }
10619    
10620                                    query.append(orderByConditionFields[i]);
10621    
10622                                    if ((i + 1) < orderByConditionFields.length) {
10623                                            if (orderByComparator.isAscending() ^ previous) {
10624                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10625                                            }
10626                                            else {
10627                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10628                                            }
10629                                    }
10630                                    else {
10631                                            if (orderByComparator.isAscending() ^ previous) {
10632                                                    query.append(WHERE_GREATER_THAN);
10633                                            }
10634                                            else {
10635                                                    query.append(WHERE_LESSER_THAN);
10636                                            }
10637                                    }
10638                            }
10639    
10640                            query.append(ORDER_BY_CLAUSE);
10641    
10642                            String[] orderByFields = orderByComparator.getOrderByFields();
10643    
10644                            for (int i = 0; i < orderByFields.length; i++) {
10645                                    if (getDB().isSupportsInlineDistinct()) {
10646                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10647                                    }
10648                                    else {
10649                                            query.append(_ORDER_BY_ENTITY_TABLE);
10650                                    }
10651    
10652                                    query.append(orderByFields[i]);
10653    
10654                                    if ((i + 1) < orderByFields.length) {
10655                                            if (orderByComparator.isAscending() ^ previous) {
10656                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10657                                            }
10658                                            else {
10659                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10660                                            }
10661                                    }
10662                                    else {
10663                                            if (orderByComparator.isAscending() ^ previous) {
10664                                                    query.append(ORDER_BY_ASC);
10665                                            }
10666                                            else {
10667                                                    query.append(ORDER_BY_DESC);
10668                                            }
10669                                    }
10670                            }
10671                    }
10672    
10673                    else {
10674                            if (getDB().isSupportsInlineDistinct()) {
10675                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10676                            }
10677                            else {
10678                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10679                            }
10680                    }
10681    
10682                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10683                                    MBMessage.class.getName(),
10684                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10685    
10686                    SQLQuery q = session.createSQLQuery(sql);
10687    
10688                    q.setFirstResult(0);
10689                    q.setMaxResults(2);
10690    
10691                    if (getDB().isSupportsInlineDistinct()) {
10692                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10693                    }
10694                    else {
10695                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10696                    }
10697    
10698                    QueryPos qPos = QueryPos.getInstance(q);
10699    
10700                    qPos.add(groupId);
10701    
10702                    qPos.add(categoryId);
10703    
10704                    qPos.add(threadId);
10705    
10706                    if (orderByComparator != null) {
10707                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10708    
10709                            for (Object value : values) {
10710                                    qPos.add(value);
10711                            }
10712                    }
10713    
10714                    List<MBMessage> list = q.list();
10715    
10716                    if (list.size() == 2) {
10717                            return list.get(1);
10718                    }
10719                    else {
10720                            return null;
10721                    }
10722            }
10723    
10724            /**
10725             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10726             *
10727             * @param groupId the group ID
10728             * @param categoryId the category ID
10729             * @param status the status
10730             * @return the matching message-boards messages
10731             * @throws SystemException if a system exception occurred
10732             */
10733            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
10734                    throws SystemException {
10735                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
10736                            QueryUtil.ALL_POS, null);
10737            }
10738    
10739            /**
10740             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10741             *
10742             * <p>
10743             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10744             * </p>
10745             *
10746             * @param groupId the group ID
10747             * @param categoryId the category ID
10748             * @param status the status
10749             * @param start the lower bound of the range of message-boards messages
10750             * @param end the upper bound of the range of message-boards messages (not inclusive)
10751             * @return the range of matching message-boards messages
10752             * @throws SystemException if a system exception occurred
10753             */
10754            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
10755                    int status, int start, int end) throws SystemException {
10756                    return findByG_C_S(groupId, categoryId, status, start, end, null);
10757            }
10758    
10759            /**
10760             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10761             *
10762             * <p>
10763             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10764             * </p>
10765             *
10766             * @param groupId the group ID
10767             * @param categoryId the category ID
10768             * @param status the status
10769             * @param start the lower bound of the range of message-boards messages
10770             * @param end the upper bound of the range of message-boards messages (not inclusive)
10771             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10772             * @return the ordered range of matching message-boards messages
10773             * @throws SystemException if a system exception occurred
10774             */
10775            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
10776                    int status, int start, int end, OrderByComparator orderByComparator)
10777                    throws SystemException {
10778                    FinderPath finderPath = null;
10779                    Object[] finderArgs = null;
10780    
10781                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10782                                    (orderByComparator == null)) {
10783                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
10784                            finderArgs = new Object[] { groupId, categoryId, status };
10785                    }
10786                    else {
10787                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
10788                            finderArgs = new Object[] {
10789                                            groupId, categoryId, status,
10790                                            
10791                                            start, end, orderByComparator
10792                                    };
10793                    }
10794    
10795                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10796                                    finderArgs, this);
10797    
10798                    if ((list != null) && !list.isEmpty()) {
10799                            for (MBMessage mbMessage : list) {
10800                                    if ((groupId != mbMessage.getGroupId()) ||
10801                                                    (categoryId != mbMessage.getCategoryId()) ||
10802                                                    (status != mbMessage.getStatus())) {
10803                                            list = null;
10804    
10805                                            break;
10806                                    }
10807                            }
10808                    }
10809    
10810                    if (list == null) {
10811                            StringBundler query = null;
10812    
10813                            if (orderByComparator != null) {
10814                                    query = new StringBundler(5 +
10815                                                    (orderByComparator.getOrderByFields().length * 3));
10816                            }
10817                            else {
10818                                    query = new StringBundler(5);
10819                            }
10820    
10821                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10822    
10823                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10824    
10825                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10826    
10827                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10828    
10829                            if (orderByComparator != null) {
10830                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10831                                            orderByComparator);
10832                            }
10833    
10834                            else {
10835                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10836                            }
10837    
10838                            String sql = query.toString();
10839    
10840                            Session session = null;
10841    
10842                            try {
10843                                    session = openSession();
10844    
10845                                    Query q = session.createQuery(sql);
10846    
10847                                    QueryPos qPos = QueryPos.getInstance(q);
10848    
10849                                    qPos.add(groupId);
10850    
10851                                    qPos.add(categoryId);
10852    
10853                                    qPos.add(status);
10854    
10855                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
10856                                                    end);
10857                            }
10858                            catch (Exception e) {
10859                                    throw processException(e);
10860                            }
10861                            finally {
10862                                    if (list == null) {
10863                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
10864                                    }
10865                                    else {
10866                                            cacheResult(list);
10867    
10868                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
10869                                    }
10870    
10871                                    closeSession(session);
10872                            }
10873                    }
10874    
10875                    return list;
10876            }
10877    
10878            /**
10879             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
10880             *
10881             * <p>
10882             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10883             * </p>
10884             *
10885             * @param groupId the group ID
10886             * @param categoryId the category ID
10887             * @param status the status
10888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10889             * @return the first matching message-boards message
10890             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10891             * @throws SystemException if a system exception occurred
10892             */
10893            public MBMessage findByG_C_S_First(long groupId, long categoryId,
10894                    int status, OrderByComparator orderByComparator)
10895                    throws NoSuchMessageException, SystemException {
10896                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
10897                                    orderByComparator);
10898    
10899                    if (list.isEmpty()) {
10900                            StringBundler msg = new StringBundler(8);
10901    
10902                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10903    
10904                            msg.append("groupId=");
10905                            msg.append(groupId);
10906    
10907                            msg.append(", categoryId=");
10908                            msg.append(categoryId);
10909    
10910                            msg.append(", status=");
10911                            msg.append(status);
10912    
10913                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10914    
10915                            throw new NoSuchMessageException(msg.toString());
10916                    }
10917                    else {
10918                            return list.get(0);
10919                    }
10920            }
10921    
10922            /**
10923             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
10924             *
10925             * <p>
10926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10927             * </p>
10928             *
10929             * @param groupId the group ID
10930             * @param categoryId the category ID
10931             * @param status the status
10932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10933             * @return the last matching message-boards message
10934             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10935             * @throws SystemException if a system exception occurred
10936             */
10937            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
10938                    int status, OrderByComparator orderByComparator)
10939                    throws NoSuchMessageException, SystemException {
10940                    int count = countByG_C_S(groupId, categoryId, status);
10941    
10942                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
10943                                    count - 1, count, orderByComparator);
10944    
10945                    if (list.isEmpty()) {
10946                            StringBundler msg = new StringBundler(8);
10947    
10948                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10949    
10950                            msg.append("groupId=");
10951                            msg.append(groupId);
10952    
10953                            msg.append(", categoryId=");
10954                            msg.append(categoryId);
10955    
10956                            msg.append(", status=");
10957                            msg.append(status);
10958    
10959                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10960    
10961                            throw new NoSuchMessageException(msg.toString());
10962                    }
10963                    else {
10964                            return list.get(0);
10965                    }
10966            }
10967    
10968            /**
10969             * 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;.
10970             *
10971             * <p>
10972             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10973             * </p>
10974             *
10975             * @param messageId the primary key of the current message-boards message
10976             * @param groupId the group ID
10977             * @param categoryId the category ID
10978             * @param status the status
10979             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10980             * @return the previous, current, and next message-boards message
10981             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10982             * @throws SystemException if a system exception occurred
10983             */
10984            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
10985                    long categoryId, int status, OrderByComparator orderByComparator)
10986                    throws NoSuchMessageException, SystemException {
10987                    MBMessage mbMessage = findByPrimaryKey(messageId);
10988    
10989                    Session session = null;
10990    
10991                    try {
10992                            session = openSession();
10993    
10994                            MBMessage[] array = new MBMessageImpl[3];
10995    
10996                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
10997                                            categoryId, status, orderByComparator, true);
10998    
10999                            array[1] = mbMessage;
11000    
11001                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
11002                                            categoryId, status, orderByComparator, false);
11003    
11004                            return array;
11005                    }
11006                    catch (Exception e) {
11007                            throw processException(e);
11008                    }
11009                    finally {
11010                            closeSession(session);
11011                    }
11012            }
11013    
11014            protected MBMessage getByG_C_S_PrevAndNext(Session session,
11015                    MBMessage mbMessage, long groupId, long categoryId, int status,
11016                    OrderByComparator orderByComparator, boolean previous) {
11017                    StringBundler query = null;
11018    
11019                    if (orderByComparator != null) {
11020                            query = new StringBundler(6 +
11021                                            (orderByComparator.getOrderByFields().length * 6));
11022                    }
11023                    else {
11024                            query = new StringBundler(3);
11025                    }
11026    
11027                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11028    
11029                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11030    
11031                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11032    
11033                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11034    
11035                    if (orderByComparator != null) {
11036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11037    
11038                            if (orderByConditionFields.length > 0) {
11039                                    query.append(WHERE_AND);
11040                            }
11041    
11042                            for (int i = 0; i < orderByConditionFields.length; i++) {
11043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11044                                    query.append(orderByConditionFields[i]);
11045    
11046                                    if ((i + 1) < orderByConditionFields.length) {
11047                                            if (orderByComparator.isAscending() ^ previous) {
11048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11049                                            }
11050                                            else {
11051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11052                                            }
11053                                    }
11054                                    else {
11055                                            if (orderByComparator.isAscending() ^ previous) {
11056                                                    query.append(WHERE_GREATER_THAN);
11057                                            }
11058                                            else {
11059                                                    query.append(WHERE_LESSER_THAN);
11060                                            }
11061                                    }
11062                            }
11063    
11064                            query.append(ORDER_BY_CLAUSE);
11065    
11066                            String[] orderByFields = orderByComparator.getOrderByFields();
11067    
11068                            for (int i = 0; i < orderByFields.length; i++) {
11069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11070                                    query.append(orderByFields[i]);
11071    
11072                                    if ((i + 1) < orderByFields.length) {
11073                                            if (orderByComparator.isAscending() ^ previous) {
11074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11075                                            }
11076                                            else {
11077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11078                                            }
11079                                    }
11080                                    else {
11081                                            if (orderByComparator.isAscending() ^ previous) {
11082                                                    query.append(ORDER_BY_ASC);
11083                                            }
11084                                            else {
11085                                                    query.append(ORDER_BY_DESC);
11086                                            }
11087                                    }
11088                            }
11089                    }
11090    
11091                    else {
11092                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11093                    }
11094    
11095                    String sql = query.toString();
11096    
11097                    Query q = session.createQuery(sql);
11098    
11099                    q.setFirstResult(0);
11100                    q.setMaxResults(2);
11101    
11102                    QueryPos qPos = QueryPos.getInstance(q);
11103    
11104                    qPos.add(groupId);
11105    
11106                    qPos.add(categoryId);
11107    
11108                    qPos.add(status);
11109    
11110                    if (orderByComparator != null) {
11111                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11112    
11113                            for (Object value : values) {
11114                                    qPos.add(value);
11115                            }
11116                    }
11117    
11118                    List<MBMessage> list = q.list();
11119    
11120                    if (list.size() == 2) {
11121                            return list.get(1);
11122                    }
11123                    else {
11124                            return null;
11125                    }
11126            }
11127    
11128            /**
11129             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
11130             *
11131             * @param groupId the group ID
11132             * @param categoryId the category ID
11133             * @param status the status
11134             * @return the matching message-boards messages that the user has permission to view
11135             * @throws SystemException if a system exception occurred
11136             */
11137            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11138                    int status) throws SystemException {
11139                    return filterFindByG_C_S(groupId, categoryId, status,
11140                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11141            }
11142    
11143            /**
11144             * 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;.
11145             *
11146             * <p>
11147             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11148             * </p>
11149             *
11150             * @param groupId the group ID
11151             * @param categoryId the category ID
11152             * @param status the status
11153             * @param start the lower bound of the range of message-boards messages
11154             * @param end the upper bound of the range of message-boards messages (not inclusive)
11155             * @return the range of matching message-boards messages that the user has permission to view
11156             * @throws SystemException if a system exception occurred
11157             */
11158            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11159                    int status, int start, int end) throws SystemException {
11160                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
11161            }
11162    
11163            /**
11164             * 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;.
11165             *
11166             * <p>
11167             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11168             * </p>
11169             *
11170             * @param groupId the group ID
11171             * @param categoryId the category ID
11172             * @param status the status
11173             * @param start the lower bound of the range of message-boards messages
11174             * @param end the upper bound of the range of message-boards messages (not inclusive)
11175             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11176             * @return the ordered range of matching message-boards messages that the user has permission to view
11177             * @throws SystemException if a system exception occurred
11178             */
11179            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
11180                    int status, int start, int end, OrderByComparator orderByComparator)
11181                    throws SystemException {
11182                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11183                            return findByG_C_S(groupId, categoryId, status, start, end,
11184                                    orderByComparator);
11185                    }
11186    
11187                    StringBundler query = null;
11188    
11189                    if (orderByComparator != null) {
11190                            query = new StringBundler(5 +
11191                                            (orderByComparator.getOrderByFields().length * 3));
11192                    }
11193                    else {
11194                            query = new StringBundler(5);
11195                    }
11196    
11197                    if (getDB().isSupportsInlineDistinct()) {
11198                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11199                    }
11200                    else {
11201                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11202                    }
11203    
11204                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11205    
11206                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11207    
11208                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11209    
11210                    if (!getDB().isSupportsInlineDistinct()) {
11211                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11212                    }
11213    
11214                    if (orderByComparator != null) {
11215                            if (getDB().isSupportsInlineDistinct()) {
11216                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11217                                            orderByComparator);
11218                            }
11219                            else {
11220                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11221                                            orderByComparator);
11222                            }
11223                    }
11224    
11225                    else {
11226                            if (getDB().isSupportsInlineDistinct()) {
11227                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11228                            }
11229                            else {
11230                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11231                            }
11232                    }
11233    
11234                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11235                                    MBMessage.class.getName(),
11236                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11237    
11238                    Session session = null;
11239    
11240                    try {
11241                            session = openSession();
11242    
11243                            SQLQuery q = session.createSQLQuery(sql);
11244    
11245                            if (getDB().isSupportsInlineDistinct()) {
11246                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11247                            }
11248                            else {
11249                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11250                            }
11251    
11252                            QueryPos qPos = QueryPos.getInstance(q);
11253    
11254                            qPos.add(groupId);
11255    
11256                            qPos.add(categoryId);
11257    
11258                            qPos.add(status);
11259    
11260                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11261                    }
11262                    catch (Exception e) {
11263                            throw processException(e);
11264                    }
11265                    finally {
11266                            closeSession(session);
11267                    }
11268            }
11269    
11270            /**
11271             * 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;.
11272             *
11273             * @param messageId the primary key of the current message-boards message
11274             * @param groupId the group ID
11275             * @param categoryId the category ID
11276             * @param status the status
11277             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11278             * @return the previous, current, and next message-boards message
11279             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11280             * @throws SystemException if a system exception occurred
11281             */
11282            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
11283                    long groupId, long categoryId, int status,
11284                    OrderByComparator orderByComparator)
11285                    throws NoSuchMessageException, SystemException {
11286                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11287                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
11288                                    status, orderByComparator);
11289                    }
11290    
11291                    MBMessage mbMessage = findByPrimaryKey(messageId);
11292    
11293                    Session session = null;
11294    
11295                    try {
11296                            session = openSession();
11297    
11298                            MBMessage[] array = new MBMessageImpl[3];
11299    
11300                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11301                                            groupId, categoryId, status, orderByComparator, true);
11302    
11303                            array[1] = mbMessage;
11304    
11305                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11306                                            groupId, categoryId, status, orderByComparator, false);
11307    
11308                            return array;
11309                    }
11310                    catch (Exception e) {
11311                            throw processException(e);
11312                    }
11313                    finally {
11314                            closeSession(session);
11315                    }
11316            }
11317    
11318            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
11319                    MBMessage mbMessage, long groupId, long categoryId, int status,
11320                    OrderByComparator orderByComparator, boolean previous) {
11321                    StringBundler query = null;
11322    
11323                    if (orderByComparator != null) {
11324                            query = new StringBundler(6 +
11325                                            (orderByComparator.getOrderByFields().length * 6));
11326                    }
11327                    else {
11328                            query = new StringBundler(3);
11329                    }
11330    
11331                    if (getDB().isSupportsInlineDistinct()) {
11332                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11333                    }
11334                    else {
11335                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11336                    }
11337    
11338                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11339    
11340                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11341    
11342                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11343    
11344                    if (!getDB().isSupportsInlineDistinct()) {
11345                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11346                    }
11347    
11348                    if (orderByComparator != null) {
11349                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11350    
11351                            if (orderByConditionFields.length > 0) {
11352                                    query.append(WHERE_AND);
11353                            }
11354    
11355                            for (int i = 0; i < orderByConditionFields.length; i++) {
11356                                    if (getDB().isSupportsInlineDistinct()) {
11357                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11358                                    }
11359                                    else {
11360                                            query.append(_ORDER_BY_ENTITY_TABLE);
11361                                    }
11362    
11363                                    query.append(orderByConditionFields[i]);
11364    
11365                                    if ((i + 1) < orderByConditionFields.length) {
11366                                            if (orderByComparator.isAscending() ^ previous) {
11367                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11368                                            }
11369                                            else {
11370                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11371                                            }
11372                                    }
11373                                    else {
11374                                            if (orderByComparator.isAscending() ^ previous) {
11375                                                    query.append(WHERE_GREATER_THAN);
11376                                            }
11377                                            else {
11378                                                    query.append(WHERE_LESSER_THAN);
11379                                            }
11380                                    }
11381                            }
11382    
11383                            query.append(ORDER_BY_CLAUSE);
11384    
11385                            String[] orderByFields = orderByComparator.getOrderByFields();
11386    
11387                            for (int i = 0; i < orderByFields.length; i++) {
11388                                    if (getDB().isSupportsInlineDistinct()) {
11389                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11390                                    }
11391                                    else {
11392                                            query.append(_ORDER_BY_ENTITY_TABLE);
11393                                    }
11394    
11395                                    query.append(orderByFields[i]);
11396    
11397                                    if ((i + 1) < orderByFields.length) {
11398                                            if (orderByComparator.isAscending() ^ previous) {
11399                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11400                                            }
11401                                            else {
11402                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11403                                            }
11404                                    }
11405                                    else {
11406                                            if (orderByComparator.isAscending() ^ previous) {
11407                                                    query.append(ORDER_BY_ASC);
11408                                            }
11409                                            else {
11410                                                    query.append(ORDER_BY_DESC);
11411                                            }
11412                                    }
11413                            }
11414                    }
11415    
11416                    else {
11417                            if (getDB().isSupportsInlineDistinct()) {
11418                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11419                            }
11420                            else {
11421                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11422                            }
11423                    }
11424    
11425                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11426                                    MBMessage.class.getName(),
11427                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11428    
11429                    SQLQuery q = session.createSQLQuery(sql);
11430    
11431                    q.setFirstResult(0);
11432                    q.setMaxResults(2);
11433    
11434                    if (getDB().isSupportsInlineDistinct()) {
11435                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11436                    }
11437                    else {
11438                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11439                    }
11440    
11441                    QueryPos qPos = QueryPos.getInstance(q);
11442    
11443                    qPos.add(groupId);
11444    
11445                    qPos.add(categoryId);
11446    
11447                    qPos.add(status);
11448    
11449                    if (orderByComparator != null) {
11450                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11451    
11452                            for (Object value : values) {
11453                                    qPos.add(value);
11454                            }
11455                    }
11456    
11457                    List<MBMessage> list = q.list();
11458    
11459                    if (list.size() == 2) {
11460                            return list.get(1);
11461                    }
11462                    else {
11463                            return null;
11464                    }
11465            }
11466    
11467            /**
11468             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11469             *
11470             * @param userId the user ID
11471             * @param classNameId the class name ID
11472             * @param classPK the class p k
11473             * @return the matching message-boards messages
11474             * @throws SystemException if a system exception occurred
11475             */
11476            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11477                    long classPK) throws SystemException {
11478                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
11479                            QueryUtil.ALL_POS, null);
11480            }
11481    
11482            /**
11483             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11484             *
11485             * <p>
11486             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11487             * </p>
11488             *
11489             * @param userId the user ID
11490             * @param classNameId the class name ID
11491             * @param classPK the class p k
11492             * @param start the lower bound of the range of message-boards messages
11493             * @param end the upper bound of the range of message-boards messages (not inclusive)
11494             * @return the range of matching message-boards messages
11495             * @throws SystemException if a system exception occurred
11496             */
11497            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11498                    long classPK, int start, int end) throws SystemException {
11499                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
11500            }
11501    
11502            /**
11503             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11504             *
11505             * <p>
11506             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11507             * </p>
11508             *
11509             * @param userId the user ID
11510             * @param classNameId the class name ID
11511             * @param classPK the class p k
11512             * @param start the lower bound of the range of message-boards messages
11513             * @param end the upper bound of the range of message-boards messages (not inclusive)
11514             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11515             * @return the ordered range of matching message-boards messages
11516             * @throws SystemException if a system exception occurred
11517             */
11518            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11519                    long classPK, int start, int end, OrderByComparator orderByComparator)
11520                    throws SystemException {
11521                    FinderPath finderPath = null;
11522                    Object[] finderArgs = null;
11523    
11524                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11525                                    (orderByComparator == null)) {
11526                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
11527                            finderArgs = new Object[] { userId, classNameId, classPK };
11528                    }
11529                    else {
11530                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
11531                            finderArgs = new Object[] {
11532                                            userId, classNameId, classPK,
11533                                            
11534                                            start, end, orderByComparator
11535                                    };
11536                    }
11537    
11538                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11539                                    finderArgs, this);
11540    
11541                    if ((list != null) && !list.isEmpty()) {
11542                            for (MBMessage mbMessage : list) {
11543                                    if ((userId != mbMessage.getUserId()) ||
11544                                                    (classNameId != mbMessage.getClassNameId()) ||
11545                                                    (classPK != mbMessage.getClassPK())) {
11546                                            list = null;
11547    
11548                                            break;
11549                                    }
11550                            }
11551                    }
11552    
11553                    if (list == null) {
11554                            StringBundler query = null;
11555    
11556                            if (orderByComparator != null) {
11557                                    query = new StringBundler(5 +
11558                                                    (orderByComparator.getOrderByFields().length * 3));
11559                            }
11560                            else {
11561                                    query = new StringBundler(5);
11562                            }
11563    
11564                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11565    
11566                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
11567    
11568                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
11569    
11570                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
11571    
11572                            if (orderByComparator != null) {
11573                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11574                                            orderByComparator);
11575                            }
11576    
11577                            else {
11578                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11579                            }
11580    
11581                            String sql = query.toString();
11582    
11583                            Session session = null;
11584    
11585                            try {
11586                                    session = openSession();
11587    
11588                                    Query q = session.createQuery(sql);
11589    
11590                                    QueryPos qPos = QueryPos.getInstance(q);
11591    
11592                                    qPos.add(userId);
11593    
11594                                    qPos.add(classNameId);
11595    
11596                                    qPos.add(classPK);
11597    
11598                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11599                                                    end);
11600                            }
11601                            catch (Exception e) {
11602                                    throw processException(e);
11603                            }
11604                            finally {
11605                                    if (list == null) {
11606                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11607                                    }
11608                                    else {
11609                                            cacheResult(list);
11610    
11611                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11612                                    }
11613    
11614                                    closeSession(session);
11615                            }
11616                    }
11617    
11618                    return list;
11619            }
11620    
11621            /**
11622             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11623             *
11624             * <p>
11625             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11626             * </p>
11627             *
11628             * @param userId the user ID
11629             * @param classNameId the class name ID
11630             * @param classPK the class p k
11631             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11632             * @return the first matching message-boards message
11633             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11634             * @throws SystemException if a system exception occurred
11635             */
11636            public MBMessage findByU_C_C_First(long userId, long classNameId,
11637                    long classPK, OrderByComparator orderByComparator)
11638                    throws NoSuchMessageException, SystemException {
11639                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
11640                                    orderByComparator);
11641    
11642                    if (list.isEmpty()) {
11643                            StringBundler msg = new StringBundler(8);
11644    
11645                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11646    
11647                            msg.append("userId=");
11648                            msg.append(userId);
11649    
11650                            msg.append(", classNameId=");
11651                            msg.append(classNameId);
11652    
11653                            msg.append(", classPK=");
11654                            msg.append(classPK);
11655    
11656                            msg.append(StringPool.CLOSE_CURLY_BRACE);
11657    
11658                            throw new NoSuchMessageException(msg.toString());
11659                    }
11660                    else {
11661                            return list.get(0);
11662                    }
11663            }
11664    
11665            /**
11666             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11667             *
11668             * <p>
11669             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11670             * </p>
11671             *
11672             * @param userId the user ID
11673             * @param classNameId the class name ID
11674             * @param classPK the class p k
11675             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11676             * @return the last matching message-boards message
11677             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11678             * @throws SystemException if a system exception occurred
11679             */
11680            public MBMessage findByU_C_C_Last(long userId, long classNameId,
11681                    long classPK, OrderByComparator orderByComparator)
11682                    throws NoSuchMessageException, SystemException {
11683                    int count = countByU_C_C(userId, classNameId, classPK);
11684    
11685                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
11686                                    count - 1, count, orderByComparator);
11687    
11688                    if (list.isEmpty()) {
11689                            StringBundler msg = new StringBundler(8);
11690    
11691                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11692    
11693                            msg.append("userId=");
11694                            msg.append(userId);
11695    
11696                            msg.append(", classNameId=");
11697                            msg.append(classNameId);
11698    
11699                            msg.append(", classPK=");
11700                            msg.append(classPK);
11701    
11702                            msg.append(StringPool.CLOSE_CURLY_BRACE);
11703    
11704                            throw new NoSuchMessageException(msg.toString());
11705                    }
11706                    else {
11707                            return list.get(0);
11708                    }
11709            }
11710    
11711            /**
11712             * 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;.
11713             *
11714             * <p>
11715             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11716             * </p>
11717             *
11718             * @param messageId the primary key of the current message-boards message
11719             * @param userId the user ID
11720             * @param classNameId the class name ID
11721             * @param classPK the class p k
11722             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11723             * @return the previous, current, and next message-boards message
11724             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11725             * @throws SystemException if a system exception occurred
11726             */
11727            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
11728                    long classNameId, long classPK, OrderByComparator orderByComparator)
11729                    throws NoSuchMessageException, SystemException {
11730                    MBMessage mbMessage = findByPrimaryKey(messageId);
11731    
11732                    Session session = null;
11733    
11734                    try {
11735                            session = openSession();
11736    
11737                            MBMessage[] array = new MBMessageImpl[3];
11738    
11739                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
11740                                            classNameId, classPK, orderByComparator, true);
11741    
11742                            array[1] = mbMessage;
11743    
11744                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
11745                                            classNameId, classPK, orderByComparator, false);
11746    
11747                            return array;
11748                    }
11749                    catch (Exception e) {
11750                            throw processException(e);
11751                    }
11752                    finally {
11753                            closeSession(session);
11754                    }
11755            }
11756    
11757            protected MBMessage getByU_C_C_PrevAndNext(Session session,
11758                    MBMessage mbMessage, long userId, long classNameId, long classPK,
11759                    OrderByComparator orderByComparator, boolean previous) {
11760                    StringBundler query = null;
11761    
11762                    if (orderByComparator != null) {
11763                            query = new StringBundler(6 +
11764                                            (orderByComparator.getOrderByFields().length * 6));
11765                    }
11766                    else {
11767                            query = new StringBundler(3);
11768                    }
11769    
11770                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11771    
11772                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
11773    
11774                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
11775    
11776                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
11777    
11778                    if (orderByComparator != null) {
11779                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11780    
11781                            if (orderByConditionFields.length > 0) {
11782                                    query.append(WHERE_AND);
11783                            }
11784    
11785                            for (int i = 0; i < orderByConditionFields.length; i++) {
11786                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11787                                    query.append(orderByConditionFields[i]);
11788    
11789                                    if ((i + 1) < orderByConditionFields.length) {
11790                                            if (orderByComparator.isAscending() ^ previous) {
11791                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11792                                            }
11793                                            else {
11794                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11795                                            }
11796                                    }
11797                                    else {
11798                                            if (orderByComparator.isAscending() ^ previous) {
11799                                                    query.append(WHERE_GREATER_THAN);
11800                                            }
11801                                            else {
11802                                                    query.append(WHERE_LESSER_THAN);
11803                                            }
11804                                    }
11805                            }
11806    
11807                            query.append(ORDER_BY_CLAUSE);
11808    
11809                            String[] orderByFields = orderByComparator.getOrderByFields();
11810    
11811                            for (int i = 0; i < orderByFields.length; i++) {
11812                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11813                                    query.append(orderByFields[i]);
11814    
11815                                    if ((i + 1) < orderByFields.length) {
11816                                            if (orderByComparator.isAscending() ^ previous) {
11817                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11818                                            }
11819                                            else {
11820                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11821                                            }
11822                                    }
11823                                    else {
11824                                            if (orderByComparator.isAscending() ^ previous) {
11825                                                    query.append(ORDER_BY_ASC);
11826                                            }
11827                                            else {
11828                                                    query.append(ORDER_BY_DESC);
11829                                            }
11830                                    }
11831                            }
11832                    }
11833    
11834                    else {
11835                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11836                    }
11837    
11838                    String sql = query.toString();
11839    
11840                    Query q = session.createQuery(sql);
11841    
11842                    q.setFirstResult(0);
11843                    q.setMaxResults(2);
11844    
11845                    QueryPos qPos = QueryPos.getInstance(q);
11846    
11847                    qPos.add(userId);
11848    
11849                    qPos.add(classNameId);
11850    
11851                    qPos.add(classPK);
11852    
11853                    if (orderByComparator != null) {
11854                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11855    
11856                            for (Object value : values) {
11857                                    qPos.add(value);
11858                            }
11859                    }
11860    
11861                    List<MBMessage> list = q.list();
11862    
11863                    if (list.size() == 2) {
11864                            return list.get(1);
11865                    }
11866                    else {
11867                            return null;
11868                    }
11869            }
11870    
11871            /**
11872             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
11873             *
11874             * @param userId the user ID
11875             * @param classNameId the class name ID
11876             * @param status the status
11877             * @return the matching message-boards messages
11878             * @throws SystemException if a system exception occurred
11879             */
11880            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
11881                    throws SystemException {
11882                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
11883                            QueryUtil.ALL_POS, null);
11884            }
11885    
11886            /**
11887             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
11888             *
11889             * <p>
11890             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11891             * </p>
11892             *
11893             * @param userId the user ID
11894             * @param classNameId the class name ID
11895             * @param status the status
11896             * @param start the lower bound of the range of message-boards messages
11897             * @param end the upper bound of the range of message-boards messages (not inclusive)
11898             * @return the range of matching message-boards messages
11899             * @throws SystemException if a system exception occurred
11900             */
11901            public List<MBMessage> findByU_C_S(long userId, long classNameId,
11902                    int status, int start, int end) throws SystemException {
11903                    return findByU_C_S(userId, classNameId, status, start, end, null);
11904            }
11905    
11906            /**
11907             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
11908             *
11909             * <p>
11910             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11911             * </p>
11912             *
11913             * @param userId the user ID
11914             * @param classNameId the class name ID
11915             * @param status the status
11916             * @param start the lower bound of the range of message-boards messages
11917             * @param end the upper bound of the range of message-boards messages (not inclusive)
11918             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11919             * @return the ordered range of matching message-boards messages
11920             * @throws SystemException if a system exception occurred
11921             */
11922            public List<MBMessage> findByU_C_S(long userId, long classNameId,
11923                    int status, int start, int end, OrderByComparator orderByComparator)
11924                    throws SystemException {
11925                    FinderPath finderPath = null;
11926                    Object[] finderArgs = null;
11927    
11928                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11929                                    (orderByComparator == null)) {
11930                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
11931                            finderArgs = new Object[] { userId, classNameId, status };
11932                    }
11933                    else {
11934                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
11935                            finderArgs = new Object[] {
11936                                            userId, classNameId, status,
11937                                            
11938                                            start, end, orderByComparator
11939                                    };
11940                    }
11941    
11942                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11943                                    finderArgs, this);
11944    
11945                    if ((list != null) && !list.isEmpty()) {
11946                            for (MBMessage mbMessage : list) {
11947                                    if ((userId != mbMessage.getUserId()) ||
11948                                                    (classNameId != mbMessage.getClassNameId()) ||
11949                                                    (status != mbMessage.getStatus())) {
11950                                            list = null;
11951    
11952                                            break;
11953                                    }
11954                            }
11955                    }
11956    
11957                    if (list == null) {
11958                            StringBundler query = null;
11959    
11960                            if (orderByComparator != null) {
11961                                    query = new StringBundler(5 +
11962                                                    (orderByComparator.getOrderByFields().length * 3));
11963                            }
11964                            else {
11965                                    query = new StringBundler(5);
11966                            }
11967    
11968                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11969    
11970                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
11971    
11972                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
11973    
11974                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
11975    
11976                            if (orderByComparator != null) {
11977                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11978                                            orderByComparator);
11979                            }
11980    
11981                            else {
11982                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11983                            }
11984    
11985                            String sql = query.toString();
11986    
11987                            Session session = null;
11988    
11989                            try {
11990                                    session = openSession();
11991    
11992                                    Query q = session.createQuery(sql);
11993    
11994                                    QueryPos qPos = QueryPos.getInstance(q);
11995    
11996                                    qPos.add(userId);
11997    
11998                                    qPos.add(classNameId);
11999    
12000                                    qPos.add(status);
12001    
12002                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12003                                                    end);
12004                            }
12005                            catch (Exception e) {
12006                                    throw processException(e);
12007                            }
12008                            finally {
12009                                    if (list == null) {
12010                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12011                                    }
12012                                    else {
12013                                            cacheResult(list);
12014    
12015                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12016                                    }
12017    
12018                                    closeSession(session);
12019                            }
12020                    }
12021    
12022                    return list;
12023            }
12024    
12025            /**
12026             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12027             *
12028             * <p>
12029             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12030             * </p>
12031             *
12032             * @param userId the user ID
12033             * @param classNameId the class name ID
12034             * @param status the status
12035             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12036             * @return the first matching message-boards message
12037             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12038             * @throws SystemException if a system exception occurred
12039             */
12040            public MBMessage findByU_C_S_First(long userId, long classNameId,
12041                    int status, OrderByComparator orderByComparator)
12042                    throws NoSuchMessageException, SystemException {
12043                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
12044                                    orderByComparator);
12045    
12046                    if (list.isEmpty()) {
12047                            StringBundler msg = new StringBundler(8);
12048    
12049                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12050    
12051                            msg.append("userId=");
12052                            msg.append(userId);
12053    
12054                            msg.append(", classNameId=");
12055                            msg.append(classNameId);
12056    
12057                            msg.append(", status=");
12058                            msg.append(status);
12059    
12060                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12061    
12062                            throw new NoSuchMessageException(msg.toString());
12063                    }
12064                    else {
12065                            return list.get(0);
12066                    }
12067            }
12068    
12069            /**
12070             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
12071             *
12072             * <p>
12073             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12074             * </p>
12075             *
12076             * @param userId the user ID
12077             * @param classNameId the class name ID
12078             * @param status the status
12079             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12080             * @return the last matching message-boards message
12081             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12082             * @throws SystemException if a system exception occurred
12083             */
12084            public MBMessage findByU_C_S_Last(long userId, long classNameId,
12085                    int status, OrderByComparator orderByComparator)
12086                    throws NoSuchMessageException, SystemException {
12087                    int count = countByU_C_S(userId, classNameId, status);
12088    
12089                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
12090                                    count - 1, count, orderByComparator);
12091    
12092                    if (list.isEmpty()) {
12093                            StringBundler msg = new StringBundler(8);
12094    
12095                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12096    
12097                            msg.append("userId=");
12098                            msg.append(userId);
12099    
12100                            msg.append(", classNameId=");
12101                            msg.append(classNameId);
12102    
12103                            msg.append(", status=");
12104                            msg.append(status);
12105    
12106                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12107    
12108                            throw new NoSuchMessageException(msg.toString());
12109                    }
12110                    else {
12111                            return list.get(0);
12112                    }
12113            }
12114    
12115            /**
12116             * 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;.
12117             *
12118             * <p>
12119             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12120             * </p>
12121             *
12122             * @param messageId the primary key of the current message-boards message
12123             * @param userId the user ID
12124             * @param classNameId the class name ID
12125             * @param status the status
12126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12127             * @return the previous, current, and next message-boards message
12128             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12129             * @throws SystemException if a system exception occurred
12130             */
12131            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
12132                    long classNameId, int status, OrderByComparator orderByComparator)
12133                    throws NoSuchMessageException, SystemException {
12134                    MBMessage mbMessage = findByPrimaryKey(messageId);
12135    
12136                    Session session = null;
12137    
12138                    try {
12139                            session = openSession();
12140    
12141                            MBMessage[] array = new MBMessageImpl[3];
12142    
12143                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
12144                                            classNameId, status, orderByComparator, true);
12145    
12146                            array[1] = mbMessage;
12147    
12148                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
12149                                            classNameId, status, orderByComparator, false);
12150    
12151                            return array;
12152                    }
12153                    catch (Exception e) {
12154                            throw processException(e);
12155                    }
12156                    finally {
12157                            closeSession(session);
12158                    }
12159            }
12160    
12161            protected MBMessage getByU_C_S_PrevAndNext(Session session,
12162                    MBMessage mbMessage, long userId, long classNameId, int status,
12163                    OrderByComparator orderByComparator, boolean previous) {
12164                    StringBundler query = null;
12165    
12166                    if (orderByComparator != null) {
12167                            query = new StringBundler(6 +
12168                                            (orderByComparator.getOrderByFields().length * 6));
12169                    }
12170                    else {
12171                            query = new StringBundler(3);
12172                    }
12173    
12174                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12175    
12176                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
12177    
12178                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
12179    
12180                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
12181    
12182                    if (orderByComparator != null) {
12183                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12184    
12185                            if (orderByConditionFields.length > 0) {
12186                                    query.append(WHERE_AND);
12187                            }
12188    
12189                            for (int i = 0; i < orderByConditionFields.length; i++) {
12190                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12191                                    query.append(orderByConditionFields[i]);
12192    
12193                                    if ((i + 1) < orderByConditionFields.length) {
12194                                            if (orderByComparator.isAscending() ^ previous) {
12195                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12196                                            }
12197                                            else {
12198                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12199                                            }
12200                                    }
12201                                    else {
12202                                            if (orderByComparator.isAscending() ^ previous) {
12203                                                    query.append(WHERE_GREATER_THAN);
12204                                            }
12205                                            else {
12206                                                    query.append(WHERE_LESSER_THAN);
12207                                            }
12208                                    }
12209                            }
12210    
12211                            query.append(ORDER_BY_CLAUSE);
12212    
12213                            String[] orderByFields = orderByComparator.getOrderByFields();
12214    
12215                            for (int i = 0; i < orderByFields.length; i++) {
12216                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12217                                    query.append(orderByFields[i]);
12218    
12219                                    if ((i + 1) < orderByFields.length) {
12220                                            if (orderByComparator.isAscending() ^ previous) {
12221                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12222                                            }
12223                                            else {
12224                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12225                                            }
12226                                    }
12227                                    else {
12228                                            if (orderByComparator.isAscending() ^ previous) {
12229                                                    query.append(ORDER_BY_ASC);
12230                                            }
12231                                            else {
12232                                                    query.append(ORDER_BY_DESC);
12233                                            }
12234                                    }
12235                            }
12236                    }
12237    
12238                    else {
12239                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12240                    }
12241    
12242                    String sql = query.toString();
12243    
12244                    Query q = session.createQuery(sql);
12245    
12246                    q.setFirstResult(0);
12247                    q.setMaxResults(2);
12248    
12249                    QueryPos qPos = QueryPos.getInstance(q);
12250    
12251                    qPos.add(userId);
12252    
12253                    qPos.add(classNameId);
12254    
12255                    qPos.add(status);
12256    
12257                    if (orderByComparator != null) {
12258                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12259    
12260                            for (Object value : values) {
12261                                    qPos.add(value);
12262                            }
12263                    }
12264    
12265                    List<MBMessage> list = q.list();
12266    
12267                    if (list.size() == 2) {
12268                            return list.get(1);
12269                    }
12270                    else {
12271                            return null;
12272                    }
12273            }
12274    
12275            /**
12276             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12277             *
12278             * <p>
12279             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12280             * </p>
12281             *
12282             * @param userId the user ID
12283             * @param classNameIds the class name IDs
12284             * @param status the status
12285             * @return the matching message-boards messages
12286             * @throws SystemException if a system exception occurred
12287             */
12288            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12289                    int status) throws SystemException {
12290                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
12291                            QueryUtil.ALL_POS, null);
12292            }
12293    
12294            /**
12295             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12296             *
12297             * <p>
12298             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12299             * </p>
12300             *
12301             * @param userId the user ID
12302             * @param classNameIds the class name IDs
12303             * @param status the status
12304             * @param start the lower bound of the range of message-boards messages
12305             * @param end the upper bound of the range of message-boards messages (not inclusive)
12306             * @return the range of matching message-boards messages
12307             * @throws SystemException if a system exception occurred
12308             */
12309            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12310                    int status, int start, int end) throws SystemException {
12311                    return findByU_C_S(userId, classNameIds, status, start, end, null);
12312            }
12313    
12314            /**
12315             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12316             *
12317             * <p>
12318             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12319             * </p>
12320             *
12321             * @param userId the user ID
12322             * @param classNameIds the class name IDs
12323             * @param status the status
12324             * @param start the lower bound of the range of message-boards messages
12325             * @param end the upper bound of the range of message-boards messages (not inclusive)
12326             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12327             * @return the ordered range of matching message-boards messages
12328             * @throws SystemException if a system exception occurred
12329             */
12330            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12331                    int status, int start, int end, OrderByComparator orderByComparator)
12332                    throws SystemException {
12333                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12334                    Object[] finderArgs = null;
12335    
12336                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12337                                    (orderByComparator == null)) {
12338                            finderArgs = new Object[] {
12339                                            userId, StringUtil.merge(classNameIds), status
12340                                    };
12341                    }
12342                    else {
12343                            finderArgs = new Object[] {
12344                                            userId, StringUtil.merge(classNameIds), status,
12345                                            
12346                                            start, end, orderByComparator
12347                                    };
12348                    }
12349    
12350                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12351                                    finderArgs, this);
12352    
12353                    if ((list != null) && !list.isEmpty()) {
12354                            for (MBMessage mbMessage : list) {
12355                                    if ((userId != mbMessage.getUserId()) ||
12356                                                    !ArrayUtil.contains(classNameIds,
12357                                                            mbMessage.getClassNameId()) ||
12358                                                    (status != mbMessage.getStatus())) {
12359                                            list = null;
12360    
12361                                            break;
12362                                    }
12363                            }
12364                    }
12365    
12366                    if (list == null) {
12367                            StringBundler query = new StringBundler();
12368    
12369                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12370    
12371                            boolean conjunctionable = false;
12372    
12373                            if (conjunctionable) {
12374                                    query.append(WHERE_AND);
12375                            }
12376    
12377                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
12378    
12379                            conjunctionable = true;
12380    
12381                            if ((classNameIds == null) || (classNameIds.length > 0)) {
12382                                    if (conjunctionable) {
12383                                            query.append(WHERE_AND);
12384                                    }
12385    
12386                                    query.append(StringPool.OPEN_PARENTHESIS);
12387    
12388                                    for (int i = 0; i < classNameIds.length; i++) {
12389                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
12390    
12391                                            if ((i + 1) < classNameIds.length) {
12392                                                    query.append(WHERE_OR);
12393                                            }
12394                                    }
12395    
12396                                    query.append(StringPool.CLOSE_PARENTHESIS);
12397    
12398                                    conjunctionable = true;
12399                            }
12400    
12401                            if (conjunctionable) {
12402                                    query.append(WHERE_AND);
12403                            }
12404    
12405                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
12406    
12407                            conjunctionable = true;
12408    
12409                            if (orderByComparator != null) {
12410                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12411                                            orderByComparator);
12412                            }
12413    
12414                            else {
12415                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12416                            }
12417    
12418                            String sql = query.toString();
12419    
12420                            Session session = null;
12421    
12422                            try {
12423                                    session = openSession();
12424    
12425                                    Query q = session.createQuery(sql);
12426    
12427                                    QueryPos qPos = QueryPos.getInstance(q);
12428    
12429                                    qPos.add(userId);
12430    
12431                                    if (classNameIds != null) {
12432                                            qPos.add(classNameIds);
12433                                    }
12434    
12435                                    qPos.add(status);
12436    
12437                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12438                                                    end);
12439                            }
12440                            catch (Exception e) {
12441                                    throw processException(e);
12442                            }
12443                            finally {
12444                                    if (list == null) {
12445                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12446                                    }
12447                                    else {
12448                                            cacheResult(list);
12449    
12450                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12451                                    }
12452    
12453                                    closeSession(session);
12454                            }
12455                    }
12456    
12457                    return list;
12458            }
12459    
12460            /**
12461             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
12462             *
12463             * @param classNameId the class name ID
12464             * @param classPK the class p k
12465             * @param status the status
12466             * @return the matching message-boards messages
12467             * @throws SystemException if a system exception occurred
12468             */
12469            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
12470                    int status) throws SystemException {
12471                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
12472                            QueryUtil.ALL_POS, null);
12473            }
12474    
12475            /**
12476             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
12477             *
12478             * <p>
12479             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12480             * </p>
12481             *
12482             * @param classNameId the class name ID
12483             * @param classPK the class p k
12484             * @param status the status
12485             * @param start the lower bound of the range of message-boards messages
12486             * @param end the upper bound of the range of message-boards messages (not inclusive)
12487             * @return the range of matching message-boards messages
12488             * @throws SystemException if a system exception occurred
12489             */
12490            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
12491                    int status, int start, int end) throws SystemException {
12492                    return findByC_C_S(classNameId, classPK, status, start, end, null);
12493            }
12494    
12495            /**
12496             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
12497             *
12498             * <p>
12499             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12500             * </p>
12501             *
12502             * @param classNameId the class name ID
12503             * @param classPK the class p k
12504             * @param status the status
12505             * @param start the lower bound of the range of message-boards messages
12506             * @param end the upper bound of the range of message-boards messages (not inclusive)
12507             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12508             * @return the ordered range of matching message-boards messages
12509             * @throws SystemException if a system exception occurred
12510             */
12511            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
12512                    int status, int start, int end, OrderByComparator orderByComparator)
12513                    throws SystemException {
12514                    FinderPath finderPath = null;
12515                    Object[] finderArgs = null;
12516    
12517                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12518                                    (orderByComparator == null)) {
12519                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
12520                            finderArgs = new Object[] { classNameId, classPK, status };
12521                    }
12522                    else {
12523                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
12524                            finderArgs = new Object[] {
12525                                            classNameId, classPK, status,
12526                                            
12527                                            start, end, orderByComparator
12528                                    };
12529                    }
12530    
12531                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12532                                    finderArgs, this);
12533    
12534                    if ((list != null) && !list.isEmpty()) {
12535                            for (MBMessage mbMessage : list) {
12536                                    if ((classNameId != mbMessage.getClassNameId()) ||
12537                                                    (classPK != mbMessage.getClassPK()) ||
12538                                                    (status != mbMessage.getStatus())) {
12539                                            list = null;
12540    
12541                                            break;
12542                                    }
12543                            }
12544                    }
12545    
12546                    if (list == null) {
12547                            StringBundler query = null;
12548    
12549                            if (orderByComparator != null) {
12550                                    query = new StringBundler(5 +
12551                                                    (orderByComparator.getOrderByFields().length * 3));
12552                            }
12553                            else {
12554                                    query = new StringBundler(5);
12555                            }
12556    
12557                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12558    
12559                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
12560    
12561                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
12562    
12563                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
12564    
12565                            if (orderByComparator != null) {
12566                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12567                                            orderByComparator);
12568                            }
12569    
12570                            else {
12571                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12572                            }
12573    
12574                            String sql = query.toString();
12575    
12576                            Session session = null;
12577    
12578                            try {
12579                                    session = openSession();
12580    
12581                                    Query q = session.createQuery(sql);
12582    
12583                                    QueryPos qPos = QueryPos.getInstance(q);
12584    
12585                                    qPos.add(classNameId);
12586    
12587                                    qPos.add(classPK);
12588    
12589                                    qPos.add(status);
12590    
12591                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12592                                                    end);
12593                            }
12594                            catch (Exception e) {
12595                                    throw processException(e);
12596                            }
12597                            finally {
12598                                    if (list == null) {
12599                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12600                                    }
12601                                    else {
12602                                            cacheResult(list);
12603    
12604                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12605                                    }
12606    
12607                                    closeSession(session);
12608                            }
12609                    }
12610    
12611                    return list;
12612            }
12613    
12614            /**
12615             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
12616             *
12617             * <p>
12618             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12619             * </p>
12620             *
12621             * @param classNameId the class name ID
12622             * @param classPK the class p k
12623             * @param status the status
12624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12625             * @return the first matching message-boards message
12626             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12627             * @throws SystemException if a system exception occurred
12628             */
12629            public MBMessage findByC_C_S_First(long classNameId, long classPK,
12630                    int status, OrderByComparator orderByComparator)
12631                    throws NoSuchMessageException, SystemException {
12632                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
12633                                    orderByComparator);
12634    
12635                    if (list.isEmpty()) {
12636                            StringBundler msg = new StringBundler(8);
12637    
12638                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12639    
12640                            msg.append("classNameId=");
12641                            msg.append(classNameId);
12642    
12643                            msg.append(", classPK=");
12644                            msg.append(classPK);
12645    
12646                            msg.append(", status=");
12647                            msg.append(status);
12648    
12649                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12650    
12651                            throw new NoSuchMessageException(msg.toString());
12652                    }
12653                    else {
12654                            return list.get(0);
12655                    }
12656            }
12657    
12658            /**
12659             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
12660             *
12661             * <p>
12662             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12663             * </p>
12664             *
12665             * @param classNameId the class name ID
12666             * @param classPK the class p k
12667             * @param status the status
12668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12669             * @return the last matching message-boards message
12670             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12671             * @throws SystemException if a system exception occurred
12672             */
12673            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
12674                    int status, OrderByComparator orderByComparator)
12675                    throws NoSuchMessageException, SystemException {
12676                    int count = countByC_C_S(classNameId, classPK, status);
12677    
12678                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
12679                                    count - 1, count, orderByComparator);
12680    
12681                    if (list.isEmpty()) {
12682                            StringBundler msg = new StringBundler(8);
12683    
12684                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12685    
12686                            msg.append("classNameId=");
12687                            msg.append(classNameId);
12688    
12689                            msg.append(", classPK=");
12690                            msg.append(classPK);
12691    
12692                            msg.append(", status=");
12693                            msg.append(status);
12694    
12695                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12696    
12697                            throw new NoSuchMessageException(msg.toString());
12698                    }
12699                    else {
12700                            return list.get(0);
12701                    }
12702            }
12703    
12704            /**
12705             * 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;.
12706             *
12707             * <p>
12708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12709             * </p>
12710             *
12711             * @param messageId the primary key of the current message-boards message
12712             * @param classNameId the class name ID
12713             * @param classPK the class p k
12714             * @param status the status
12715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12716             * @return the previous, current, and next message-boards message
12717             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12718             * @throws SystemException if a system exception occurred
12719             */
12720            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
12721                    long classNameId, long classPK, int status,
12722                    OrderByComparator orderByComparator)
12723                    throws NoSuchMessageException, SystemException {
12724                    MBMessage mbMessage = findByPrimaryKey(messageId);
12725    
12726                    Session session = null;
12727    
12728                    try {
12729                            session = openSession();
12730    
12731                            MBMessage[] array = new MBMessageImpl[3];
12732    
12733                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
12734                                            classPK, status, orderByComparator, true);
12735    
12736                            array[1] = mbMessage;
12737    
12738                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
12739                                            classPK, status, orderByComparator, false);
12740    
12741                            return array;
12742                    }
12743                    catch (Exception e) {
12744                            throw processException(e);
12745                    }
12746                    finally {
12747                            closeSession(session);
12748                    }
12749            }
12750    
12751            protected MBMessage getByC_C_S_PrevAndNext(Session session,
12752                    MBMessage mbMessage, long classNameId, long classPK, int status,
12753                    OrderByComparator orderByComparator, boolean previous) {
12754                    StringBundler query = null;
12755    
12756                    if (orderByComparator != null) {
12757                            query = new StringBundler(6 +
12758                                            (orderByComparator.getOrderByFields().length * 6));
12759                    }
12760                    else {
12761                            query = new StringBundler(3);
12762                    }
12763    
12764                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12765    
12766                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
12767    
12768                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
12769    
12770                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
12771    
12772                    if (orderByComparator != null) {
12773                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12774    
12775                            if (orderByConditionFields.length > 0) {
12776                                    query.append(WHERE_AND);
12777                            }
12778    
12779                            for (int i = 0; i < orderByConditionFields.length; i++) {
12780                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12781                                    query.append(orderByConditionFields[i]);
12782    
12783                                    if ((i + 1) < orderByConditionFields.length) {
12784                                            if (orderByComparator.isAscending() ^ previous) {
12785                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12786                                            }
12787                                            else {
12788                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12789                                            }
12790                                    }
12791                                    else {
12792                                            if (orderByComparator.isAscending() ^ previous) {
12793                                                    query.append(WHERE_GREATER_THAN);
12794                                            }
12795                                            else {
12796                                                    query.append(WHERE_LESSER_THAN);
12797                                            }
12798                                    }
12799                            }
12800    
12801                            query.append(ORDER_BY_CLAUSE);
12802    
12803                            String[] orderByFields = orderByComparator.getOrderByFields();
12804    
12805                            for (int i = 0; i < orderByFields.length; i++) {
12806                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12807                                    query.append(orderByFields[i]);
12808    
12809                                    if ((i + 1) < orderByFields.length) {
12810                                            if (orderByComparator.isAscending() ^ previous) {
12811                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12812                                            }
12813                                            else {
12814                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12815                                            }
12816                                    }
12817                                    else {
12818                                            if (orderByComparator.isAscending() ^ previous) {
12819                                                    query.append(ORDER_BY_ASC);
12820                                            }
12821                                            else {
12822                                                    query.append(ORDER_BY_DESC);
12823                                            }
12824                                    }
12825                            }
12826                    }
12827    
12828                    else {
12829                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12830                    }
12831    
12832                    String sql = query.toString();
12833    
12834                    Query q = session.createQuery(sql);
12835    
12836                    q.setFirstResult(0);
12837                    q.setMaxResults(2);
12838    
12839                    QueryPos qPos = QueryPos.getInstance(q);
12840    
12841                    qPos.add(classNameId);
12842    
12843                    qPos.add(classPK);
12844    
12845                    qPos.add(status);
12846    
12847                    if (orderByComparator != null) {
12848                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12849    
12850                            for (Object value : values) {
12851                                    qPos.add(value);
12852                            }
12853                    }
12854    
12855                    List<MBMessage> list = q.list();
12856    
12857                    if (list.size() == 2) {
12858                            return list.get(1);
12859                    }
12860                    else {
12861                            return null;
12862                    }
12863            }
12864    
12865            /**
12866             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12867             *
12868             * @param groupId the group ID
12869             * @param categoryId the category ID
12870             * @param threadId the thread ID
12871             * @param answer the answer
12872             * @return the matching message-boards messages
12873             * @throws SystemException if a system exception occurred
12874             */
12875            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
12876                    long threadId, boolean answer) throws SystemException {
12877                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
12878                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12879            }
12880    
12881            /**
12882             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12883             *
12884             * <p>
12885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12886             * </p>
12887             *
12888             * @param groupId the group ID
12889             * @param categoryId the category ID
12890             * @param threadId the thread ID
12891             * @param answer the answer
12892             * @param start the lower bound of the range of message-boards messages
12893             * @param end the upper bound of the range of message-boards messages (not inclusive)
12894             * @return the range of matching message-boards messages
12895             * @throws SystemException if a system exception occurred
12896             */
12897            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
12898                    long threadId, boolean answer, int start, int end)
12899                    throws SystemException {
12900                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
12901                            null);
12902            }
12903    
12904            /**
12905             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12906             *
12907             * <p>
12908             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12909             * </p>
12910             *
12911             * @param groupId the group ID
12912             * @param categoryId the category ID
12913             * @param threadId the thread ID
12914             * @param answer the answer
12915             * @param start the lower bound of the range of message-boards messages
12916             * @param end the upper bound of the range of message-boards messages (not inclusive)
12917             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12918             * @return the ordered range of matching message-boards messages
12919             * @throws SystemException if a system exception occurred
12920             */
12921            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
12922                    long threadId, boolean answer, int start, int end,
12923                    OrderByComparator orderByComparator) throws SystemException {
12924                    FinderPath finderPath = null;
12925                    Object[] finderArgs = null;
12926    
12927                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12928                                    (orderByComparator == null)) {
12929                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
12930                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
12931                    }
12932                    else {
12933                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
12934                            finderArgs = new Object[] {
12935                                            groupId, categoryId, threadId, answer,
12936                                            
12937                                            start, end, orderByComparator
12938                                    };
12939                    }
12940    
12941                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12942                                    finderArgs, this);
12943    
12944                    if ((list != null) && !list.isEmpty()) {
12945                            for (MBMessage mbMessage : list) {
12946                                    if ((groupId != mbMessage.getGroupId()) ||
12947                                                    (categoryId != mbMessage.getCategoryId()) ||
12948                                                    (threadId != mbMessage.getThreadId()) ||
12949                                                    (answer != mbMessage.getAnswer())) {
12950                                            list = null;
12951    
12952                                            break;
12953                                    }
12954                            }
12955                    }
12956    
12957                    if (list == null) {
12958                            StringBundler query = null;
12959    
12960                            if (orderByComparator != null) {
12961                                    query = new StringBundler(6 +
12962                                                    (orderByComparator.getOrderByFields().length * 3));
12963                            }
12964                            else {
12965                                    query = new StringBundler(6);
12966                            }
12967    
12968                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12969    
12970                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
12971    
12972                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
12973    
12974                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
12975    
12976                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
12977    
12978                            if (orderByComparator != null) {
12979                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12980                                            orderByComparator);
12981                            }
12982    
12983                            else {
12984                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12985                            }
12986    
12987                            String sql = query.toString();
12988    
12989                            Session session = null;
12990    
12991                            try {
12992                                    session = openSession();
12993    
12994                                    Query q = session.createQuery(sql);
12995    
12996                                    QueryPos qPos = QueryPos.getInstance(q);
12997    
12998                                    qPos.add(groupId);
12999    
13000                                    qPos.add(categoryId);
13001    
13002                                    qPos.add(threadId);
13003    
13004                                    qPos.add(answer);
13005    
13006                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13007                                                    end);
13008                            }
13009                            catch (Exception e) {
13010                                    throw processException(e);
13011                            }
13012                            finally {
13013                                    if (list == null) {
13014                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13015                                    }
13016                                    else {
13017                                            cacheResult(list);
13018    
13019                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13020                                    }
13021    
13022                                    closeSession(session);
13023                            }
13024                    }
13025    
13026                    return list;
13027            }
13028    
13029            /**
13030             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13031             *
13032             * <p>
13033             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13034             * </p>
13035             *
13036             * @param groupId the group ID
13037             * @param categoryId the category ID
13038             * @param threadId the thread ID
13039             * @param answer the answer
13040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13041             * @return the first matching message-boards message
13042             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13043             * @throws SystemException if a system exception occurred
13044             */
13045            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
13046                    long threadId, boolean answer, OrderByComparator orderByComparator)
13047                    throws NoSuchMessageException, SystemException {
13048                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
13049                                    answer, 0, 1, orderByComparator);
13050    
13051                    if (list.isEmpty()) {
13052                            StringBundler msg = new StringBundler(10);
13053    
13054                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13055    
13056                            msg.append("groupId=");
13057                            msg.append(groupId);
13058    
13059                            msg.append(", categoryId=");
13060                            msg.append(categoryId);
13061    
13062                            msg.append(", threadId=");
13063                            msg.append(threadId);
13064    
13065                            msg.append(", answer=");
13066                            msg.append(answer);
13067    
13068                            msg.append(StringPool.CLOSE_CURLY_BRACE);
13069    
13070                            throw new NoSuchMessageException(msg.toString());
13071                    }
13072                    else {
13073                            return list.get(0);
13074                    }
13075            }
13076    
13077            /**
13078             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13079             *
13080             * <p>
13081             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13082             * </p>
13083             *
13084             * @param groupId the group ID
13085             * @param categoryId the category ID
13086             * @param threadId the thread ID
13087             * @param answer the answer
13088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13089             * @return the last matching message-boards message
13090             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13091             * @throws SystemException if a system exception occurred
13092             */
13093            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
13094                    long threadId, boolean answer, OrderByComparator orderByComparator)
13095                    throws NoSuchMessageException, SystemException {
13096                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
13097    
13098                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
13099                                    answer, count - 1, count, orderByComparator);
13100    
13101                    if (list.isEmpty()) {
13102                            StringBundler msg = new StringBundler(10);
13103    
13104                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13105    
13106                            msg.append("groupId=");
13107                            msg.append(groupId);
13108    
13109                            msg.append(", categoryId=");
13110                            msg.append(categoryId);
13111    
13112                            msg.append(", threadId=");
13113                            msg.append(threadId);
13114    
13115                            msg.append(", answer=");
13116                            msg.append(answer);
13117    
13118                            msg.append(StringPool.CLOSE_CURLY_BRACE);
13119    
13120                            throw new NoSuchMessageException(msg.toString());
13121                    }
13122                    else {
13123                            return list.get(0);
13124                    }
13125            }
13126    
13127            /**
13128             * 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;.
13129             *
13130             * <p>
13131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13132             * </p>
13133             *
13134             * @param messageId the primary key of the current message-boards message
13135             * @param groupId the group ID
13136             * @param categoryId the category ID
13137             * @param threadId the thread ID
13138             * @param answer the answer
13139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13140             * @return the previous, current, and next message-boards message
13141             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13142             * @throws SystemException if a system exception occurred
13143             */
13144            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
13145                    long categoryId, long threadId, boolean answer,
13146                    OrderByComparator orderByComparator)
13147                    throws NoSuchMessageException, SystemException {
13148                    MBMessage mbMessage = findByPrimaryKey(messageId);
13149    
13150                    Session session = null;
13151    
13152                    try {
13153                            session = openSession();
13154    
13155                            MBMessage[] array = new MBMessageImpl[3];
13156    
13157                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
13158                                            categoryId, threadId, answer, orderByComparator, true);
13159    
13160                            array[1] = mbMessage;
13161    
13162                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
13163                                            categoryId, threadId, answer, orderByComparator, false);
13164    
13165                            return array;
13166                    }
13167                    catch (Exception e) {
13168                            throw processException(e);
13169                    }
13170                    finally {
13171                            closeSession(session);
13172                    }
13173            }
13174    
13175            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
13176                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13177                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
13178                    StringBundler query = null;
13179    
13180                    if (orderByComparator != null) {
13181                            query = new StringBundler(6 +
13182                                            (orderByComparator.getOrderByFields().length * 6));
13183                    }
13184                    else {
13185                            query = new StringBundler(3);
13186                    }
13187    
13188                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13189    
13190                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13191    
13192                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13193    
13194                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13195    
13196                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13197    
13198                    if (orderByComparator != null) {
13199                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13200    
13201                            if (orderByConditionFields.length > 0) {
13202                                    query.append(WHERE_AND);
13203                            }
13204    
13205                            for (int i = 0; i < orderByConditionFields.length; i++) {
13206                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13207                                    query.append(orderByConditionFields[i]);
13208    
13209                                    if ((i + 1) < orderByConditionFields.length) {
13210                                            if (orderByComparator.isAscending() ^ previous) {
13211                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13212                                            }
13213                                            else {
13214                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13215                                            }
13216                                    }
13217                                    else {
13218                                            if (orderByComparator.isAscending() ^ previous) {
13219                                                    query.append(WHERE_GREATER_THAN);
13220                                            }
13221                                            else {
13222                                                    query.append(WHERE_LESSER_THAN);
13223                                            }
13224                                    }
13225                            }
13226    
13227                            query.append(ORDER_BY_CLAUSE);
13228    
13229                            String[] orderByFields = orderByComparator.getOrderByFields();
13230    
13231                            for (int i = 0; i < orderByFields.length; i++) {
13232                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13233                                    query.append(orderByFields[i]);
13234    
13235                                    if ((i + 1) < orderByFields.length) {
13236                                            if (orderByComparator.isAscending() ^ previous) {
13237                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13238                                            }
13239                                            else {
13240                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13241                                            }
13242                                    }
13243                                    else {
13244                                            if (orderByComparator.isAscending() ^ previous) {
13245                                                    query.append(ORDER_BY_ASC);
13246                                            }
13247                                            else {
13248                                                    query.append(ORDER_BY_DESC);
13249                                            }
13250                                    }
13251                            }
13252                    }
13253    
13254                    else {
13255                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13256                    }
13257    
13258                    String sql = query.toString();
13259    
13260                    Query q = session.createQuery(sql);
13261    
13262                    q.setFirstResult(0);
13263                    q.setMaxResults(2);
13264    
13265                    QueryPos qPos = QueryPos.getInstance(q);
13266    
13267                    qPos.add(groupId);
13268    
13269                    qPos.add(categoryId);
13270    
13271                    qPos.add(threadId);
13272    
13273                    qPos.add(answer);
13274    
13275                    if (orderByComparator != null) {
13276                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13277    
13278                            for (Object value : values) {
13279                                    qPos.add(value);
13280                            }
13281                    }
13282    
13283                    List<MBMessage> list = q.list();
13284    
13285                    if (list.size() == 2) {
13286                            return list.get(1);
13287                    }
13288                    else {
13289                            return null;
13290                    }
13291            }
13292    
13293            /**
13294             * 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;.
13295             *
13296             * @param groupId the group ID
13297             * @param categoryId the category ID
13298             * @param threadId the thread ID
13299             * @param answer the answer
13300             * @return the matching message-boards messages that the user has permission to view
13301             * @throws SystemException if a system exception occurred
13302             */
13303            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13304                    long threadId, boolean answer) throws SystemException {
13305                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13306                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13307            }
13308    
13309            /**
13310             * 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;.
13311             *
13312             * <p>
13313             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13314             * </p>
13315             *
13316             * @param groupId the group ID
13317             * @param categoryId the category ID
13318             * @param threadId the thread ID
13319             * @param answer the answer
13320             * @param start the lower bound of the range of message-boards messages
13321             * @param end the upper bound of the range of message-boards messages (not inclusive)
13322             * @return the range of matching message-boards messages that the user has permission to view
13323             * @throws SystemException if a system exception occurred
13324             */
13325            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13326                    long threadId, boolean answer, int start, int end)
13327                    throws SystemException {
13328                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13329                            start, end, null);
13330            }
13331    
13332            /**
13333             * 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;.
13334             *
13335             * <p>
13336             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13337             * </p>
13338             *
13339             * @param groupId the group ID
13340             * @param categoryId the category ID
13341             * @param threadId the thread ID
13342             * @param answer the answer
13343             * @param start the lower bound of the range of message-boards messages
13344             * @param end the upper bound of the range of message-boards messages (not inclusive)
13345             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13346             * @return the ordered range of matching message-boards messages that the user has permission to view
13347             * @throws SystemException if a system exception occurred
13348             */
13349            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13350                    long threadId, boolean answer, int start, int end,
13351                    OrderByComparator orderByComparator) throws SystemException {
13352                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13353                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
13354                                    end, orderByComparator);
13355                    }
13356    
13357                    StringBundler query = null;
13358    
13359                    if (orderByComparator != null) {
13360                            query = new StringBundler(6 +
13361                                            (orderByComparator.getOrderByFields().length * 3));
13362                    }
13363                    else {
13364                            query = new StringBundler(6);
13365                    }
13366    
13367                    if (getDB().isSupportsInlineDistinct()) {
13368                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13369                    }
13370                    else {
13371                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13372                    }
13373    
13374                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13375    
13376                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13377    
13378                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13379    
13380                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13381    
13382                    if (!getDB().isSupportsInlineDistinct()) {
13383                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13384                    }
13385    
13386                    if (orderByComparator != null) {
13387                            if (getDB().isSupportsInlineDistinct()) {
13388                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13389                                            orderByComparator);
13390                            }
13391                            else {
13392                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13393                                            orderByComparator);
13394                            }
13395                    }
13396    
13397                    else {
13398                            if (getDB().isSupportsInlineDistinct()) {
13399                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13400                            }
13401                            else {
13402                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13403                            }
13404                    }
13405    
13406                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13407                                    MBMessage.class.getName(),
13408                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13409    
13410                    Session session = null;
13411    
13412                    try {
13413                            session = openSession();
13414    
13415                            SQLQuery q = session.createSQLQuery(sql);
13416    
13417                            if (getDB().isSupportsInlineDistinct()) {
13418                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13419                            }
13420                            else {
13421                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13422                            }
13423    
13424                            QueryPos qPos = QueryPos.getInstance(q);
13425    
13426                            qPos.add(groupId);
13427    
13428                            qPos.add(categoryId);
13429    
13430                            qPos.add(threadId);
13431    
13432                            qPos.add(answer);
13433    
13434                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13435                    }
13436                    catch (Exception e) {
13437                            throw processException(e);
13438                    }
13439                    finally {
13440                            closeSession(session);
13441                    }
13442            }
13443    
13444            /**
13445             * 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;.
13446             *
13447             * @param messageId the primary key of the current message-boards message
13448             * @param groupId the group ID
13449             * @param categoryId the category ID
13450             * @param threadId the thread ID
13451             * @param answer the answer
13452             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13453             * @return the previous, current, and next message-boards message
13454             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13455             * @throws SystemException if a system exception occurred
13456             */
13457            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
13458                    long groupId, long categoryId, long threadId, boolean answer,
13459                    OrderByComparator orderByComparator)
13460                    throws NoSuchMessageException, SystemException {
13461                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13462                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
13463                                    threadId, answer, orderByComparator);
13464                    }
13465    
13466                    MBMessage mbMessage = findByPrimaryKey(messageId);
13467    
13468                    Session session = null;
13469    
13470                    try {
13471                            session = openSession();
13472    
13473                            MBMessage[] array = new MBMessageImpl[3];
13474    
13475                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
13476                                            groupId, categoryId, threadId, answer, orderByComparator,
13477                                            true);
13478    
13479                            array[1] = mbMessage;
13480    
13481                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
13482                                            groupId, categoryId, threadId, answer, orderByComparator,
13483                                            false);
13484    
13485                            return array;
13486                    }
13487                    catch (Exception e) {
13488                            throw processException(e);
13489                    }
13490                    finally {
13491                            closeSession(session);
13492                    }
13493            }
13494    
13495            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
13496                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13497                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
13498                    StringBundler query = null;
13499    
13500                    if (orderByComparator != null) {
13501                            query = new StringBundler(6 +
13502                                            (orderByComparator.getOrderByFields().length * 6));
13503                    }
13504                    else {
13505                            query = new StringBundler(3);
13506                    }
13507    
13508                    if (getDB().isSupportsInlineDistinct()) {
13509                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13510                    }
13511                    else {
13512                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13513                    }
13514    
13515                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13516    
13517                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13518    
13519                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13520    
13521                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13522    
13523                    if (!getDB().isSupportsInlineDistinct()) {
13524                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13525                    }
13526    
13527                    if (orderByComparator != null) {
13528                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13529    
13530                            if (orderByConditionFields.length > 0) {
13531                                    query.append(WHERE_AND);
13532                            }
13533    
13534                            for (int i = 0; i < orderByConditionFields.length; i++) {
13535                                    if (getDB().isSupportsInlineDistinct()) {
13536                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13537                                    }
13538                                    else {
13539                                            query.append(_ORDER_BY_ENTITY_TABLE);
13540                                    }
13541    
13542                                    query.append(orderByConditionFields[i]);
13543    
13544                                    if ((i + 1) < orderByConditionFields.length) {
13545                                            if (orderByComparator.isAscending() ^ previous) {
13546                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13547                                            }
13548                                            else {
13549                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13550                                            }
13551                                    }
13552                                    else {
13553                                            if (orderByComparator.isAscending() ^ previous) {
13554                                                    query.append(WHERE_GREATER_THAN);
13555                                            }
13556                                            else {
13557                                                    query.append(WHERE_LESSER_THAN);
13558                                            }
13559                                    }
13560                            }
13561    
13562                            query.append(ORDER_BY_CLAUSE);
13563    
13564                            String[] orderByFields = orderByComparator.getOrderByFields();
13565    
13566                            for (int i = 0; i < orderByFields.length; i++) {
13567                                    if (getDB().isSupportsInlineDistinct()) {
13568                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13569                                    }
13570                                    else {
13571                                            query.append(_ORDER_BY_ENTITY_TABLE);
13572                                    }
13573    
13574                                    query.append(orderByFields[i]);
13575    
13576                                    if ((i + 1) < orderByFields.length) {
13577                                            if (orderByComparator.isAscending() ^ previous) {
13578                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13579                                            }
13580                                            else {
13581                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13582                                            }
13583                                    }
13584                                    else {
13585                                            if (orderByComparator.isAscending() ^ previous) {
13586                                                    query.append(ORDER_BY_ASC);
13587                                            }
13588                                            else {
13589                                                    query.append(ORDER_BY_DESC);
13590                                            }
13591                                    }
13592                            }
13593                    }
13594    
13595                    else {
13596                            if (getDB().isSupportsInlineDistinct()) {
13597                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13598                            }
13599                            else {
13600                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13601                            }
13602                    }
13603    
13604                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13605                                    MBMessage.class.getName(),
13606                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13607    
13608                    SQLQuery q = session.createSQLQuery(sql);
13609    
13610                    q.setFirstResult(0);
13611                    q.setMaxResults(2);
13612    
13613                    if (getDB().isSupportsInlineDistinct()) {
13614                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13615                    }
13616                    else {
13617                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13618                    }
13619    
13620                    QueryPos qPos = QueryPos.getInstance(q);
13621    
13622                    qPos.add(groupId);
13623    
13624                    qPos.add(categoryId);
13625    
13626                    qPos.add(threadId);
13627    
13628                    qPos.add(answer);
13629    
13630                    if (orderByComparator != null) {
13631                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13632    
13633                            for (Object value : values) {
13634                                    qPos.add(value);
13635                            }
13636                    }
13637    
13638                    List<MBMessage> list = q.list();
13639    
13640                    if (list.size() == 2) {
13641                            return list.get(1);
13642                    }
13643                    else {
13644                            return null;
13645                    }
13646            }
13647    
13648            /**
13649             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13650             *
13651             * @param groupId the group ID
13652             * @param categoryId the category ID
13653             * @param threadId the thread ID
13654             * @param status the status
13655             * @return the matching message-boards messages
13656             * @throws SystemException if a system exception occurred
13657             */
13658            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
13659                    long threadId, int status) throws SystemException {
13660                    return findByG_C_T_S(groupId, categoryId, threadId, status,
13661                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13662            }
13663    
13664            /**
13665             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13666             *
13667             * <p>
13668             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13669             * </p>
13670             *
13671             * @param groupId the group ID
13672             * @param categoryId the category ID
13673             * @param threadId the thread ID
13674             * @param status the status
13675             * @param start the lower bound of the range of message-boards messages
13676             * @param end the upper bound of the range of message-boards messages (not inclusive)
13677             * @return the range of matching message-boards messages
13678             * @throws SystemException if a system exception occurred
13679             */
13680            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
13681                    long threadId, int status, int start, int end)
13682                    throws SystemException {
13683                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
13684                            null);
13685            }
13686    
13687            /**
13688             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13689             *
13690             * <p>
13691             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13692             * </p>
13693             *
13694             * @param groupId the group ID
13695             * @param categoryId the category ID
13696             * @param threadId the thread ID
13697             * @param status the status
13698             * @param start the lower bound of the range of message-boards messages
13699             * @param end the upper bound of the range of message-boards messages (not inclusive)
13700             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13701             * @return the ordered range of matching message-boards messages
13702             * @throws SystemException if a system exception occurred
13703             */
13704            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
13705                    long threadId, int status, int start, int end,
13706                    OrderByComparator orderByComparator) throws SystemException {
13707                    FinderPath finderPath = null;
13708                    Object[] finderArgs = null;
13709    
13710                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13711                                    (orderByComparator == null)) {
13712                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
13713                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
13714                    }
13715                    else {
13716                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
13717                            finderArgs = new Object[] {
13718                                            groupId, categoryId, threadId, status,
13719                                            
13720                                            start, end, orderByComparator
13721                                    };
13722                    }
13723    
13724                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13725                                    finderArgs, this);
13726    
13727                    if ((list != null) && !list.isEmpty()) {
13728                            for (MBMessage mbMessage : list) {
13729                                    if ((groupId != mbMessage.getGroupId()) ||
13730                                                    (categoryId != mbMessage.getCategoryId()) ||
13731                                                    (threadId != mbMessage.getThreadId()) ||
13732                                                    (status != mbMessage.getStatus())) {
13733                                            list = null;
13734    
13735                                            break;
13736                                    }
13737                            }
13738                    }
13739    
13740                    if (list == null) {
13741                            StringBundler query = null;
13742    
13743                            if (orderByComparator != null) {
13744                                    query = new StringBundler(6 +
13745                                                    (orderByComparator.getOrderByFields().length * 3));
13746                            }
13747                            else {
13748                                    query = new StringBundler(6);
13749                            }
13750    
13751                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13752    
13753                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
13754    
13755                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
13756    
13757                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
13758    
13759                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
13760    
13761                            if (orderByComparator != null) {
13762                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13763                                            orderByComparator);
13764                            }
13765    
13766                            else {
13767                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13768                            }
13769    
13770                            String sql = query.toString();
13771    
13772                            Session session = null;
13773    
13774                            try {
13775                                    session = openSession();
13776    
13777                                    Query q = session.createQuery(sql);
13778    
13779                                    QueryPos qPos = QueryPos.getInstance(q);
13780    
13781                                    qPos.add(groupId);
13782    
13783                                    qPos.add(categoryId);
13784    
13785                                    qPos.add(threadId);
13786    
13787                                    qPos.add(status);
13788    
13789                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13790                                                    end);
13791                            }
13792                            catch (Exception e) {
13793                                    throw processException(e);
13794                            }
13795                            finally {
13796                                    if (list == null) {
13797                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13798                                    }
13799                                    else {
13800                                            cacheResult(list);
13801    
13802                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13803                                    }
13804    
13805                                    closeSession(session);
13806                            }
13807                    }
13808    
13809                    return list;
13810            }
13811    
13812            /**
13813             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13814             *
13815             * <p>
13816             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13817             * </p>
13818             *
13819             * @param groupId the group ID
13820             * @param categoryId the category ID
13821             * @param threadId the thread ID
13822             * @param status the status
13823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13824             * @return the first matching message-boards message
13825             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13826             * @throws SystemException if a system exception occurred
13827             */
13828            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
13829                    long threadId, int status, OrderByComparator orderByComparator)
13830                    throws NoSuchMessageException, SystemException {
13831                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
13832                                    status, 0, 1, orderByComparator);
13833    
13834                    if (list.isEmpty()) {
13835                            StringBundler msg = new StringBundler(10);
13836    
13837                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13838    
13839                            msg.append("groupId=");
13840                            msg.append(groupId);
13841    
13842                            msg.append(", categoryId=");
13843                            msg.append(categoryId);
13844    
13845                            msg.append(", threadId=");
13846                            msg.append(threadId);
13847    
13848                            msg.append(", status=");
13849                            msg.append(status);
13850    
13851                            msg.append(StringPool.CLOSE_CURLY_BRACE);
13852    
13853                            throw new NoSuchMessageException(msg.toString());
13854                    }
13855                    else {
13856                            return list.get(0);
13857                    }
13858            }
13859    
13860            /**
13861             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13862             *
13863             * <p>
13864             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13865             * </p>
13866             *
13867             * @param groupId the group ID
13868             * @param categoryId the category ID
13869             * @param threadId the thread ID
13870             * @param status the status
13871             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13872             * @return the last matching message-boards message
13873             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13874             * @throws SystemException if a system exception occurred
13875             */
13876            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
13877                    long threadId, int status, OrderByComparator orderByComparator)
13878                    throws NoSuchMessageException, SystemException {
13879                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
13880    
13881                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
13882                                    status, count - 1, count, orderByComparator);
13883    
13884                    if (list.isEmpty()) {
13885                            StringBundler msg = new StringBundler(10);
13886    
13887                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13888    
13889                            msg.append("groupId=");
13890                            msg.append(groupId);
13891    
13892                            msg.append(", categoryId=");
13893                            msg.append(categoryId);
13894    
13895                            msg.append(", threadId=");
13896                            msg.append(threadId);
13897    
13898                            msg.append(", status=");
13899                            msg.append(status);
13900    
13901                            msg.append(StringPool.CLOSE_CURLY_BRACE);
13902    
13903                            throw new NoSuchMessageException(msg.toString());
13904                    }
13905                    else {
13906                            return list.get(0);
13907                    }
13908            }
13909    
13910            /**
13911             * 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;.
13912             *
13913             * <p>
13914             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13915             * </p>
13916             *
13917             * @param messageId the primary key of the current message-boards message
13918             * @param groupId the group ID
13919             * @param categoryId the category ID
13920             * @param threadId the thread ID
13921             * @param status the status
13922             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13923             * @return the previous, current, and next message-boards message
13924             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13925             * @throws SystemException if a system exception occurred
13926             */
13927            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
13928                    long categoryId, long threadId, int status,
13929                    OrderByComparator orderByComparator)
13930                    throws NoSuchMessageException, SystemException {
13931                    MBMessage mbMessage = findByPrimaryKey(messageId);
13932    
13933                    Session session = null;
13934    
13935                    try {
13936                            session = openSession();
13937    
13938                            MBMessage[] array = new MBMessageImpl[3];
13939    
13940                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
13941                                            categoryId, threadId, status, orderByComparator, true);
13942    
13943                            array[1] = mbMessage;
13944    
13945                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
13946                                            categoryId, threadId, status, orderByComparator, false);
13947    
13948                            return array;
13949                    }
13950                    catch (Exception e) {
13951                            throw processException(e);
13952                    }
13953                    finally {
13954                            closeSession(session);
13955                    }
13956            }
13957    
13958            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
13959                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13960                    int status, OrderByComparator orderByComparator, boolean previous) {
13961                    StringBundler query = null;
13962    
13963                    if (orderByComparator != null) {
13964                            query = new StringBundler(6 +
13965                                            (orderByComparator.getOrderByFields().length * 6));
13966                    }
13967                    else {
13968                            query = new StringBundler(3);
13969                    }
13970    
13971                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13972    
13973                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
13974    
13975                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
13976    
13977                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
13978    
13979                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
13980    
13981                    if (orderByComparator != null) {
13982                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13983    
13984                            if (orderByConditionFields.length > 0) {
13985                                    query.append(WHERE_AND);
13986                            }
13987    
13988                            for (int i = 0; i < orderByConditionFields.length; i++) {
13989                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13990                                    query.append(orderByConditionFields[i]);
13991    
13992                                    if ((i + 1) < orderByConditionFields.length) {
13993                                            if (orderByComparator.isAscending() ^ previous) {
13994                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13995                                            }
13996                                            else {
13997                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13998                                            }
13999                                    }
14000                                    else {
14001                                            if (orderByComparator.isAscending() ^ previous) {
14002                                                    query.append(WHERE_GREATER_THAN);
14003                                            }
14004                                            else {
14005                                                    query.append(WHERE_LESSER_THAN);
14006                                            }
14007                                    }
14008                            }
14009    
14010                            query.append(ORDER_BY_CLAUSE);
14011    
14012                            String[] orderByFields = orderByComparator.getOrderByFields();
14013    
14014                            for (int i = 0; i < orderByFields.length; i++) {
14015                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14016                                    query.append(orderByFields[i]);
14017    
14018                                    if ((i + 1) < orderByFields.length) {
14019                                            if (orderByComparator.isAscending() ^ previous) {
14020                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14021                                            }
14022                                            else {
14023                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14024                                            }
14025                                    }
14026                                    else {
14027                                            if (orderByComparator.isAscending() ^ previous) {
14028                                                    query.append(ORDER_BY_ASC);
14029                                            }
14030                                            else {
14031                                                    query.append(ORDER_BY_DESC);
14032                                            }
14033                                    }
14034                            }
14035                    }
14036    
14037                    else {
14038                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14039                    }
14040    
14041                    String sql = query.toString();
14042    
14043                    Query q = session.createQuery(sql);
14044    
14045                    q.setFirstResult(0);
14046                    q.setMaxResults(2);
14047    
14048                    QueryPos qPos = QueryPos.getInstance(q);
14049    
14050                    qPos.add(groupId);
14051    
14052                    qPos.add(categoryId);
14053    
14054                    qPos.add(threadId);
14055    
14056                    qPos.add(status);
14057    
14058                    if (orderByComparator != null) {
14059                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14060    
14061                            for (Object value : values) {
14062                                    qPos.add(value);
14063                            }
14064                    }
14065    
14066                    List<MBMessage> list = q.list();
14067    
14068                    if (list.size() == 2) {
14069                            return list.get(1);
14070                    }
14071                    else {
14072                            return null;
14073                    }
14074            }
14075    
14076            /**
14077             * 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;.
14078             *
14079             * @param groupId the group ID
14080             * @param categoryId the category ID
14081             * @param threadId the thread ID
14082             * @param status the status
14083             * @return the matching message-boards messages that the user has permission to view
14084             * @throws SystemException if a system exception occurred
14085             */
14086            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14087                    long threadId, int status) throws SystemException {
14088                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
14089                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14090            }
14091    
14092            /**
14093             * 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;.
14094             *
14095             * <p>
14096             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14097             * </p>
14098             *
14099             * @param groupId the group ID
14100             * @param categoryId the category ID
14101             * @param threadId the thread ID
14102             * @param status the status
14103             * @param start the lower bound of the range of message-boards messages
14104             * @param end the upper bound of the range of message-boards messages (not inclusive)
14105             * @return the range of matching message-boards messages that the user has permission to view
14106             * @throws SystemException if a system exception occurred
14107             */
14108            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14109                    long threadId, int status, int start, int end)
14110                    throws SystemException {
14111                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
14112                            start, end, null);
14113            }
14114    
14115            /**
14116             * 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;.
14117             *
14118             * <p>
14119             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14120             * </p>
14121             *
14122             * @param groupId the group ID
14123             * @param categoryId the category ID
14124             * @param threadId the thread ID
14125             * @param status the status
14126             * @param start the lower bound of the range of message-boards messages
14127             * @param end the upper bound of the range of message-boards messages (not inclusive)
14128             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14129             * @return the ordered range of matching message-boards messages that the user has permission to view
14130             * @throws SystemException if a system exception occurred
14131             */
14132            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
14133                    long threadId, int status, int start, int end,
14134                    OrderByComparator orderByComparator) throws SystemException {
14135                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14136                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
14137                                    end, orderByComparator);
14138                    }
14139    
14140                    StringBundler query = null;
14141    
14142                    if (orderByComparator != null) {
14143                            query = new StringBundler(6 +
14144                                            (orderByComparator.getOrderByFields().length * 3));
14145                    }
14146                    else {
14147                            query = new StringBundler(6);
14148                    }
14149    
14150                    if (getDB().isSupportsInlineDistinct()) {
14151                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14152                    }
14153                    else {
14154                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14155                    }
14156    
14157                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14158    
14159                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14160    
14161                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14162    
14163                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14164    
14165                    if (!getDB().isSupportsInlineDistinct()) {
14166                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14167                    }
14168    
14169                    if (orderByComparator != null) {
14170                            if (getDB().isSupportsInlineDistinct()) {
14171                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14172                                            orderByComparator);
14173                            }
14174                            else {
14175                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14176                                            orderByComparator);
14177                            }
14178                    }
14179    
14180                    else {
14181                            if (getDB().isSupportsInlineDistinct()) {
14182                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14183                            }
14184                            else {
14185                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14186                            }
14187                    }
14188    
14189                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14190                                    MBMessage.class.getName(),
14191                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14192    
14193                    Session session = null;
14194    
14195                    try {
14196                            session = openSession();
14197    
14198                            SQLQuery q = session.createSQLQuery(sql);
14199    
14200                            if (getDB().isSupportsInlineDistinct()) {
14201                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14202                            }
14203                            else {
14204                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14205                            }
14206    
14207                            QueryPos qPos = QueryPos.getInstance(q);
14208    
14209                            qPos.add(groupId);
14210    
14211                            qPos.add(categoryId);
14212    
14213                            qPos.add(threadId);
14214    
14215                            qPos.add(status);
14216    
14217                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
14218                    }
14219                    catch (Exception e) {
14220                            throw processException(e);
14221                    }
14222                    finally {
14223                            closeSession(session);
14224                    }
14225            }
14226    
14227            /**
14228             * 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;.
14229             *
14230             * @param messageId the primary key of the current message-boards message
14231             * @param groupId the group ID
14232             * @param categoryId the category ID
14233             * @param threadId the thread ID
14234             * @param status the status
14235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14236             * @return the previous, current, and next message-boards message
14237             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14238             * @throws SystemException if a system exception occurred
14239             */
14240            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
14241                    long groupId, long categoryId, long threadId, int status,
14242                    OrderByComparator orderByComparator)
14243                    throws NoSuchMessageException, SystemException {
14244                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14245                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
14246                                    threadId, status, orderByComparator);
14247                    }
14248    
14249                    MBMessage mbMessage = findByPrimaryKey(messageId);
14250    
14251                    Session session = null;
14252    
14253                    try {
14254                            session = openSession();
14255    
14256                            MBMessage[] array = new MBMessageImpl[3];
14257    
14258                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
14259                                            groupId, categoryId, threadId, status, orderByComparator,
14260                                            true);
14261    
14262                            array[1] = mbMessage;
14263    
14264                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
14265                                            groupId, categoryId, threadId, status, orderByComparator,
14266                                            false);
14267    
14268                            return array;
14269                    }
14270                    catch (Exception e) {
14271                            throw processException(e);
14272                    }
14273                    finally {
14274                            closeSession(session);
14275                    }
14276            }
14277    
14278            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
14279                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14280                    int status, OrderByComparator orderByComparator, boolean previous) {
14281                    StringBundler query = null;
14282    
14283                    if (orderByComparator != null) {
14284                            query = new StringBundler(6 +
14285                                            (orderByComparator.getOrderByFields().length * 6));
14286                    }
14287                    else {
14288                            query = new StringBundler(3);
14289                    }
14290    
14291                    if (getDB().isSupportsInlineDistinct()) {
14292                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14293                    }
14294                    else {
14295                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14296                    }
14297    
14298                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14299    
14300                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14301    
14302                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14303    
14304                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14305    
14306                    if (!getDB().isSupportsInlineDistinct()) {
14307                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14308                    }
14309    
14310                    if (orderByComparator != null) {
14311                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14312    
14313                            if (orderByConditionFields.length > 0) {
14314                                    query.append(WHERE_AND);
14315                            }
14316    
14317                            for (int i = 0; i < orderByConditionFields.length; i++) {
14318                                    if (getDB().isSupportsInlineDistinct()) {
14319                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14320                                    }
14321                                    else {
14322                                            query.append(_ORDER_BY_ENTITY_TABLE);
14323                                    }
14324    
14325                                    query.append(orderByConditionFields[i]);
14326    
14327                                    if ((i + 1) < orderByConditionFields.length) {
14328                                            if (orderByComparator.isAscending() ^ previous) {
14329                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14330                                            }
14331                                            else {
14332                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14333                                            }
14334                                    }
14335                                    else {
14336                                            if (orderByComparator.isAscending() ^ previous) {
14337                                                    query.append(WHERE_GREATER_THAN);
14338                                            }
14339                                            else {
14340                                                    query.append(WHERE_LESSER_THAN);
14341                                            }
14342                                    }
14343                            }
14344    
14345                            query.append(ORDER_BY_CLAUSE);
14346    
14347                            String[] orderByFields = orderByComparator.getOrderByFields();
14348    
14349                            for (int i = 0; i < orderByFields.length; i++) {
14350                                    if (getDB().isSupportsInlineDistinct()) {
14351                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14352                                    }
14353                                    else {
14354                                            query.append(_ORDER_BY_ENTITY_TABLE);
14355                                    }
14356    
14357                                    query.append(orderByFields[i]);
14358    
14359                                    if ((i + 1) < orderByFields.length) {
14360                                            if (orderByComparator.isAscending() ^ previous) {
14361                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14362                                            }
14363                                            else {
14364                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14365                                            }
14366                                    }
14367                                    else {
14368                                            if (orderByComparator.isAscending() ^ previous) {
14369                                                    query.append(ORDER_BY_ASC);
14370                                            }
14371                                            else {
14372                                                    query.append(ORDER_BY_DESC);
14373                                            }
14374                                    }
14375                            }
14376                    }
14377    
14378                    else {
14379                            if (getDB().isSupportsInlineDistinct()) {
14380                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14381                            }
14382                            else {
14383                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14384                            }
14385                    }
14386    
14387                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14388                                    MBMessage.class.getName(),
14389                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14390    
14391                    SQLQuery q = session.createSQLQuery(sql);
14392    
14393                    q.setFirstResult(0);
14394                    q.setMaxResults(2);
14395    
14396                    if (getDB().isSupportsInlineDistinct()) {
14397                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14398                    }
14399                    else {
14400                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14401                    }
14402    
14403                    QueryPos qPos = QueryPos.getInstance(q);
14404    
14405                    qPos.add(groupId);
14406    
14407                    qPos.add(categoryId);
14408    
14409                    qPos.add(threadId);
14410    
14411                    qPos.add(status);
14412    
14413                    if (orderByComparator != null) {
14414                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14415    
14416                            for (Object value : values) {
14417                                    qPos.add(value);
14418                            }
14419                    }
14420    
14421                    List<MBMessage> list = q.list();
14422    
14423                    if (list.size() == 2) {
14424                            return list.get(1);
14425                    }
14426                    else {
14427                            return null;
14428                    }
14429            }
14430    
14431            /**
14432             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14433             *
14434             * @param userId the user ID
14435             * @param classNameId the class name ID
14436             * @param classPK the class p k
14437             * @param status the status
14438             * @return the matching message-boards messages
14439             * @throws SystemException if a system exception occurred
14440             */
14441            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
14442                    long classPK, int status) throws SystemException {
14443                    return findByU_C_C_S(userId, classNameId, classPK, status,
14444                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14445            }
14446    
14447            /**
14448             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14449             *
14450             * <p>
14451             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14452             * </p>
14453             *
14454             * @param userId the user ID
14455             * @param classNameId the class name ID
14456             * @param classPK the class p k
14457             * @param status the status
14458             * @param start the lower bound of the range of message-boards messages
14459             * @param end the upper bound of the range of message-boards messages (not inclusive)
14460             * @return the range of matching message-boards messages
14461             * @throws SystemException if a system exception occurred
14462             */
14463            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
14464                    long classPK, int status, int start, int end) throws SystemException {
14465                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
14466                            null);
14467            }
14468    
14469            /**
14470             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14471             *
14472             * <p>
14473             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14474             * </p>
14475             *
14476             * @param userId the user ID
14477             * @param classNameId the class name ID
14478             * @param classPK the class p k
14479             * @param status the status
14480             * @param start the lower bound of the range of message-boards messages
14481             * @param end the upper bound of the range of message-boards messages (not inclusive)
14482             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14483             * @return the ordered range of matching message-boards messages
14484             * @throws SystemException if a system exception occurred
14485             */
14486            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
14487                    long classPK, int status, int start, int end,
14488                    OrderByComparator orderByComparator) throws SystemException {
14489                    FinderPath finderPath = null;
14490                    Object[] finderArgs = null;
14491    
14492                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14493                                    (orderByComparator == null)) {
14494                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
14495                            finderArgs = new Object[] { userId, classNameId, classPK, status };
14496                    }
14497                    else {
14498                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
14499                            finderArgs = new Object[] {
14500                                            userId, classNameId, classPK, status,
14501                                            
14502                                            start, end, orderByComparator
14503                                    };
14504                    }
14505    
14506                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14507                                    finderArgs, this);
14508    
14509                    if ((list != null) && !list.isEmpty()) {
14510                            for (MBMessage mbMessage : list) {
14511                                    if ((userId != mbMessage.getUserId()) ||
14512                                                    (classNameId != mbMessage.getClassNameId()) ||
14513                                                    (classPK != mbMessage.getClassPK()) ||
14514                                                    (status != mbMessage.getStatus())) {
14515                                            list = null;
14516    
14517                                            break;
14518                                    }
14519                            }
14520                    }
14521    
14522                    if (list == null) {
14523                            StringBundler query = null;
14524    
14525                            if (orderByComparator != null) {
14526                                    query = new StringBundler(6 +
14527                                                    (orderByComparator.getOrderByFields().length * 3));
14528                            }
14529                            else {
14530                                    query = new StringBundler(6);
14531                            }
14532    
14533                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14534    
14535                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
14536    
14537                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
14538    
14539                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
14540    
14541                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
14542    
14543                            if (orderByComparator != null) {
14544                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14545                                            orderByComparator);
14546                            }
14547    
14548                            else {
14549                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14550                            }
14551    
14552                            String sql = query.toString();
14553    
14554                            Session session = null;
14555    
14556                            try {
14557                                    session = openSession();
14558    
14559                                    Query q = session.createQuery(sql);
14560    
14561                                    QueryPos qPos = QueryPos.getInstance(q);
14562    
14563                                    qPos.add(userId);
14564    
14565                                    qPos.add(classNameId);
14566    
14567                                    qPos.add(classPK);
14568    
14569                                    qPos.add(status);
14570    
14571                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
14572                                                    end);
14573                            }
14574                            catch (Exception e) {
14575                                    throw processException(e);
14576                            }
14577                            finally {
14578                                    if (list == null) {
14579                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14580                                    }
14581                                    else {
14582                                            cacheResult(list);
14583    
14584                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14585                                    }
14586    
14587                                    closeSession(session);
14588                            }
14589                    }
14590    
14591                    return list;
14592            }
14593    
14594            /**
14595             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14596             *
14597             * <p>
14598             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14599             * </p>
14600             *
14601             * @param userId the user ID
14602             * @param classNameId the class name ID
14603             * @param classPK the class p k
14604             * @param status the status
14605             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14606             * @return the first matching message-boards message
14607             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14608             * @throws SystemException if a system exception occurred
14609             */
14610            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
14611                    long classPK, int status, OrderByComparator orderByComparator)
14612                    throws NoSuchMessageException, SystemException {
14613                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
14614                                    status, 0, 1, orderByComparator);
14615    
14616                    if (list.isEmpty()) {
14617                            StringBundler msg = new StringBundler(10);
14618    
14619                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14620    
14621                            msg.append("userId=");
14622                            msg.append(userId);
14623    
14624                            msg.append(", classNameId=");
14625                            msg.append(classNameId);
14626    
14627                            msg.append(", classPK=");
14628                            msg.append(classPK);
14629    
14630                            msg.append(", status=");
14631                            msg.append(status);
14632    
14633                            msg.append(StringPool.CLOSE_CURLY_BRACE);
14634    
14635                            throw new NoSuchMessageException(msg.toString());
14636                    }
14637                    else {
14638                            return list.get(0);
14639                    }
14640            }
14641    
14642            /**
14643             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14644             *
14645             * <p>
14646             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14647             * </p>
14648             *
14649             * @param userId the user ID
14650             * @param classNameId the class name ID
14651             * @param classPK the class p k
14652             * @param status the status
14653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14654             * @return the last matching message-boards message
14655             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14656             * @throws SystemException if a system exception occurred
14657             */
14658            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
14659                    long classPK, int status, OrderByComparator orderByComparator)
14660                    throws NoSuchMessageException, SystemException {
14661                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
14662    
14663                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
14664                                    status, count - 1, count, orderByComparator);
14665    
14666                    if (list.isEmpty()) {
14667                            StringBundler msg = new StringBundler(10);
14668    
14669                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14670    
14671                            msg.append("userId=");
14672                            msg.append(userId);
14673    
14674                            msg.append(", classNameId=");
14675                            msg.append(classNameId);
14676    
14677                            msg.append(", classPK=");
14678                            msg.append(classPK);
14679    
14680                            msg.append(", status=");
14681                            msg.append(status);
14682    
14683                            msg.append(StringPool.CLOSE_CURLY_BRACE);
14684    
14685                            throw new NoSuchMessageException(msg.toString());
14686                    }
14687                    else {
14688                            return list.get(0);
14689                    }
14690            }
14691    
14692            /**
14693             * 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;.
14694             *
14695             * <p>
14696             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14697             * </p>
14698             *
14699             * @param messageId the primary key of the current message-boards message
14700             * @param userId the user ID
14701             * @param classNameId the class name ID
14702             * @param classPK the class p k
14703             * @param status the status
14704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14705             * @return the previous, current, and next message-boards message
14706             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14707             * @throws SystemException if a system exception occurred
14708             */
14709            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
14710                    long classNameId, long classPK, int status,
14711                    OrderByComparator orderByComparator)
14712                    throws NoSuchMessageException, SystemException {
14713                    MBMessage mbMessage = findByPrimaryKey(messageId);
14714    
14715                    Session session = null;
14716    
14717                    try {
14718                            session = openSession();
14719    
14720                            MBMessage[] array = new MBMessageImpl[3];
14721    
14722                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
14723                                            classNameId, classPK, status, orderByComparator, true);
14724    
14725                            array[1] = mbMessage;
14726    
14727                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
14728                                            classNameId, classPK, status, orderByComparator, false);
14729    
14730                            return array;
14731                    }
14732                    catch (Exception e) {
14733                            throw processException(e);
14734                    }
14735                    finally {
14736                            closeSession(session);
14737                    }
14738            }
14739    
14740            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
14741                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14742                    int status, OrderByComparator orderByComparator, boolean previous) {
14743                    StringBundler query = null;
14744    
14745                    if (orderByComparator != null) {
14746                            query = new StringBundler(6 +
14747                                            (orderByComparator.getOrderByFields().length * 6));
14748                    }
14749                    else {
14750                            query = new StringBundler(3);
14751                    }
14752    
14753                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14754    
14755                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
14756    
14757                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
14758    
14759                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
14760    
14761                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
14762    
14763                    if (orderByComparator != null) {
14764                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14765    
14766                            if (orderByConditionFields.length > 0) {
14767                                    query.append(WHERE_AND);
14768                            }
14769    
14770                            for (int i = 0; i < orderByConditionFields.length; i++) {
14771                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14772                                    query.append(orderByConditionFields[i]);
14773    
14774                                    if ((i + 1) < orderByConditionFields.length) {
14775                                            if (orderByComparator.isAscending() ^ previous) {
14776                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14777                                            }
14778                                            else {
14779                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14780                                            }
14781                                    }
14782                                    else {
14783                                            if (orderByComparator.isAscending() ^ previous) {
14784                                                    query.append(WHERE_GREATER_THAN);
14785                                            }
14786                                            else {
14787                                                    query.append(WHERE_LESSER_THAN);
14788                                            }
14789                                    }
14790                            }
14791    
14792                            query.append(ORDER_BY_CLAUSE);
14793    
14794                            String[] orderByFields = orderByComparator.getOrderByFields();
14795    
14796                            for (int i = 0; i < orderByFields.length; i++) {
14797                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14798                                    query.append(orderByFields[i]);
14799    
14800                                    if ((i + 1) < orderByFields.length) {
14801                                            if (orderByComparator.isAscending() ^ previous) {
14802                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14803                                            }
14804                                            else {
14805                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14806                                            }
14807                                    }
14808                                    else {
14809                                            if (orderByComparator.isAscending() ^ previous) {
14810                                                    query.append(ORDER_BY_ASC);
14811                                            }
14812                                            else {
14813                                                    query.append(ORDER_BY_DESC);
14814                                            }
14815                                    }
14816                            }
14817                    }
14818    
14819                    else {
14820                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14821                    }
14822    
14823                    String sql = query.toString();
14824    
14825                    Query q = session.createQuery(sql);
14826    
14827                    q.setFirstResult(0);
14828                    q.setMaxResults(2);
14829    
14830                    QueryPos qPos = QueryPos.getInstance(q);
14831    
14832                    qPos.add(userId);
14833    
14834                    qPos.add(classNameId);
14835    
14836                    qPos.add(classPK);
14837    
14838                    qPos.add(status);
14839    
14840                    if (orderByComparator != null) {
14841                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14842    
14843                            for (Object value : values) {
14844                                    qPos.add(value);
14845                            }
14846                    }
14847    
14848                    List<MBMessage> list = q.list();
14849    
14850                    if (list.size() == 2) {
14851                            return list.get(1);
14852                    }
14853                    else {
14854                            return null;
14855                    }
14856            }
14857    
14858            /**
14859             * Returns all the message-boards messages.
14860             *
14861             * @return the message-boards messages
14862             * @throws SystemException if a system exception occurred
14863             */
14864            public List<MBMessage> findAll() throws SystemException {
14865                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14866            }
14867    
14868            /**
14869             * Returns a range of all the message-boards messages.
14870             *
14871             * <p>
14872             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14873             * </p>
14874             *
14875             * @param start the lower bound of the range of message-boards messages
14876             * @param end the upper bound of the range of message-boards messages (not inclusive)
14877             * @return the range of message-boards messages
14878             * @throws SystemException if a system exception occurred
14879             */
14880            public List<MBMessage> findAll(int start, int end)
14881                    throws SystemException {
14882                    return findAll(start, end, null);
14883            }
14884    
14885            /**
14886             * Returns an ordered range of all the message-boards messages.
14887             *
14888             * <p>
14889             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14890             * </p>
14891             *
14892             * @param start the lower bound of the range of message-boards messages
14893             * @param end the upper bound of the range of message-boards messages (not inclusive)
14894             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14895             * @return the ordered range of message-boards messages
14896             * @throws SystemException if a system exception occurred
14897             */
14898            public List<MBMessage> findAll(int start, int end,
14899                    OrderByComparator orderByComparator) throws SystemException {
14900                    FinderPath finderPath = null;
14901                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
14902    
14903                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14904                                    (orderByComparator == null)) {
14905                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
14906                            finderArgs = FINDER_ARGS_EMPTY;
14907                    }
14908                    else {
14909                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
14910                            finderArgs = new Object[] { start, end, orderByComparator };
14911                    }
14912    
14913                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14914                                    finderArgs, this);
14915    
14916                    if (list == null) {
14917                            StringBundler query = null;
14918                            String sql = null;
14919    
14920                            if (orderByComparator != null) {
14921                                    query = new StringBundler(2 +
14922                                                    (orderByComparator.getOrderByFields().length * 3));
14923    
14924                                    query.append(_SQL_SELECT_MBMESSAGE);
14925    
14926                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14927                                            orderByComparator);
14928    
14929                                    sql = query.toString();
14930                            }
14931                            else {
14932                                    sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
14933                            }
14934    
14935                            Session session = null;
14936    
14937                            try {
14938                                    session = openSession();
14939    
14940                                    Query q = session.createQuery(sql);
14941    
14942                                    if (orderByComparator == null) {
14943                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14944                                                            start, end, false);
14945    
14946                                            Collections.sort(list);
14947                                    }
14948                                    else {
14949                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14950                                                            start, end);
14951                                    }
14952                            }
14953                            catch (Exception e) {
14954                                    throw processException(e);
14955                            }
14956                            finally {
14957                                    if (list == null) {
14958                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14959                                    }
14960                                    else {
14961                                            cacheResult(list);
14962    
14963                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14964                                    }
14965    
14966                                    closeSession(session);
14967                            }
14968                    }
14969    
14970                    return list;
14971            }
14972    
14973            /**
14974             * Removes all the message-boards messages where uuid = &#63; from the database.
14975             *
14976             * @param uuid the uuid
14977             * @throws SystemException if a system exception occurred
14978             */
14979            public void removeByUuid(String uuid) throws SystemException {
14980                    for (MBMessage mbMessage : findByUuid(uuid)) {
14981                            remove(mbMessage);
14982                    }
14983            }
14984    
14985            /**
14986             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
14987             *
14988             * @param uuid the uuid
14989             * @param groupId the group ID
14990             * @throws SystemException if a system exception occurred
14991             */
14992            public void removeByUUID_G(String uuid, long groupId)
14993                    throws NoSuchMessageException, SystemException {
14994                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
14995    
14996                    remove(mbMessage);
14997            }
14998    
14999            /**
15000             * Removes all the message-boards messages where groupId = &#63; from the database.
15001             *
15002             * @param groupId the group ID
15003             * @throws SystemException if a system exception occurred
15004             */
15005            public void removeByGroupId(long groupId) throws SystemException {
15006                    for (MBMessage mbMessage : findByGroupId(groupId)) {
15007                            remove(mbMessage);
15008                    }
15009            }
15010    
15011            /**
15012             * Removes all the message-boards messages where companyId = &#63; from the database.
15013             *
15014             * @param companyId the company ID
15015             * @throws SystemException if a system exception occurred
15016             */
15017            public void removeByCompanyId(long companyId) throws SystemException {
15018                    for (MBMessage mbMessage : findByCompanyId(companyId)) {
15019                            remove(mbMessage);
15020                    }
15021            }
15022    
15023            /**
15024             * Removes all the message-boards messages where threadId = &#63; from the database.
15025             *
15026             * @param threadId the thread ID
15027             * @throws SystemException if a system exception occurred
15028             */
15029            public void removeByThreadId(long threadId) throws SystemException {
15030                    for (MBMessage mbMessage : findByThreadId(threadId)) {
15031                            remove(mbMessage);
15032                    }
15033            }
15034    
15035            /**
15036             * Removes all the message-boards messages where threadId = &#63; from the database.
15037             *
15038             * @param threadId the thread ID
15039             * @throws SystemException if a system exception occurred
15040             */
15041            public void removeByThreadReplies(long threadId) throws SystemException {
15042                    for (MBMessage mbMessage : findByThreadReplies(threadId)) {
15043                            remove(mbMessage);
15044                    }
15045            }
15046    
15047            /**
15048             * Removes all the message-boards messages where userId = &#63; from the database.
15049             *
15050             * @param userId the user ID
15051             * @throws SystemException if a system exception occurred
15052             */
15053            public void removeByUserId(long userId) throws SystemException {
15054                    for (MBMessage mbMessage : findByUserId(userId)) {
15055                            remove(mbMessage);
15056                    }
15057            }
15058    
15059            /**
15060             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
15061             *
15062             * @param groupId the group ID
15063             * @param userId the user ID
15064             * @throws SystemException if a system exception occurred
15065             */
15066            public void removeByG_U(long groupId, long userId)
15067                    throws SystemException {
15068                    for (MBMessage mbMessage : findByG_U(groupId, userId)) {
15069                            remove(mbMessage);
15070                    }
15071            }
15072    
15073            /**
15074             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
15075             *
15076             * @param groupId the group ID
15077             * @param categoryId the category ID
15078             * @throws SystemException if a system exception occurred
15079             */
15080            public void removeByG_C(long groupId, long categoryId)
15081                    throws SystemException {
15082                    for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
15083                            remove(mbMessage);
15084                    }
15085            }
15086    
15087            /**
15088             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
15089             *
15090             * @param groupId the group ID
15091             * @param status the status
15092             * @throws SystemException if a system exception occurred
15093             */
15094            public void removeByG_S(long groupId, int status) throws SystemException {
15095                    for (MBMessage mbMessage : findByG_S(groupId, status)) {
15096                            remove(mbMessage);
15097                    }
15098            }
15099    
15100            /**
15101             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
15102             *
15103             * @param companyId the company ID
15104             * @param status the status
15105             * @throws SystemException if a system exception occurred
15106             */
15107            public void removeByC_S(long companyId, int status)
15108                    throws SystemException {
15109                    for (MBMessage mbMessage : findByC_S(companyId, status)) {
15110                            remove(mbMessage);
15111                    }
15112            }
15113    
15114            /**
15115             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
15116             *
15117             * @param userId the user ID
15118             * @param classNameId the class name ID
15119             * @throws SystemException if a system exception occurred
15120             */
15121            public void removeByU_C(long userId, long classNameId)
15122                    throws SystemException {
15123                    for (MBMessage mbMessage : findByU_C(userId, classNameId)) {
15124                            remove(mbMessage);
15125                    }
15126            }
15127    
15128            /**
15129             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
15130             *
15131             * @param classNameId the class name ID
15132             * @param classPK the class p k
15133             * @throws SystemException if a system exception occurred
15134             */
15135            public void removeByC_C(long classNameId, long classPK)
15136                    throws SystemException {
15137                    for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
15138                            remove(mbMessage);
15139                    }
15140            }
15141    
15142            /**
15143             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
15144             *
15145             * @param threadId the thread ID
15146             * @param parentMessageId the parent message ID
15147             * @throws SystemException if a system exception occurred
15148             */
15149            public void removeByT_P(long threadId, long parentMessageId)
15150                    throws SystemException {
15151                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
15152                            remove(mbMessage);
15153                    }
15154            }
15155    
15156            /**
15157             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
15158             *
15159             * @param threadId the thread ID
15160             * @param answer the answer
15161             * @throws SystemException if a system exception occurred
15162             */
15163            public void removeByT_A(long threadId, boolean answer)
15164                    throws SystemException {
15165                    for (MBMessage mbMessage : findByT_A(threadId, answer)) {
15166                            remove(mbMessage);
15167                    }
15168            }
15169    
15170            /**
15171             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
15172             *
15173             * @param threadId the thread ID
15174             * @param status the status
15175             * @throws SystemException if a system exception occurred
15176             */
15177            public void removeByT_S(long threadId, int status)
15178                    throws SystemException {
15179                    for (MBMessage mbMessage : findByT_S(threadId, status)) {
15180                            remove(mbMessage);
15181                    }
15182            }
15183    
15184            /**
15185             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
15186             *
15187             * @param threadId the thread ID
15188             * @param status the status
15189             * @throws SystemException if a system exception occurred
15190             */
15191            public void removeByTR_S(long threadId, int status)
15192                    throws SystemException {
15193                    for (MBMessage mbMessage : findByTR_S(threadId, status)) {
15194                            remove(mbMessage);
15195                    }
15196            }
15197    
15198            /**
15199             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
15200             *
15201             * @param groupId the group ID
15202             * @param userId the user ID
15203             * @param status the status
15204             * @throws SystemException if a system exception occurred
15205             */
15206            public void removeByG_U_S(long groupId, long userId, int status)
15207                    throws SystemException {
15208                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
15209                            remove(mbMessage);
15210                    }
15211            }
15212    
15213            /**
15214             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
15215             *
15216             * @param groupId the group ID
15217             * @param categoryId the category ID
15218             * @param threadId the thread ID
15219             * @throws SystemException if a system exception occurred
15220             */
15221            public void removeByG_C_T(long groupId, long categoryId, long threadId)
15222                    throws SystemException {
15223                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
15224                            remove(mbMessage);
15225                    }
15226            }
15227    
15228            /**
15229             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
15230             *
15231             * @param groupId the group ID
15232             * @param categoryId the category ID
15233             * @param status the status
15234             * @throws SystemException if a system exception occurred
15235             */
15236            public void removeByG_C_S(long groupId, long categoryId, int status)
15237                    throws SystemException {
15238                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
15239                            remove(mbMessage);
15240                    }
15241            }
15242    
15243            /**
15244             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
15245             *
15246             * @param userId the user ID
15247             * @param classNameId the class name ID
15248             * @param classPK the class p k
15249             * @throws SystemException if a system exception occurred
15250             */
15251            public void removeByU_C_C(long userId, long classNameId, long classPK)
15252                    throws SystemException {
15253                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK)) {
15254                            remove(mbMessage);
15255                    }
15256            }
15257    
15258            /**
15259             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15260             *
15261             * @param userId the user ID
15262             * @param classNameId the class name ID
15263             * @param status the status
15264             * @throws SystemException if a system exception occurred
15265             */
15266            public void removeByU_C_S(long userId, long classNameId, int status)
15267                    throws SystemException {
15268                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status)) {
15269                            remove(mbMessage);
15270                    }
15271            }
15272    
15273            /**
15274             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15275             *
15276             * @param classNameId the class name ID
15277             * @param classPK the class p k
15278             * @param status the status
15279             * @throws SystemException if a system exception occurred
15280             */
15281            public void removeByC_C_S(long classNameId, long classPK, int status)
15282                    throws SystemException {
15283                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
15284                            remove(mbMessage);
15285                    }
15286            }
15287    
15288            /**
15289             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
15290             *
15291             * @param groupId the group ID
15292             * @param categoryId the category ID
15293             * @param threadId the thread ID
15294             * @param answer the answer
15295             * @throws SystemException if a system exception occurred
15296             */
15297            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
15298                    boolean answer) throws SystemException {
15299                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
15300                                    answer)) {
15301                            remove(mbMessage);
15302                    }
15303            }
15304    
15305            /**
15306             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
15307             *
15308             * @param groupId the group ID
15309             * @param categoryId the category ID
15310             * @param threadId the thread ID
15311             * @param status the status
15312             * @throws SystemException if a system exception occurred
15313             */
15314            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
15315                    int status) throws SystemException {
15316                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
15317                                    status)) {
15318                            remove(mbMessage);
15319                    }
15320            }
15321    
15322            /**
15323             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
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             * @throws SystemException if a system exception occurred
15330             */
15331            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
15332                    int status) throws SystemException {
15333                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
15334                                    status)) {
15335                            remove(mbMessage);
15336                    }
15337            }
15338    
15339            /**
15340             * Removes all the message-boards messages from the database.
15341             *
15342             * @throws SystemException if a system exception occurred
15343             */
15344            public void removeAll() throws SystemException {
15345                    for (MBMessage mbMessage : findAll()) {
15346                            remove(mbMessage);
15347                    }
15348            }
15349    
15350            /**
15351             * Returns the number of message-boards messages where uuid = &#63;.
15352             *
15353             * @param uuid the uuid
15354             * @return the number of matching message-boards messages
15355             * @throws SystemException if a system exception occurred
15356             */
15357            public int countByUuid(String uuid) throws SystemException {
15358                    Object[] finderArgs = new Object[] { uuid };
15359    
15360                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
15361                                    finderArgs, this);
15362    
15363                    if (count == null) {
15364                            StringBundler query = new StringBundler(2);
15365    
15366                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15367    
15368                            if (uuid == null) {
15369                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
15370                            }
15371                            else {
15372                                    if (uuid.equals(StringPool.BLANK)) {
15373                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
15374                                    }
15375                                    else {
15376                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
15377                                    }
15378                            }
15379    
15380                            String sql = query.toString();
15381    
15382                            Session session = null;
15383    
15384                            try {
15385                                    session = openSession();
15386    
15387                                    Query q = session.createQuery(sql);
15388    
15389                                    QueryPos qPos = QueryPos.getInstance(q);
15390    
15391                                    if (uuid != null) {
15392                                            qPos.add(uuid);
15393                                    }
15394    
15395                                    count = (Long)q.uniqueResult();
15396                            }
15397                            catch (Exception e) {
15398                                    throw processException(e);
15399                            }
15400                            finally {
15401                                    if (count == null) {
15402                                            count = Long.valueOf(0);
15403                                    }
15404    
15405                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
15406                                            finderArgs, count);
15407    
15408                                    closeSession(session);
15409                            }
15410                    }
15411    
15412                    return count.intValue();
15413            }
15414    
15415            /**
15416             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
15417             *
15418             * @param uuid the uuid
15419             * @param groupId the group ID
15420             * @return the number of matching message-boards messages
15421             * @throws SystemException if a system exception occurred
15422             */
15423            public int countByUUID_G(String uuid, long groupId)
15424                    throws SystemException {
15425                    Object[] finderArgs = new Object[] { uuid, groupId };
15426    
15427                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
15428                                    finderArgs, this);
15429    
15430                    if (count == null) {
15431                            StringBundler query = new StringBundler(3);
15432    
15433                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15434    
15435                            if (uuid == null) {
15436                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
15437                            }
15438                            else {
15439                                    if (uuid.equals(StringPool.BLANK)) {
15440                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
15441                                    }
15442                                    else {
15443                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
15444                                    }
15445                            }
15446    
15447                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
15448    
15449                            String sql = query.toString();
15450    
15451                            Session session = null;
15452    
15453                            try {
15454                                    session = openSession();
15455    
15456                                    Query q = session.createQuery(sql);
15457    
15458                                    QueryPos qPos = QueryPos.getInstance(q);
15459    
15460                                    if (uuid != null) {
15461                                            qPos.add(uuid);
15462                                    }
15463    
15464                                    qPos.add(groupId);
15465    
15466                                    count = (Long)q.uniqueResult();
15467                            }
15468                            catch (Exception e) {
15469                                    throw processException(e);
15470                            }
15471                            finally {
15472                                    if (count == null) {
15473                                            count = Long.valueOf(0);
15474                                    }
15475    
15476                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
15477                                            finderArgs, count);
15478    
15479                                    closeSession(session);
15480                            }
15481                    }
15482    
15483                    return count.intValue();
15484            }
15485    
15486            /**
15487             * Returns the number of message-boards messages where groupId = &#63;.
15488             *
15489             * @param groupId the group ID
15490             * @return the number of matching message-boards messages
15491             * @throws SystemException if a system exception occurred
15492             */
15493            public int countByGroupId(long groupId) throws SystemException {
15494                    Object[] finderArgs = new Object[] { groupId };
15495    
15496                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
15497                                    finderArgs, this);
15498    
15499                    if (count == null) {
15500                            StringBundler query = new StringBundler(2);
15501    
15502                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15503    
15504                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
15505    
15506                            String sql = query.toString();
15507    
15508                            Session session = null;
15509    
15510                            try {
15511                                    session = openSession();
15512    
15513                                    Query q = session.createQuery(sql);
15514    
15515                                    QueryPos qPos = QueryPos.getInstance(q);
15516    
15517                                    qPos.add(groupId);
15518    
15519                                    count = (Long)q.uniqueResult();
15520                            }
15521                            catch (Exception e) {
15522                                    throw processException(e);
15523                            }
15524                            finally {
15525                                    if (count == null) {
15526                                            count = Long.valueOf(0);
15527                                    }
15528    
15529                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
15530                                            finderArgs, count);
15531    
15532                                    closeSession(session);
15533                            }
15534                    }
15535    
15536                    return count.intValue();
15537            }
15538    
15539            /**
15540             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
15541             *
15542             * @param groupId the group ID
15543             * @return the number of matching message-boards messages that the user has permission to view
15544             * @throws SystemException if a system exception occurred
15545             */
15546            public int filterCountByGroupId(long groupId) throws SystemException {
15547                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15548                            return countByGroupId(groupId);
15549                    }
15550    
15551                    StringBundler query = new StringBundler(2);
15552    
15553                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15554    
15555                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
15556    
15557                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15558                                    MBMessage.class.getName(),
15559                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15560    
15561                    Session session = null;
15562    
15563                    try {
15564                            session = openSession();
15565    
15566                            SQLQuery q = session.createSQLQuery(sql);
15567    
15568                            q.addScalar(COUNT_COLUMN_NAME,
15569                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15570    
15571                            QueryPos qPos = QueryPos.getInstance(q);
15572    
15573                            qPos.add(groupId);
15574    
15575                            Long count = (Long)q.uniqueResult();
15576    
15577                            return count.intValue();
15578                    }
15579                    catch (Exception e) {
15580                            throw processException(e);
15581                    }
15582                    finally {
15583                            closeSession(session);
15584                    }
15585            }
15586    
15587            /**
15588             * Returns the number of message-boards messages where companyId = &#63;.
15589             *
15590             * @param companyId the company ID
15591             * @return the number of matching message-boards messages
15592             * @throws SystemException if a system exception occurred
15593             */
15594            public int countByCompanyId(long companyId) throws SystemException {
15595                    Object[] finderArgs = new Object[] { companyId };
15596    
15597                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
15598                                    finderArgs, this);
15599    
15600                    if (count == null) {
15601                            StringBundler query = new StringBundler(2);
15602    
15603                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15604    
15605                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
15606    
15607                            String sql = query.toString();
15608    
15609                            Session session = null;
15610    
15611                            try {
15612                                    session = openSession();
15613    
15614                                    Query q = session.createQuery(sql);
15615    
15616                                    QueryPos qPos = QueryPos.getInstance(q);
15617    
15618                                    qPos.add(companyId);
15619    
15620                                    count = (Long)q.uniqueResult();
15621                            }
15622                            catch (Exception e) {
15623                                    throw processException(e);
15624                            }
15625                            finally {
15626                                    if (count == null) {
15627                                            count = Long.valueOf(0);
15628                                    }
15629    
15630                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
15631                                            finderArgs, count);
15632    
15633                                    closeSession(session);
15634                            }
15635                    }
15636    
15637                    return count.intValue();
15638            }
15639    
15640            /**
15641             * Returns the number of message-boards messages where threadId = &#63;.
15642             *
15643             * @param threadId the thread ID
15644             * @return the number of matching message-boards messages
15645             * @throws SystemException if a system exception occurred
15646             */
15647            public int countByThreadId(long threadId) throws SystemException {
15648                    Object[] finderArgs = new Object[] { threadId };
15649    
15650                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
15651                                    finderArgs, this);
15652    
15653                    if (count == null) {
15654                            StringBundler query = new StringBundler(2);
15655    
15656                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15657    
15658                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
15659    
15660                            String sql = query.toString();
15661    
15662                            Session session = null;
15663    
15664                            try {
15665                                    session = openSession();
15666    
15667                                    Query q = session.createQuery(sql);
15668    
15669                                    QueryPos qPos = QueryPos.getInstance(q);
15670    
15671                                    qPos.add(threadId);
15672    
15673                                    count = (Long)q.uniqueResult();
15674                            }
15675                            catch (Exception e) {
15676                                    throw processException(e);
15677                            }
15678                            finally {
15679                                    if (count == null) {
15680                                            count = Long.valueOf(0);
15681                                    }
15682    
15683                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
15684                                            finderArgs, count);
15685    
15686                                    closeSession(session);
15687                            }
15688                    }
15689    
15690                    return count.intValue();
15691            }
15692    
15693            /**
15694             * Returns the number of message-boards messages where threadId = &#63;.
15695             *
15696             * @param threadId the thread ID
15697             * @return the number of matching message-boards messages
15698             * @throws SystemException if a system exception occurred
15699             */
15700            public int countByThreadReplies(long threadId) throws SystemException {
15701                    Object[] finderArgs = new Object[] { threadId };
15702    
15703                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
15704                                    finderArgs, this);
15705    
15706                    if (count == null) {
15707                            StringBundler query = new StringBundler(2);
15708    
15709                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15710    
15711                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
15712    
15713                            String sql = query.toString();
15714    
15715                            Session session = null;
15716    
15717                            try {
15718                                    session = openSession();
15719    
15720                                    Query q = session.createQuery(sql);
15721    
15722                                    QueryPos qPos = QueryPos.getInstance(q);
15723    
15724                                    qPos.add(threadId);
15725    
15726                                    count = (Long)q.uniqueResult();
15727                            }
15728                            catch (Exception e) {
15729                                    throw processException(e);
15730                            }
15731                            finally {
15732                                    if (count == null) {
15733                                            count = Long.valueOf(0);
15734                                    }
15735    
15736                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
15737                                            finderArgs, count);
15738    
15739                                    closeSession(session);
15740                            }
15741                    }
15742    
15743                    return count.intValue();
15744            }
15745    
15746            /**
15747             * Returns the number of message-boards messages where userId = &#63;.
15748             *
15749             * @param userId the user ID
15750             * @return the number of matching message-boards messages
15751             * @throws SystemException if a system exception occurred
15752             */
15753            public int countByUserId(long userId) throws SystemException {
15754                    Object[] finderArgs = new Object[] { userId };
15755    
15756                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
15757                                    finderArgs, this);
15758    
15759                    if (count == null) {
15760                            StringBundler query = new StringBundler(2);
15761    
15762                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15763    
15764                            query.append(_FINDER_COLUMN_USERID_USERID_2);
15765    
15766                            String sql = query.toString();
15767    
15768                            Session session = null;
15769    
15770                            try {
15771                                    session = openSession();
15772    
15773                                    Query q = session.createQuery(sql);
15774    
15775                                    QueryPos qPos = QueryPos.getInstance(q);
15776    
15777                                    qPos.add(userId);
15778    
15779                                    count = (Long)q.uniqueResult();
15780                            }
15781                            catch (Exception e) {
15782                                    throw processException(e);
15783                            }
15784                            finally {
15785                                    if (count == null) {
15786                                            count = Long.valueOf(0);
15787                                    }
15788    
15789                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
15790                                            finderArgs, count);
15791    
15792                                    closeSession(session);
15793                            }
15794                    }
15795    
15796                    return count.intValue();
15797            }
15798    
15799            /**
15800             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
15801             *
15802             * @param groupId the group ID
15803             * @param userId the user ID
15804             * @return the number of matching message-boards messages
15805             * @throws SystemException if a system exception occurred
15806             */
15807            public int countByG_U(long groupId, long userId) throws SystemException {
15808                    Object[] finderArgs = new Object[] { groupId, userId };
15809    
15810                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
15811                                    finderArgs, this);
15812    
15813                    if (count == null) {
15814                            StringBundler query = new StringBundler(3);
15815    
15816                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15817    
15818                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
15819    
15820                            query.append(_FINDER_COLUMN_G_U_USERID_2);
15821    
15822                            String sql = query.toString();
15823    
15824                            Session session = null;
15825    
15826                            try {
15827                                    session = openSession();
15828    
15829                                    Query q = session.createQuery(sql);
15830    
15831                                    QueryPos qPos = QueryPos.getInstance(q);
15832    
15833                                    qPos.add(groupId);
15834    
15835                                    qPos.add(userId);
15836    
15837                                    count = (Long)q.uniqueResult();
15838                            }
15839                            catch (Exception e) {
15840                                    throw processException(e);
15841                            }
15842                            finally {
15843                                    if (count == null) {
15844                                            count = Long.valueOf(0);
15845                                    }
15846    
15847                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
15848                                            count);
15849    
15850                                    closeSession(session);
15851                            }
15852                    }
15853    
15854                    return count.intValue();
15855            }
15856    
15857            /**
15858             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
15859             *
15860             * @param groupId the group ID
15861             * @param userId the user ID
15862             * @return the number of matching message-boards messages that the user has permission to view
15863             * @throws SystemException if a system exception occurred
15864             */
15865            public int filterCountByG_U(long groupId, long userId)
15866                    throws SystemException {
15867                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15868                            return countByG_U(groupId, userId);
15869                    }
15870    
15871                    StringBundler query = new StringBundler(3);
15872    
15873                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15874    
15875                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
15876    
15877                    query.append(_FINDER_COLUMN_G_U_USERID_2);
15878    
15879                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15880                                    MBMessage.class.getName(),
15881                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15882    
15883                    Session session = null;
15884    
15885                    try {
15886                            session = openSession();
15887    
15888                            SQLQuery q = session.createSQLQuery(sql);
15889    
15890                            q.addScalar(COUNT_COLUMN_NAME,
15891                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15892    
15893                            QueryPos qPos = QueryPos.getInstance(q);
15894    
15895                            qPos.add(groupId);
15896    
15897                            qPos.add(userId);
15898    
15899                            Long count = (Long)q.uniqueResult();
15900    
15901                            return count.intValue();
15902                    }
15903                    catch (Exception e) {
15904                            throw processException(e);
15905                    }
15906                    finally {
15907                            closeSession(session);
15908                    }
15909            }
15910    
15911            /**
15912             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
15913             *
15914             * @param groupId the group ID
15915             * @param categoryId the category ID
15916             * @return the number of matching message-boards messages
15917             * @throws SystemException if a system exception occurred
15918             */
15919            public int countByG_C(long groupId, long categoryId)
15920                    throws SystemException {
15921                    Object[] finderArgs = new Object[] { groupId, categoryId };
15922    
15923                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
15924                                    finderArgs, this);
15925    
15926                    if (count == null) {
15927                            StringBundler query = new StringBundler(3);
15928    
15929                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15930    
15931                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
15932    
15933                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
15934    
15935                            String sql = query.toString();
15936    
15937                            Session session = null;
15938    
15939                            try {
15940                                    session = openSession();
15941    
15942                                    Query q = session.createQuery(sql);
15943    
15944                                    QueryPos qPos = QueryPos.getInstance(q);
15945    
15946                                    qPos.add(groupId);
15947    
15948                                    qPos.add(categoryId);
15949    
15950                                    count = (Long)q.uniqueResult();
15951                            }
15952                            catch (Exception e) {
15953                                    throw processException(e);
15954                            }
15955                            finally {
15956                                    if (count == null) {
15957                                            count = Long.valueOf(0);
15958                                    }
15959    
15960                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
15961                                            count);
15962    
15963                                    closeSession(session);
15964                            }
15965                    }
15966    
15967                    return count.intValue();
15968            }
15969    
15970            /**
15971             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
15972             *
15973             * @param groupId the group ID
15974             * @param categoryId the category ID
15975             * @return the number of matching message-boards messages that the user has permission to view
15976             * @throws SystemException if a system exception occurred
15977             */
15978            public int filterCountByG_C(long groupId, long categoryId)
15979                    throws SystemException {
15980                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15981                            return countByG_C(groupId, categoryId);
15982                    }
15983    
15984                    StringBundler query = new StringBundler(3);
15985    
15986                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15987    
15988                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
15989    
15990                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
15991    
15992                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15993                                    MBMessage.class.getName(),
15994                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15995    
15996                    Session session = null;
15997    
15998                    try {
15999                            session = openSession();
16000    
16001                            SQLQuery q = session.createSQLQuery(sql);
16002    
16003                            q.addScalar(COUNT_COLUMN_NAME,
16004                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16005    
16006                            QueryPos qPos = QueryPos.getInstance(q);
16007    
16008                            qPos.add(groupId);
16009    
16010                            qPos.add(categoryId);
16011    
16012                            Long count = (Long)q.uniqueResult();
16013    
16014                            return count.intValue();
16015                    }
16016                    catch (Exception e) {
16017                            throw processException(e);
16018                    }
16019                    finally {
16020                            closeSession(session);
16021                    }
16022            }
16023    
16024            /**
16025             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
16026             *
16027             * @param groupId the group ID
16028             * @param status the status
16029             * @return the number of matching message-boards messages
16030             * @throws SystemException if a system exception occurred
16031             */
16032            public int countByG_S(long groupId, int status) throws SystemException {
16033                    Object[] finderArgs = new Object[] { groupId, status };
16034    
16035                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
16036                                    finderArgs, this);
16037    
16038                    if (count == null) {
16039                            StringBundler query = new StringBundler(3);
16040    
16041                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16042    
16043                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
16044    
16045                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
16046    
16047                            String sql = query.toString();
16048    
16049                            Session session = null;
16050    
16051                            try {
16052                                    session = openSession();
16053    
16054                                    Query q = session.createQuery(sql);
16055    
16056                                    QueryPos qPos = QueryPos.getInstance(q);
16057    
16058                                    qPos.add(groupId);
16059    
16060                                    qPos.add(status);
16061    
16062                                    count = (Long)q.uniqueResult();
16063                            }
16064                            catch (Exception e) {
16065                                    throw processException(e);
16066                            }
16067                            finally {
16068                                    if (count == null) {
16069                                            count = Long.valueOf(0);
16070                                    }
16071    
16072                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
16073                                            count);
16074    
16075                                    closeSession(session);
16076                            }
16077                    }
16078    
16079                    return count.intValue();
16080            }
16081    
16082            /**
16083             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
16084             *
16085             * @param groupId the group ID
16086             * @param status the status
16087             * @return the number of matching message-boards messages that the user has permission to view
16088             * @throws SystemException if a system exception occurred
16089             */
16090            public int filterCountByG_S(long groupId, int status)
16091                    throws SystemException {
16092                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16093                            return countByG_S(groupId, status);
16094                    }
16095    
16096                    StringBundler query = new StringBundler(3);
16097    
16098                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16099    
16100                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
16101    
16102                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
16103    
16104                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16105                                    MBMessage.class.getName(),
16106                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16107    
16108                    Session session = null;
16109    
16110                    try {
16111                            session = openSession();
16112    
16113                            SQLQuery q = session.createSQLQuery(sql);
16114    
16115                            q.addScalar(COUNT_COLUMN_NAME,
16116                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16117    
16118                            QueryPos qPos = QueryPos.getInstance(q);
16119    
16120                            qPos.add(groupId);
16121    
16122                            qPos.add(status);
16123    
16124                            Long count = (Long)q.uniqueResult();
16125    
16126                            return count.intValue();
16127                    }
16128                    catch (Exception e) {
16129                            throw processException(e);
16130                    }
16131                    finally {
16132                            closeSession(session);
16133                    }
16134            }
16135    
16136            /**
16137             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
16138             *
16139             * @param companyId the company ID
16140             * @param status the status
16141             * @return the number of matching message-boards messages
16142             * @throws SystemException if a system exception occurred
16143             */
16144            public int countByC_S(long companyId, int status) throws SystemException {
16145                    Object[] finderArgs = new Object[] { companyId, status };
16146    
16147                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
16148                                    finderArgs, this);
16149    
16150                    if (count == null) {
16151                            StringBundler query = new StringBundler(3);
16152    
16153                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16154    
16155                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
16156    
16157                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
16158    
16159                            String sql = query.toString();
16160    
16161                            Session session = null;
16162    
16163                            try {
16164                                    session = openSession();
16165    
16166                                    Query q = session.createQuery(sql);
16167    
16168                                    QueryPos qPos = QueryPos.getInstance(q);
16169    
16170                                    qPos.add(companyId);
16171    
16172                                    qPos.add(status);
16173    
16174                                    count = (Long)q.uniqueResult();
16175                            }
16176                            catch (Exception e) {
16177                                    throw processException(e);
16178                            }
16179                            finally {
16180                                    if (count == null) {
16181                                            count = Long.valueOf(0);
16182                                    }
16183    
16184                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
16185                                            count);
16186    
16187                                    closeSession(session);
16188                            }
16189                    }
16190    
16191                    return count.intValue();
16192            }
16193    
16194            /**
16195             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
16196             *
16197             * @param userId the user ID
16198             * @param classNameId the class name ID
16199             * @return the number of matching message-boards messages
16200             * @throws SystemException if a system exception occurred
16201             */
16202            public int countByU_C(long userId, long classNameId)
16203                    throws SystemException {
16204                    Object[] finderArgs = new Object[] { userId, classNameId };
16205    
16206                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
16207                                    finderArgs, this);
16208    
16209                    if (count == null) {
16210                            StringBundler query = new StringBundler(3);
16211    
16212                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16213    
16214                            query.append(_FINDER_COLUMN_U_C_USERID_2);
16215    
16216                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
16217    
16218                            String sql = query.toString();
16219    
16220                            Session session = null;
16221    
16222                            try {
16223                                    session = openSession();
16224    
16225                                    Query q = session.createQuery(sql);
16226    
16227                                    QueryPos qPos = QueryPos.getInstance(q);
16228    
16229                                    qPos.add(userId);
16230    
16231                                    qPos.add(classNameId);
16232    
16233                                    count = (Long)q.uniqueResult();
16234                            }
16235                            catch (Exception e) {
16236                                    throw processException(e);
16237                            }
16238                            finally {
16239                                    if (count == null) {
16240                                            count = Long.valueOf(0);
16241                                    }
16242    
16243                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
16244                                            count);
16245    
16246                                    closeSession(session);
16247                            }
16248                    }
16249    
16250                    return count.intValue();
16251            }
16252    
16253            /**
16254             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
16255             *
16256             * @param userId the user ID
16257             * @param classNameIds the class name IDs
16258             * @return the number of matching message-boards messages
16259             * @throws SystemException if a system exception occurred
16260             */
16261            public int countByU_C(long userId, long[] classNameIds)
16262                    throws SystemException {
16263                    Object[] finderArgs = new Object[] {
16264                                    userId, StringUtil.merge(classNameIds)
16265                            };
16266    
16267                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
16268                                    finderArgs, this);
16269    
16270                    if (count == null) {
16271                            StringBundler query = new StringBundler();
16272    
16273                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16274    
16275                            boolean conjunctionable = false;
16276    
16277                            if (conjunctionable) {
16278                                    query.append(WHERE_AND);
16279                            }
16280    
16281                            query.append(_FINDER_COLUMN_U_C_USERID_5);
16282    
16283                            conjunctionable = true;
16284    
16285                            if ((classNameIds == null) || (classNameIds.length > 0)) {
16286                                    if (conjunctionable) {
16287                                            query.append(WHERE_AND);
16288                                    }
16289    
16290                                    query.append(StringPool.OPEN_PARENTHESIS);
16291    
16292                                    for (int i = 0; i < classNameIds.length; i++) {
16293                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
16294    
16295                                            if ((i + 1) < classNameIds.length) {
16296                                                    query.append(WHERE_OR);
16297                                            }
16298                                    }
16299    
16300                                    query.append(StringPool.CLOSE_PARENTHESIS);
16301    
16302                                    conjunctionable = true;
16303                            }
16304    
16305                            String sql = query.toString();
16306    
16307                            Session session = null;
16308    
16309                            try {
16310                                    session = openSession();
16311    
16312                                    Query q = session.createQuery(sql);
16313    
16314                                    QueryPos qPos = QueryPos.getInstance(q);
16315    
16316                                    qPos.add(userId);
16317    
16318                                    if (classNameIds != null) {
16319                                            qPos.add(classNameIds);
16320                                    }
16321    
16322                                    count = (Long)q.uniqueResult();
16323                            }
16324                            catch (Exception e) {
16325                                    throw processException(e);
16326                            }
16327                            finally {
16328                                    if (count == null) {
16329                                            count = Long.valueOf(0);
16330                                    }
16331    
16332                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
16333                                            finderArgs, count);
16334    
16335                                    closeSession(session);
16336                            }
16337                    }
16338    
16339                    return count.intValue();
16340            }
16341    
16342            /**
16343             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
16344             *
16345             * @param classNameId the class name ID
16346             * @param classPK the class p k
16347             * @return the number of matching message-boards messages
16348             * @throws SystemException if a system exception occurred
16349             */
16350            public int countByC_C(long classNameId, long classPK)
16351                    throws SystemException {
16352                    Object[] finderArgs = new Object[] { classNameId, classPK };
16353    
16354                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
16355                                    finderArgs, this);
16356    
16357                    if (count == null) {
16358                            StringBundler query = new StringBundler(3);
16359    
16360                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16361    
16362                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
16363    
16364                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
16365    
16366                            String sql = query.toString();
16367    
16368                            Session session = null;
16369    
16370                            try {
16371                                    session = openSession();
16372    
16373                                    Query q = session.createQuery(sql);
16374    
16375                                    QueryPos qPos = QueryPos.getInstance(q);
16376    
16377                                    qPos.add(classNameId);
16378    
16379                                    qPos.add(classPK);
16380    
16381                                    count = (Long)q.uniqueResult();
16382                            }
16383                            catch (Exception e) {
16384                                    throw processException(e);
16385                            }
16386                            finally {
16387                                    if (count == null) {
16388                                            count = Long.valueOf(0);
16389                                    }
16390    
16391                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
16392                                            count);
16393    
16394                                    closeSession(session);
16395                            }
16396                    }
16397    
16398                    return count.intValue();
16399            }
16400    
16401            /**
16402             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
16403             *
16404             * @param threadId the thread ID
16405             * @param parentMessageId the parent message ID
16406             * @return the number of matching message-boards messages
16407             * @throws SystemException if a system exception occurred
16408             */
16409            public int countByT_P(long threadId, long parentMessageId)
16410                    throws SystemException {
16411                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
16412    
16413                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
16414                                    finderArgs, this);
16415    
16416                    if (count == null) {
16417                            StringBundler query = new StringBundler(3);
16418    
16419                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16420    
16421                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
16422    
16423                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
16424    
16425                            String sql = query.toString();
16426    
16427                            Session session = null;
16428    
16429                            try {
16430                                    session = openSession();
16431    
16432                                    Query q = session.createQuery(sql);
16433    
16434                                    QueryPos qPos = QueryPos.getInstance(q);
16435    
16436                                    qPos.add(threadId);
16437    
16438                                    qPos.add(parentMessageId);
16439    
16440                                    count = (Long)q.uniqueResult();
16441                            }
16442                            catch (Exception e) {
16443                                    throw processException(e);
16444                            }
16445                            finally {
16446                                    if (count == null) {
16447                                            count = Long.valueOf(0);
16448                                    }
16449    
16450                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
16451                                            count);
16452    
16453                                    closeSession(session);
16454                            }
16455                    }
16456    
16457                    return count.intValue();
16458            }
16459    
16460            /**
16461             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
16462             *
16463             * @param threadId the thread ID
16464             * @param answer the answer
16465             * @return the number of matching message-boards messages
16466             * @throws SystemException if a system exception occurred
16467             */
16468            public int countByT_A(long threadId, boolean answer)
16469                    throws SystemException {
16470                    Object[] finderArgs = new Object[] { threadId, answer };
16471    
16472                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_A,
16473                                    finderArgs, this);
16474    
16475                    if (count == null) {
16476                            StringBundler query = new StringBundler(3);
16477    
16478                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16479    
16480                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
16481    
16482                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
16483    
16484                            String sql = query.toString();
16485    
16486                            Session session = null;
16487    
16488                            try {
16489                                    session = openSession();
16490    
16491                                    Query q = session.createQuery(sql);
16492    
16493                                    QueryPos qPos = QueryPos.getInstance(q);
16494    
16495                                    qPos.add(threadId);
16496    
16497                                    qPos.add(answer);
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_T_A, finderArgs,
16510                                            count);
16511    
16512                                    closeSession(session);
16513                            }
16514                    }
16515    
16516                    return count.intValue();
16517            }
16518    
16519            /**
16520             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
16521             *
16522             * @param threadId the thread ID
16523             * @param status the status
16524             * @return the number of matching message-boards messages
16525             * @throws SystemException if a system exception occurred
16526             */
16527            public int countByT_S(long threadId, int status) throws SystemException {
16528                    Object[] finderArgs = new Object[] { threadId, status };
16529    
16530                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
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_T_S_THREADID_2);
16539    
16540                            query.append(_FINDER_COLUMN_T_S_STATUS_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(threadId);
16554    
16555                                    qPos.add(status);
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_T_S, 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 where threadId = &#63; and status = &#63;.
16579             *
16580             * @param threadId the thread ID
16581             * @param status the status
16582             * @return the number of matching message-boards messages
16583             * @throws SystemException if a system exception occurred
16584             */
16585            public int countByTR_S(long threadId, int status) throws SystemException {
16586                    Object[] finderArgs = new Object[] { threadId, status };
16587    
16588                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
16589                                    finderArgs, this);
16590    
16591                    if (count == null) {
16592                            StringBundler query = new StringBundler(3);
16593    
16594                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16595    
16596                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
16597    
16598                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
16599    
16600                            String sql = query.toString();
16601    
16602                            Session session = null;
16603    
16604                            try {
16605                                    session = openSession();
16606    
16607                                    Query q = session.createQuery(sql);
16608    
16609                                    QueryPos qPos = QueryPos.getInstance(q);
16610    
16611                                    qPos.add(threadId);
16612    
16613                                    qPos.add(status);
16614    
16615                                    count = (Long)q.uniqueResult();
16616                            }
16617                            catch (Exception e) {
16618                                    throw processException(e);
16619                            }
16620                            finally {
16621                                    if (count == null) {
16622                                            count = Long.valueOf(0);
16623                                    }
16624    
16625                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
16626                                            finderArgs, count);
16627    
16628                                    closeSession(session);
16629                            }
16630                    }
16631    
16632                    return count.intValue();
16633            }
16634    
16635            /**
16636             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
16637             *
16638             * @param groupId the group ID
16639             * @param userId the user ID
16640             * @param status the status
16641             * @return the number of matching message-boards messages
16642             * @throws SystemException if a system exception occurred
16643             */
16644            public int countByG_U_S(long groupId, long userId, int status)
16645                    throws SystemException {
16646                    Object[] finderArgs = new Object[] { groupId, userId, status };
16647    
16648                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
16649                                    finderArgs, this);
16650    
16651                    if (count == null) {
16652                            StringBundler query = new StringBundler(4);
16653    
16654                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16655    
16656                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
16657    
16658                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
16659    
16660                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
16661    
16662                            String sql = query.toString();
16663    
16664                            Session session = null;
16665    
16666                            try {
16667                                    session = openSession();
16668    
16669                                    Query q = session.createQuery(sql);
16670    
16671                                    QueryPos qPos = QueryPos.getInstance(q);
16672    
16673                                    qPos.add(groupId);
16674    
16675                                    qPos.add(userId);
16676    
16677                                    qPos.add(status);
16678    
16679                                    count = (Long)q.uniqueResult();
16680                            }
16681                            catch (Exception e) {
16682                                    throw processException(e);
16683                            }
16684                            finally {
16685                                    if (count == null) {
16686                                            count = Long.valueOf(0);
16687                                    }
16688    
16689                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
16690                                            finderArgs, count);
16691    
16692                                    closeSession(session);
16693                            }
16694                    }
16695    
16696                    return count.intValue();
16697            }
16698    
16699            /**
16700             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
16701             *
16702             * @param groupId the group ID
16703             * @param userId the user ID
16704             * @param status the status
16705             * @return the number of matching message-boards messages that the user has permission to view
16706             * @throws SystemException if a system exception occurred
16707             */
16708            public int filterCountByG_U_S(long groupId, long userId, int status)
16709                    throws SystemException {
16710                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16711                            return countByG_U_S(groupId, userId, status);
16712                    }
16713    
16714                    StringBundler query = new StringBundler(4);
16715    
16716                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16717    
16718                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
16719    
16720                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
16721    
16722                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
16723    
16724                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16725                                    MBMessage.class.getName(),
16726                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16727    
16728                    Session session = null;
16729    
16730                    try {
16731                            session = openSession();
16732    
16733                            SQLQuery q = session.createSQLQuery(sql);
16734    
16735                            q.addScalar(COUNT_COLUMN_NAME,
16736                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16737    
16738                            QueryPos qPos = QueryPos.getInstance(q);
16739    
16740                            qPos.add(groupId);
16741    
16742                            qPos.add(userId);
16743    
16744                            qPos.add(status);
16745    
16746                            Long count = (Long)q.uniqueResult();
16747    
16748                            return count.intValue();
16749                    }
16750                    catch (Exception e) {
16751                            throw processException(e);
16752                    }
16753                    finally {
16754                            closeSession(session);
16755                    }
16756            }
16757    
16758            /**
16759             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
16760             *
16761             * @param groupId the group ID
16762             * @param categoryId the category ID
16763             * @param threadId the thread ID
16764             * @return the number of matching message-boards messages
16765             * @throws SystemException if a system exception occurred
16766             */
16767            public int countByG_C_T(long groupId, long categoryId, long threadId)
16768                    throws SystemException {
16769                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
16770    
16771                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
16772                                    finderArgs, this);
16773    
16774                    if (count == null) {
16775                            StringBundler query = new StringBundler(4);
16776    
16777                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16778    
16779                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
16780    
16781                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
16782    
16783                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
16784    
16785                            String sql = query.toString();
16786    
16787                            Session session = null;
16788    
16789                            try {
16790                                    session = openSession();
16791    
16792                                    Query q = session.createQuery(sql);
16793    
16794                                    QueryPos qPos = QueryPos.getInstance(q);
16795    
16796                                    qPos.add(groupId);
16797    
16798                                    qPos.add(categoryId);
16799    
16800                                    qPos.add(threadId);
16801    
16802                                    count = (Long)q.uniqueResult();
16803                            }
16804                            catch (Exception e) {
16805                                    throw processException(e);
16806                            }
16807                            finally {
16808                                    if (count == null) {
16809                                            count = Long.valueOf(0);
16810                                    }
16811    
16812                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
16813                                            finderArgs, count);
16814    
16815                                    closeSession(session);
16816                            }
16817                    }
16818    
16819                    return count.intValue();
16820            }
16821    
16822            /**
16823             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
16824             *
16825             * @param groupId the group ID
16826             * @param categoryId the category ID
16827             * @param threadId the thread ID
16828             * @return the number of matching message-boards messages that the user has permission to view
16829             * @throws SystemException if a system exception occurred
16830             */
16831            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
16832                    throws SystemException {
16833                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16834                            return countByG_C_T(groupId, categoryId, threadId);
16835                    }
16836    
16837                    StringBundler query = new StringBundler(4);
16838    
16839                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16840    
16841                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
16842    
16843                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
16844    
16845                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
16846    
16847                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16848                                    MBMessage.class.getName(),
16849                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16850    
16851                    Session session = null;
16852    
16853                    try {
16854                            session = openSession();
16855    
16856                            SQLQuery q = session.createSQLQuery(sql);
16857    
16858                            q.addScalar(COUNT_COLUMN_NAME,
16859                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16860    
16861                            QueryPos qPos = QueryPos.getInstance(q);
16862    
16863                            qPos.add(groupId);
16864    
16865                            qPos.add(categoryId);
16866    
16867                            qPos.add(threadId);
16868    
16869                            Long count = (Long)q.uniqueResult();
16870    
16871                            return count.intValue();
16872                    }
16873                    catch (Exception e) {
16874                            throw processException(e);
16875                    }
16876                    finally {
16877                            closeSession(session);
16878                    }
16879            }
16880    
16881            /**
16882             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
16883             *
16884             * @param groupId the group ID
16885             * @param categoryId the category ID
16886             * @param status the status
16887             * @return the number of matching message-boards messages
16888             * @throws SystemException if a system exception occurred
16889             */
16890            public int countByG_C_S(long groupId, long categoryId, int status)
16891                    throws SystemException {
16892                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
16893    
16894                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
16895                                    finderArgs, this);
16896    
16897                    if (count == null) {
16898                            StringBundler query = new StringBundler(4);
16899    
16900                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16901    
16902                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
16903    
16904                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
16905    
16906                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
16907    
16908                            String sql = query.toString();
16909    
16910                            Session session = null;
16911    
16912                            try {
16913                                    session = openSession();
16914    
16915                                    Query q = session.createQuery(sql);
16916    
16917                                    QueryPos qPos = QueryPos.getInstance(q);
16918    
16919                                    qPos.add(groupId);
16920    
16921                                    qPos.add(categoryId);
16922    
16923                                    qPos.add(status);
16924    
16925                                    count = (Long)q.uniqueResult();
16926                            }
16927                            catch (Exception e) {
16928                                    throw processException(e);
16929                            }
16930                            finally {
16931                                    if (count == null) {
16932                                            count = Long.valueOf(0);
16933                                    }
16934    
16935                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
16936                                            finderArgs, count);
16937    
16938                                    closeSession(session);
16939                            }
16940                    }
16941    
16942                    return count.intValue();
16943            }
16944    
16945            /**
16946             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
16947             *
16948             * @param groupId the group ID
16949             * @param categoryId the category ID
16950             * @param status the status
16951             * @return the number of matching message-boards messages that the user has permission to view
16952             * @throws SystemException if a system exception occurred
16953             */
16954            public int filterCountByG_C_S(long groupId, long categoryId, int status)
16955                    throws SystemException {
16956                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16957                            return countByG_C_S(groupId, categoryId, status);
16958                    }
16959    
16960                    StringBundler query = new StringBundler(4);
16961    
16962                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16963    
16964                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
16965    
16966                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
16967    
16968                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
16969    
16970                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16971                                    MBMessage.class.getName(),
16972                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16973    
16974                    Session session = null;
16975    
16976                    try {
16977                            session = openSession();
16978    
16979                            SQLQuery q = session.createSQLQuery(sql);
16980    
16981                            q.addScalar(COUNT_COLUMN_NAME,
16982                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16983    
16984                            QueryPos qPos = QueryPos.getInstance(q);
16985    
16986                            qPos.add(groupId);
16987    
16988                            qPos.add(categoryId);
16989    
16990                            qPos.add(status);
16991    
16992                            Long count = (Long)q.uniqueResult();
16993    
16994                            return count.intValue();
16995                    }
16996                    catch (Exception e) {
16997                            throw processException(e);
16998                    }
16999                    finally {
17000                            closeSession(session);
17001                    }
17002            }
17003    
17004            /**
17005             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
17006             *
17007             * @param userId the user ID
17008             * @param classNameId the class name ID
17009             * @param classPK the class p k
17010             * @return the number of matching message-boards messages
17011             * @throws SystemException if a system exception occurred
17012             */
17013            public int countByU_C_C(long userId, long classNameId, long classPK)
17014                    throws SystemException {
17015                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
17016    
17017                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
17018                                    finderArgs, this);
17019    
17020                    if (count == null) {
17021                            StringBundler query = new StringBundler(4);
17022    
17023                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17024    
17025                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
17026    
17027                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
17028    
17029                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
17030    
17031                            String sql = query.toString();
17032    
17033                            Session session = null;
17034    
17035                            try {
17036                                    session = openSession();
17037    
17038                                    Query q = session.createQuery(sql);
17039    
17040                                    QueryPos qPos = QueryPos.getInstance(q);
17041    
17042                                    qPos.add(userId);
17043    
17044                                    qPos.add(classNameId);
17045    
17046                                    qPos.add(classPK);
17047    
17048                                    count = (Long)q.uniqueResult();
17049                            }
17050                            catch (Exception e) {
17051                                    throw processException(e);
17052                            }
17053                            finally {
17054                                    if (count == null) {
17055                                            count = Long.valueOf(0);
17056                                    }
17057    
17058                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
17059                                            finderArgs, count);
17060    
17061                                    closeSession(session);
17062                            }
17063                    }
17064    
17065                    return count.intValue();
17066            }
17067    
17068            /**
17069             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
17070             *
17071             * @param userId the user ID
17072             * @param classNameId the class name ID
17073             * @param status the status
17074             * @return the number of matching message-boards messages
17075             * @throws SystemException if a system exception occurred
17076             */
17077            public int countByU_C_S(long userId, long classNameId, int status)
17078                    throws SystemException {
17079                    Object[] finderArgs = new Object[] { userId, classNameId, status };
17080    
17081                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_S,
17082                                    finderArgs, this);
17083    
17084                    if (count == null) {
17085                            StringBundler query = new StringBundler(4);
17086    
17087                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17088    
17089                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
17090    
17091                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
17092    
17093                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
17094    
17095                            String sql = query.toString();
17096    
17097                            Session session = null;
17098    
17099                            try {
17100                                    session = openSession();
17101    
17102                                    Query q = session.createQuery(sql);
17103    
17104                                    QueryPos qPos = QueryPos.getInstance(q);
17105    
17106                                    qPos.add(userId);
17107    
17108                                    qPos.add(classNameId);
17109    
17110                                    qPos.add(status);
17111    
17112                                    count = (Long)q.uniqueResult();
17113                            }
17114                            catch (Exception e) {
17115                                    throw processException(e);
17116                            }
17117                            finally {
17118                                    if (count == null) {
17119                                            count = Long.valueOf(0);
17120                                    }
17121    
17122                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_S,
17123                                            finderArgs, count);
17124    
17125                                    closeSession(session);
17126                            }
17127                    }
17128    
17129                    return count.intValue();
17130            }
17131    
17132            /**
17133             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
17134             *
17135             * @param userId the user ID
17136             * @param classNameIds the class name IDs
17137             * @param status the status
17138             * @return the number of matching message-boards messages
17139             * @throws SystemException if a system exception occurred
17140             */
17141            public int countByU_C_S(long userId, long[] classNameIds, int status)
17142                    throws SystemException {
17143                    Object[] finderArgs = new Object[] {
17144                                    userId, StringUtil.merge(classNameIds), status
17145                            };
17146    
17147                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
17148                                    finderArgs, this);
17149    
17150                    if (count == null) {
17151                            StringBundler query = new StringBundler();
17152    
17153                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17154    
17155                            boolean conjunctionable = false;
17156    
17157                            if (conjunctionable) {
17158                                    query.append(WHERE_AND);
17159                            }
17160    
17161                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
17162    
17163                            conjunctionable = true;
17164    
17165                            if ((classNameIds == null) || (classNameIds.length > 0)) {
17166                                    if (conjunctionable) {
17167                                            query.append(WHERE_AND);
17168                                    }
17169    
17170                                    query.append(StringPool.OPEN_PARENTHESIS);
17171    
17172                                    for (int i = 0; i < classNameIds.length; i++) {
17173                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
17174    
17175                                            if ((i + 1) < classNameIds.length) {
17176                                                    query.append(WHERE_OR);
17177                                            }
17178                                    }
17179    
17180                                    query.append(StringPool.CLOSE_PARENTHESIS);
17181    
17182                                    conjunctionable = true;
17183                            }
17184    
17185                            if (conjunctionable) {
17186                                    query.append(WHERE_AND);
17187                            }
17188    
17189                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
17190    
17191                            conjunctionable = true;
17192    
17193                            String sql = query.toString();
17194    
17195                            Session session = null;
17196    
17197                            try {
17198                                    session = openSession();
17199    
17200                                    Query q = session.createQuery(sql);
17201    
17202                                    QueryPos qPos = QueryPos.getInstance(q);
17203    
17204                                    qPos.add(userId);
17205    
17206                                    if (classNameIds != null) {
17207                                            qPos.add(classNameIds);
17208                                    }
17209    
17210                                    qPos.add(status);
17211    
17212                                    count = (Long)q.uniqueResult();
17213                            }
17214                            catch (Exception e) {
17215                                    throw processException(e);
17216                            }
17217                            finally {
17218                                    if (count == null) {
17219                                            count = Long.valueOf(0);
17220                                    }
17221    
17222                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
17223                                            finderArgs, count);
17224    
17225                                    closeSession(session);
17226                            }
17227                    }
17228    
17229                    return count.intValue();
17230            }
17231    
17232            /**
17233             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
17234             *
17235             * @param classNameId the class name ID
17236             * @param classPK the class p k
17237             * @param status the status
17238             * @return the number of matching message-boards messages
17239             * @throws SystemException if a system exception occurred
17240             */
17241            public int countByC_C_S(long classNameId, long classPK, int status)
17242                    throws SystemException {
17243                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
17244    
17245                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
17246                                    finderArgs, this);
17247    
17248                    if (count == null) {
17249                            StringBundler query = new StringBundler(4);
17250    
17251                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17252    
17253                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
17254    
17255                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
17256    
17257                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
17258    
17259                            String sql = query.toString();
17260    
17261                            Session session = null;
17262    
17263                            try {
17264                                    session = openSession();
17265    
17266                                    Query q = session.createQuery(sql);
17267    
17268                                    QueryPos qPos = QueryPos.getInstance(q);
17269    
17270                                    qPos.add(classNameId);
17271    
17272                                    qPos.add(classPK);
17273    
17274                                    qPos.add(status);
17275    
17276                                    count = (Long)q.uniqueResult();
17277                            }
17278                            catch (Exception e) {
17279                                    throw processException(e);
17280                            }
17281                            finally {
17282                                    if (count == null) {
17283                                            count = Long.valueOf(0);
17284                                    }
17285    
17286                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
17287                                            finderArgs, count);
17288    
17289                                    closeSession(session);
17290                            }
17291                    }
17292    
17293                    return count.intValue();
17294            }
17295    
17296            /**
17297             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17298             *
17299             * @param groupId the group ID
17300             * @param categoryId the category ID
17301             * @param threadId the thread ID
17302             * @param answer the answer
17303             * @return the number of matching message-boards messages
17304             * @throws SystemException if a system exception occurred
17305             */
17306            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17307                    boolean answer) throws SystemException {
17308                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17309    
17310                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_A,
17311                                    finderArgs, this);
17312    
17313                    if (count == null) {
17314                            StringBundler query = new StringBundler(5);
17315    
17316                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17317    
17318                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17319    
17320                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17321    
17322                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17323    
17324                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17325    
17326                            String sql = query.toString();
17327    
17328                            Session session = null;
17329    
17330                            try {
17331                                    session = openSession();
17332    
17333                                    Query q = session.createQuery(sql);
17334    
17335                                    QueryPos qPos = QueryPos.getInstance(q);
17336    
17337                                    qPos.add(groupId);
17338    
17339                                    qPos.add(categoryId);
17340    
17341                                    qPos.add(threadId);
17342    
17343                                    qPos.add(answer);
17344    
17345                                    count = (Long)q.uniqueResult();
17346                            }
17347                            catch (Exception e) {
17348                                    throw processException(e);
17349                            }
17350                            finally {
17351                                    if (count == null) {
17352                                            count = Long.valueOf(0);
17353                                    }
17354    
17355                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_A,
17356                                            finderArgs, count);
17357    
17358                                    closeSession(session);
17359                            }
17360                    }
17361    
17362                    return count.intValue();
17363            }
17364    
17365            /**
17366             * 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;.
17367             *
17368             * @param groupId the group ID
17369             * @param categoryId the category ID
17370             * @param threadId the thread ID
17371             * @param answer the answer
17372             * @return the number of matching message-boards messages that the user has permission to view
17373             * @throws SystemException if a system exception occurred
17374             */
17375            public int filterCountByG_C_T_A(long groupId, long categoryId,
17376                    long threadId, boolean answer) throws SystemException {
17377                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17378                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17379                    }
17380    
17381                    StringBundler query = new StringBundler(5);
17382    
17383                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17384    
17385                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17386    
17387                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17388    
17389                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17390    
17391                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17392    
17393                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17394                                    MBMessage.class.getName(),
17395                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17396    
17397                    Session session = null;
17398    
17399                    try {
17400                            session = openSession();
17401    
17402                            SQLQuery q = session.createSQLQuery(sql);
17403    
17404                            q.addScalar(COUNT_COLUMN_NAME,
17405                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17406    
17407                            QueryPos qPos = QueryPos.getInstance(q);
17408    
17409                            qPos.add(groupId);
17410    
17411                            qPos.add(categoryId);
17412    
17413                            qPos.add(threadId);
17414    
17415                            qPos.add(answer);
17416    
17417                            Long count = (Long)q.uniqueResult();
17418    
17419                            return count.intValue();
17420                    }
17421                    catch (Exception e) {
17422                            throw processException(e);
17423                    }
17424                    finally {
17425                            closeSession(session);
17426                    }
17427            }
17428    
17429            /**
17430             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17431             *
17432             * @param groupId the group ID
17433             * @param categoryId the category ID
17434             * @param threadId the thread ID
17435             * @param status the status
17436             * @return the number of matching message-boards messages
17437             * @throws SystemException if a system exception occurred
17438             */
17439            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17440                    int status) throws SystemException {
17441                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17442    
17443                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
17444                                    finderArgs, this);
17445    
17446                    if (count == null) {
17447                            StringBundler query = new StringBundler(5);
17448    
17449                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17450    
17451                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17452    
17453                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17454    
17455                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17456    
17457                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17458    
17459                            String sql = query.toString();
17460    
17461                            Session session = null;
17462    
17463                            try {
17464                                    session = openSession();
17465    
17466                                    Query q = session.createQuery(sql);
17467    
17468                                    QueryPos qPos = QueryPos.getInstance(q);
17469    
17470                                    qPos.add(groupId);
17471    
17472                                    qPos.add(categoryId);
17473    
17474                                    qPos.add(threadId);
17475    
17476                                    qPos.add(status);
17477    
17478                                    count = (Long)q.uniqueResult();
17479                            }
17480                            catch (Exception e) {
17481                                    throw processException(e);
17482                            }
17483                            finally {
17484                                    if (count == null) {
17485                                            count = Long.valueOf(0);
17486                                    }
17487    
17488                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
17489                                            finderArgs, count);
17490    
17491                                    closeSession(session);
17492                            }
17493                    }
17494    
17495                    return count.intValue();
17496            }
17497    
17498            /**
17499             * 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;.
17500             *
17501             * @param groupId the group ID
17502             * @param categoryId the category ID
17503             * @param threadId the thread ID
17504             * @param status the status
17505             * @return the number of matching message-boards messages that the user has permission to view
17506             * @throws SystemException if a system exception occurred
17507             */
17508            public int filterCountByG_C_T_S(long groupId, long categoryId,
17509                    long threadId, int status) throws SystemException {
17510                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17511                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17512                    }
17513    
17514                    StringBundler query = new StringBundler(5);
17515    
17516                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17517    
17518                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17519    
17520                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17521    
17522                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17523    
17524                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17525    
17526                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17527                                    MBMessage.class.getName(),
17528                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17529    
17530                    Session session = null;
17531    
17532                    try {
17533                            session = openSession();
17534    
17535                            SQLQuery q = session.createSQLQuery(sql);
17536    
17537                            q.addScalar(COUNT_COLUMN_NAME,
17538                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17539    
17540                            QueryPos qPos = QueryPos.getInstance(q);
17541    
17542                            qPos.add(groupId);
17543    
17544                            qPos.add(categoryId);
17545    
17546                            qPos.add(threadId);
17547    
17548                            qPos.add(status);
17549    
17550                            Long count = (Long)q.uniqueResult();
17551    
17552                            return count.intValue();
17553                    }
17554                    catch (Exception e) {
17555                            throw processException(e);
17556                    }
17557                    finally {
17558                            closeSession(session);
17559                    }
17560            }
17561    
17562            /**
17563             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17564             *
17565             * @param userId the user ID
17566             * @param classNameId the class name ID
17567             * @param classPK the class p k
17568             * @param status the status
17569             * @return the number of matching message-boards messages
17570             * @throws SystemException if a system exception occurred
17571             */
17572            public int countByU_C_C_S(long userId, long classNameId, long classPK,
17573                    int status) throws SystemException {
17574                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
17575    
17576                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_S,
17577                                    finderArgs, this);
17578    
17579                    if (count == null) {
17580                            StringBundler query = new StringBundler(5);
17581    
17582                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17583    
17584                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17585    
17586                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17587    
17588                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17589    
17590                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17591    
17592                            String sql = query.toString();
17593    
17594                            Session session = null;
17595    
17596                            try {
17597                                    session = openSession();
17598    
17599                                    Query q = session.createQuery(sql);
17600    
17601                                    QueryPos qPos = QueryPos.getInstance(q);
17602    
17603                                    qPos.add(userId);
17604    
17605                                    qPos.add(classNameId);
17606    
17607                                    qPos.add(classPK);
17608    
17609                                    qPos.add(status);
17610    
17611                                    count = (Long)q.uniqueResult();
17612                            }
17613                            catch (Exception e) {
17614                                    throw processException(e);
17615                            }
17616                            finally {
17617                                    if (count == null) {
17618                                            count = Long.valueOf(0);
17619                                    }
17620    
17621                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_S,
17622                                            finderArgs, count);
17623    
17624                                    closeSession(session);
17625                            }
17626                    }
17627    
17628                    return count.intValue();
17629            }
17630    
17631            /**
17632             * Returns the number of message-boards messages.
17633             *
17634             * @return the number of message-boards messages
17635             * @throws SystemException if a system exception occurred
17636             */
17637            public int countAll() throws SystemException {
17638                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
17639                                    FINDER_ARGS_EMPTY, this);
17640    
17641                    if (count == null) {
17642                            Session session = null;
17643    
17644                            try {
17645                                    session = openSession();
17646    
17647                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
17648    
17649                                    count = (Long)q.uniqueResult();
17650                            }
17651                            catch (Exception e) {
17652                                    throw processException(e);
17653                            }
17654                            finally {
17655                                    if (count == null) {
17656                                            count = Long.valueOf(0);
17657                                    }
17658    
17659                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
17660                                            FINDER_ARGS_EMPTY, count);
17661    
17662                                    closeSession(session);
17663                            }
17664                    }
17665    
17666                    return count.intValue();
17667            }
17668    
17669            /**
17670             * Initializes the message-boards message persistence.
17671             */
17672            public void afterPropertiesSet() {
17673                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
17674                                            com.liferay.portal.util.PropsUtil.get(
17675                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
17676    
17677                    if (listenerClassNames.length > 0) {
17678                            try {
17679                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
17680    
17681                                    for (String listenerClassName : listenerClassNames) {
17682                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
17683                                                            listenerClassName));
17684                                    }
17685    
17686                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
17687                            }
17688                            catch (Exception e) {
17689                                    _log.error(e);
17690                            }
17691                    }
17692            }
17693    
17694            public void destroy() {
17695                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
17696                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
17697                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17698            }
17699    
17700            @BeanReference(type = MBBanPersistence.class)
17701            protected MBBanPersistence mbBanPersistence;
17702            @BeanReference(type = MBCategoryPersistence.class)
17703            protected MBCategoryPersistence mbCategoryPersistence;
17704            @BeanReference(type = MBDiscussionPersistence.class)
17705            protected MBDiscussionPersistence mbDiscussionPersistence;
17706            @BeanReference(type = MBMailingListPersistence.class)
17707            protected MBMailingListPersistence mbMailingListPersistence;
17708            @BeanReference(type = MBMessagePersistence.class)
17709            protected MBMessagePersistence mbMessagePersistence;
17710            @BeanReference(type = MBStatsUserPersistence.class)
17711            protected MBStatsUserPersistence mbStatsUserPersistence;
17712            @BeanReference(type = MBThreadPersistence.class)
17713            protected MBThreadPersistence mbThreadPersistence;
17714            @BeanReference(type = MBThreadFlagPersistence.class)
17715            protected MBThreadFlagPersistence mbThreadFlagPersistence;
17716            @BeanReference(type = CompanyPersistence.class)
17717            protected CompanyPersistence companyPersistence;
17718            @BeanReference(type = GroupPersistence.class)
17719            protected GroupPersistence groupPersistence;
17720            @BeanReference(type = LockPersistence.class)
17721            protected LockPersistence lockPersistence;
17722            @BeanReference(type = PortletPreferencesPersistence.class)
17723            protected PortletPreferencesPersistence portletPreferencesPersistence;
17724            @BeanReference(type = ResourcePersistence.class)
17725            protected ResourcePersistence resourcePersistence;
17726            @BeanReference(type = SubscriptionPersistence.class)
17727            protected SubscriptionPersistence subscriptionPersistence;
17728            @BeanReference(type = UserPersistence.class)
17729            protected UserPersistence userPersistence;
17730            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
17731            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
17732            @BeanReference(type = AssetEntryPersistence.class)
17733            protected AssetEntryPersistence assetEntryPersistence;
17734            @BeanReference(type = AssetLinkPersistence.class)
17735            protected AssetLinkPersistence assetLinkPersistence;
17736            @BeanReference(type = AssetTagPersistence.class)
17737            protected AssetTagPersistence assetTagPersistence;
17738            @BeanReference(type = BlogsEntryPersistence.class)
17739            protected BlogsEntryPersistence blogsEntryPersistence;
17740            @BeanReference(type = ExpandoValuePersistence.class)
17741            protected ExpandoValuePersistence expandoValuePersistence;
17742            @BeanReference(type = RatingsStatsPersistence.class)
17743            protected RatingsStatsPersistence ratingsStatsPersistence;
17744            @BeanReference(type = SocialActivityPersistence.class)
17745            protected SocialActivityPersistence socialActivityPersistence;
17746            @BeanReference(type = WikiPagePersistence.class)
17747            protected WikiPagePersistence wikiPagePersistence;
17748            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
17749            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
17750            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
17751            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
17752            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
17753            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
17754            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
17755            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
17756            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
17757            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
17758            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
17759            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
17760            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
17761            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
17762            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
17763            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
17764            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
17765            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
17766            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
17767            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
17768            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17769            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
17770            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
17771            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
17772            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
17773            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
17774                    _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
17775            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
17776            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
17777                    _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
17778            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17779            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
17780            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
17781            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
17782            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17783            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
17784            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17785            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
17786            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17787            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
17788            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17789            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
17790            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
17791            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
17792            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17793            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
17794            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17795            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17796            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
17797            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
17798            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17799            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
17800            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
17801            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
17802                    _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
17803            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17804            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
17805                    _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
17806            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
17807            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
17808                    _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
17809            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17810            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
17811            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
17812            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17813            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17814            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17815            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17816            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17817            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17818            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17819            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17820            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
17821            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17822            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
17823            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
17824    
17825            private static String _removeConjunction(String sql) {
17826                    int pos = sql.indexOf(" AND ");
17827    
17828                    if (pos != -1) {
17829                            sql = sql.substring(0, pos);
17830                    }
17831    
17832                    return sql;
17833            }
17834    
17835            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
17836            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
17837            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
17838                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
17839            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
17840                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
17841            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
17842            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
17843            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
17844            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
17845            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
17846            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
17847            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
17848            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
17849            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
17850            private static MBMessage _nullMBMessage = new MBMessageImpl() {
17851                            @Override
17852                            public Object clone() {
17853                                    return this;
17854                            }
17855    
17856                            @Override
17857                            public CacheModel<MBMessage> toCacheModel() {
17858                                    return _nullMBMessageCacheModel;
17859                            }
17860                    };
17861    
17862            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
17863                            public MBMessage toEntityModel() {
17864                                    return _nullMBMessage;
17865                            }
17866                    };
17867    }